From ada7cb718b128cc13c4f8ea9b48a958d7b8cdb71 Mon Sep 17 00:00:00 2001 From: anntnzrb Date: Fri, 6 Nov 2020 10:34:51 -0500 Subject: [PATCH 1/4] Added corresponding exit codes - Redirection to stderr `>&2` also added to the `printf` statement in the `error()` function --- larbs.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/larbs.sh b/larbs.sh index 5b4b718..e70385d 100644 --- a/larbs.sh +++ b/larbs.sh @@ -6,12 +6,12 @@ ### OPTIONS AND VARIABLES ### while getopts ":a:r:b:p:h" o; do case "${o}" in - h) printf "Optional arguments for custom use:\\n -r: Dotfiles repository (local file or url)\\n -p: Dependencies and programs csv (local file or url)\\n -a: AUR helper (must have pacman-like syntax)\\n -h: Show this message\\n" && exit ;; - r) dotfilesrepo=${OPTARG} && git ls-remote "$dotfilesrepo" || exit ;; + h) printf "Optional arguments for custom use:\\n -r: Dotfiles repository (local file or url)\\n -p: Dependencies and programs csv (local file or url)\\n -a: AUR helper (must have pacman-like syntax)\\n -h: Show this message\\n" && exit 1 ;; + r) dotfilesrepo=${OPTARG} && git ls-remote "$dotfilesrepo" || exit 1 ;; b) repobranch=${OPTARG} ;; p) progsfile=${OPTARG} ;; a) aurhelper=${OPTARG} ;; - *) printf "Invalid option: -%s\\n" "$OPTARG" && exit ;; + *) printf "Invalid option: -%s\\n" "$OPTARG" && exit 1 ;; esac done [ -z "$dotfilesrepo" ] && dotfilesrepo="https://github.com/lukesmithxyz/voidrice.git" @@ -23,7 +23,7 @@ esac done installpkg(){ pacman --noconfirm --needed -S "$1" >/dev/null 2>&1 ;} -error() { clear; printf "ERROR:\\n%s\\n" "$1"; exit;} +error() { clear; printf "ERROR:\\n%s\\n" "$1" >&2; exit 1;} welcomemsg() { \ dialog --title "Welcome!" --msgbox "Welcome to Luke's Auto-Rice Bootstrapping Script!\\n\\nThis script will automatically install a fully-featured Linux desktop, which I use as my main machine.\\n\\n-Luke" 10 60 @@ -33,7 +33,7 @@ welcomemsg() { \ getuserandpass() { \ # Prompts user for new username an password. - name=$(dialog --inputbox "First, please enter a name for the user account." 10 60 3>&1 1>&2 2>&3 3>&1) || exit + name=$(dialog --inputbox "First, please enter a name for the user account." 10 60 3>&1 1>&2 2>&3 3>&1) || exit 1 while ! echo "$name" | grep -q "^[a-z_][a-z0-9_-]*$"; do name=$(dialog --no-cancel --inputbox "Username not valid. Give a username beginning with a letter, with only lowercase letters, - or _." 10 60 3>&1 1>&2 2>&3 3>&1) done @@ -51,7 +51,7 @@ usercheck() { \ } preinstallmsg() { \ - dialog --title "Let's get this party started!" --yes-label "Let's go!" --no-label "No, nevermind!" --yesno "The rest of the installation will now be totally automated, so you can sit back and relax.\\n\\nIt will take some time, but when done, you can relax even more with your complete system.\\n\\nNow just press and the system will begin installation!" 13 60 || { clear; exit; } + dialog --title "Let's get this party started!" --yes-label "Let's go!" --no-label "No, nevermind!" --yesno "The rest of the installation will now be totally automated, so you can sit back and relax.\\n\\nIt will take some time, but when done, you can relax even more with your complete system.\\n\\nNow just press and the system will begin installation!" 13 60 || { clear; exit 1; } } adduserandpass() { \ @@ -76,7 +76,7 @@ newperms() { # Set special sudoers settings for install (or after). manualinstall() { # Installs $1 manually if not installed. Used only for AUR helper here. [ -f "/usr/bin/$1" ] || ( dialog --infobox "Installing \"$1\", an AUR helper..." 4 50 - cd /tmp || exit + cd /tmp || exit 1 rm -rf /tmp/"$1"* curl -sO https://aur.archlinux.org/cgit/aur.git/snapshot/"$1".tar.gz && sudo -u "$name" tar -xvf "$1".tar.gz >/dev/null 2>&1 && @@ -94,7 +94,7 @@ gitmakeinstall() { dir="$repodir/$progname" dialog --title "LARBS Installation" --infobox "Installing \`$progname\` ($n of $total) via \`git\` and \`make\`. $(basename "$1") $2" 5 70 sudo -u "$name" git clone --depth 1 "$1" "$dir" >/dev/null 2>&1 || { cd "$dir" || return ; sudo -u "$name" git pull --force origin master;} - cd "$dir" || exit + cd "$dir" || exit 1 make >/dev/null 2>&1 make install >/dev/null 2>&1 cd /tmp || return ;} From 9f2b936a7f60eeed532927c2b7f60cf2e2766dd4 Mon Sep 17 00:00:00 2001 From: anntnzrb Date: Fri, 6 Nov 2020 10:49:51 -0500 Subject: [PATCH 2/4] Removed unnecessary sub-shell, use braces instead --- larbs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larbs.sh b/larbs.sh index e70385d..431da4b 100644 --- a/larbs.sh +++ b/larbs.sh @@ -46,7 +46,7 @@ getuserandpass() { \ done ;} usercheck() { \ - ! (id -u "$name" >/dev/null) 2>&1 || + ! { id -u "$name" >/dev/null 2>&1; } || dialog --colors --title "WARNING!" --yes-label "CONTINUE" --no-label "No wait..." --yesno "The user \`$name\` already exists on this system. LARBS can install for a user already existing, but it will \\Zboverwrite\\Zn any conflicting settings/dotfiles on the user account.\\n\\nLARBS will \\Zbnot\\Zn overwrite your user files, documents, videos, etc., so don't worry about that, but only click if you don't mind your settings being overwritten.\\n\\nNote also that LARBS will change $name's password to the one you just gave." 14 70 } From 8d01c333ed62f2a2437105c936777c71c913c372 Mon Sep 17 00:00:00 2001 From: anntnzrb Date: Fri, 6 Nov 2020 10:52:03 -0500 Subject: [PATCH 3/4] Added corresponding return statements codes --- larbs.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/larbs.sh b/larbs.sh index 431da4b..9bc137d 100644 --- a/larbs.sh +++ b/larbs.sh @@ -82,7 +82,7 @@ manualinstall() { # Installs $1 manually if not installed. Used only for AUR hel sudo -u "$name" tar -xvf "$1".tar.gz >/dev/null 2>&1 && cd "$1" && sudo -u "$name" makepkg --noconfirm -si >/dev/null 2>&1 - cd /tmp || return) ;} + cd /tmp || return 1) ;} maininstall() { # Installs all needed programs from main repo. dialog --title "LARBS Installation" --infobox "Installing \`$1\` ($n of $total). $1 $2" 5 70 @@ -93,15 +93,15 @@ gitmakeinstall() { progname="$(basename "$1" .git)" dir="$repodir/$progname" dialog --title "LARBS Installation" --infobox "Installing \`$progname\` ($n of $total) via \`git\` and \`make\`. $(basename "$1") $2" 5 70 - sudo -u "$name" git clone --depth 1 "$1" "$dir" >/dev/null 2>&1 || { cd "$dir" || return ; sudo -u "$name" git pull --force origin master;} + sudo -u "$name" git clone --depth 1 "$1" "$dir" >/dev/null 2>&1 || { cd "$dir" || return 1 ; sudo -u "$name" git pull --force origin master;} cd "$dir" || exit 1 make >/dev/null 2>&1 make install >/dev/null 2>&1 - cd /tmp || return ;} + cd /tmp || return 1 ;} aurinstall() { \ dialog --title "LARBS Installation" --infobox "Installing \`$1\` ($n of $total) from the AUR. $1 $2" 5 70 - echo "$aurinstalled" | grep -q "^$1$" && return + echo "$aurinstalled" | grep -q "^$1$" && return 1 sudo -u "$name" $aurhelper -S --noconfirm "$1" >/dev/null 2>&1 } From 63717dcb73c79b1c613cff1e06c47bc6551312db Mon Sep 17 00:00:00 2001 From: anntnzrb Date: Fri, 6 Nov 2020 10:56:34 -0500 Subject: [PATCH 4/4] User-defined aliases/functions prevention --- larbs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/larbs.sh b/larbs.sh index 9bc137d..88cedcb 100644 --- a/larbs.sh +++ b/larbs.sh @@ -107,7 +107,7 @@ aurinstall() { \ pipinstall() { \ dialog --title "LARBS Installation" --infobox "Installing the Python package \`$1\` ($n of $total). $1 $2" 5 70 - command -v pip || installpkg python-pip >/dev/null 2>&1 + [ -x "$(command -v "pip")" ] || installpkg python-pip >/dev/null 2>&1 yes | pip install "$1" }