So, I have a script that needs to install a software but the script needs to be run as root.
I have created a desktop icon on the GUI (using Ubuntu desktop) where ideally, the user will click this icon, it will prompt for password and then run the script as root.
So far the script does what is intended if ran as root, but not as the user. Script looks like this:
#!/bin/bash -l
zenity --question --text "This script will reboot after installation is complete" --title="Warning\!" 2> /dev/null
if [ $? = 0 ]; then
install dependencies
dpkg -i package.deb
etc
fi
reboot
However, if I click on the icon to run the script, it loads and it doesn't do anything, then I check the logs and realize that it fails: sudo: no tty present and no askpass program specified
I know I can modified the sudoers files but I do not want to do this as I need to keep this user independent.
Is there a way to force when running the script to ask the user to become root? or to force the GUI to ask for a password? what is the best way to get this done? I need users to run this program but I need to run the program as root and sudo is not doing it for whatever reason.