I'm writing a script which automates the install of a mailserver, however some of my code has to be compiled from source because it is not in repositories. I have no problem with this, however, I have no idea what the best and most safe way is from a script that is being run as root. I know I have to make a non-privileged user for building, but which on of the following is the recommended way to do it?
1
su -c "command" - builduser
su -c "othercommand" - builduser
2
sudo -u builduser command
sudo -u builduser othercommand
3
su -c "externalscriptwithcommands.sh" - builduser
Ideally, I would like to continue my script as root after this has executed; I feel like option 3 is probably the most ideal, but I would like your input on this.