I'm creating a virtual machine configuration script using whiptail that I'd like to have automatically start after the user logs in. The thing is, that I don't want the user to be root, however because the user will need to be able to change things like hostname, ip address, add directories, etc. they'll need sudo privileges in order for the script to actually do it's job.
What I've done so far is created a user that uses my whiptail shell script:
adduser -M -s /scripts/whiptail_config.sh user1
user1 ALL=(root) NOPASSWD: /scripts/whiptail3_config.sh
exec /sbin/getty -8 38400 tty1 -a user1
/scripts/whiptail3_config.sh doesn't do a sudo, then it won't have permissions. You can make the script check the uid under which it's running and sudo to itself.
#!/bin/bash [ $UID != 0 ] && exec sudo $0 "$@" # the rest of the script...