让我的脚本双击执行需要 sudo 权限的任务

Making my script double-click perform a task that requires sudo privileges

我有一个非常简单的脚本,类似于:

#!/bin/bash
#Select the directory where the file to run is located
cd '/home/vmi/Área de Trabalho/TesteComandosNoLinux'
#I run my software
mono my-program.exe

我发现我需要我的软件 运行 作为管理员才能使某些功能正常运行。 因此,我需要更换:

mono my-program.exe 

每:

sudo mono my-program.exe

此脚本 运行s with two clicks 使其尽可能对用户友好。

我想保持 运行 两次点击,但无法像那样创建(或找到脚本)。

我所做的是编辑文件 /etc/sudoers

在文件末尾添加:

user ALL=(ALL) ALL
user ALL=(ALL)NOPASSWD:path/of/my/second/script.sh
user ALL=(ALL)NOPASSWD:path/of/mono
user ALL=(ALL)NOPASSWD:path/of/my/executable

运行 我的脚本 ./my-second-script.sh 需要用户密码。使用 sudo ./my-second-script.sh 执行脚本时不会发生这种情况,但我发现没有等效的方法 sudo ./my-second-script.sh 单击两次。

解决方案是创建一个脚本来调用我的脚本,该脚本在 运行 执行 sudo 命令时不需要密码。

我的第一个-script.sh:

#!/bin/bash 
cd /home/vmi/desktop/myfolder
sudo meu-segundo-Script.sh

我的第二个-script.sh :

#!/bin/bash
sudo mono my-program.exe