I'm trying to write a script for Centos 6.8 where the user will not be root. There is no admin on the premises, so the script needs to be added to the sudoers (by adding a file to /etc/sudoers.d) by that same script.
It seems like the user should be prompted by the script for the root password, right? If not, what is the convention to get around this (other than having a second script to add to the sudoers when the user runs from root)?
I've tried something along the lines of this:
echo 'foobar ALL=(ALL:ALL) ALL' | sudo EDITOR='tee -a' visudo
and this:
ALL=NOPASSWD:/usr/bin/rsync" | (sudo su -c 'EDITOR="tee" visudo -f /etc/sudoers.d/rsync')
as suggested here, but these just give a continuation prompt.
My basic question is how to prompt for the password and use it to give the user permission to run the script.
The other option is to run the script as root, but I'd like to see if I can do it otherwise.