There is a shell script (/bin/sh, not bash) that requires root permissions for execution.
If it is ran by a normal user it should ask user a password to get root access and re-run itself.
Now it uses the following code:
if [ $(id -u) -ne 0 ]; then su root -- $0 $@ ; ... fi
That works fine, but there are some OS like Ubuntu that has no root password at all. On the other hand, a lot of systems use sudo for root permissions.
The question is: how can the script detect whether to use su
or sudo
without asking the user to enter too much passwords (e.g. enter sudo
password, if it fails - run su
).