I am writing some bash scripts to install and configure some programs.
Because the script needs to install packages - I run the scripts as root - which itself is no problem (i.e. I have root privileges etc).
However once the packages are installed I want to then configure the normal user files,ideally I would do this as a regular user, as any config files created would be owned by root
An example program snippet is something like
#! /bin/bash # Because this statement needs to be run as root - the entire script is # also run as root apt-get install -y tmux cat << EOF > ~/.tmux.conf # # config stuff # EOF
Do I need to manually revert file privileges to regular user, at the end of the script - which is simple for a single file, but could get tricky in some situations.
e.g. add something like
chown $USER:$USER ~/.tmux.conf chmod 755 ~/.tmux.conf
Or is there a better way to handle this - like execute the
~/.tmux.conf statement in a subshell as a regular user?