I'm working on some installation script in bash (on a Raspberry Pi running Stretch). It will copy files to /usr/local/bin and to my user profile and it will install a few packages if needed. The script is almost 2000 lines and 20–30 commands need root.
Now my question is: should I run the entire script with sudo or just as standard user and sudo only the commands inside the script that need admin rights?
sudoto entire one. But from good security practice side and Unix ideology, you must use min permissions as much as possible and upper it only in cases when it's needed.