From 359af900d19ec8370b4ceda8a566a24a607b2f4f Mon Sep 17 00:00:00 2001 From: Alexandre CATTEAU Date: Sat, 12 Mar 2022 12:15:06 +0100 Subject: [PATCH] install.sh: differentiate processing for root, check for sudo before calling it, and add support for ponctual user definition --- install.sh | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/install.sh b/install.sh index 3aefd63..3de68bb 100644 --- a/install.sh +++ b/install.sh @@ -2,15 +2,33 @@ run_directory=$(dirname "$0") -echo "Copying rcs to home directory..." -cp $run_directory/bashrc /home/$(whoami)/.bashrc -cp $run_directory/vimrc /home/$(whoami)/.vimrc -cp $run_directory/tmux.conf /home/$(whoami)/.tmux.conf +if [ -z "$1" ]; then + user=$(whoami) +else + user=$1 +fi -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 +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 + 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 +fi echo "Finished install. Exiting..." exit 0