diff --git a/README.md b/README.md index e26b763..669874b 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,4 @@ This repository contains setup or config files for generic CLI applications, suc * `tmux.conf` is tmux config file and should be installed at `~/.tmux.conf`. #### Installation * `install.sh` script copies above files to their respective destinations; - * can be called with an argument, which will be used as user name (to be used with setup scripts). + * can be called with an argument, which will be used as user name. diff --git a/install.sh b/install.sh index 224b4ee..3de68bb 100644 --- a/install.sh +++ b/install.sh @@ -4,32 +4,26 @@ run_directory=$(dirname "$0") if [ -z "$1" ]; then user=$(whoami) - if [[ $user != 'root' ]]; then - echo "Copying rcs to home directory..." - cp $run_directory/bashrc /home/$user/.bashrc - cp $run_directory/vimrc /home/$user/.vimrc - cp $run_directory/tmux.conf /home/$user/.tmux.conf - if ! command -v sudo &> /dev/null; then - echo "Could not copy to root directory: sudo was not found." - else - echo "Copying rcs to root directory..." - sudo cp $run_directory/bashrc /root/.bashrc - sudo cp $run_directory/vimrc /root/.vimrc - sudo cp $run_directory/tmux.conf /root/.tmux.conf - fi +else + user=$1 +fi + +if [[ $user != 'root' ]]; then + echo "Copying rcs to home directory..." + cp $run_directory/bashrc /home/$user/.bashrc + cp $run_directory/vimrc /home/$user/.vimrc + cp $run_directory/tmux.conf /home/$user/.tmux.conf + + if ! command -v sudo &> /dev/null; then + echo "Could not copy to root directory: sudo was not found." else echo "Copying rcs to root directory..." - cp $run_directory/bashrc /root/.bashrc - cp $run_directory/vimrc /root/.vimrc - cp $run_directory/tmux.conf /root/.tmux.conf + sudo cp $run_directory/bashrc /root/.bashrc + sudo cp $run_directory/vimrc /root/.vimrc + sudo cp $run_directory/tmux.conf /root/.tmux.conf fi -else # running from a setup script, assuming as root - user=$1 - echo "Copying rcs to home directory..." - sudo -H -u $user cp $run_directory/bashrc /home/$user/.bashrc - sudo -H -u $user cp $run_directory/vimrc /home/$user/.vimrc - sudo -H -u $user cp $run_directory/tmux.conf /home/$user/.tmux.conf +else echo "Copying rcs to root directory..." cp $run_directory/bashrc /root/.bashrc cp $run_directory/vimrc /root/.vimrc