diff --git a/setup_system.sh b/setup_system.sh index 55c554c..98c3852 100755 --- a/setup_system.sh +++ b/setup_system.sh @@ -4,9 +4,8 @@ # Default variables # -UPGRADE_PACKAGES=false -SCRIPT_NAME="$(basename -- "$0")" -SCRIPT_DIR="$( +upgrade_packages=false +script_dir="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit 1 pwd -P )" @@ -16,7 +15,7 @@ SCRIPT_DIR="$( # function usage() { - echo "Usage: $SCRIPT_NAME [OPTIONS]" + echo "Usage: $(basename -- "$0") [OPTIONS]" echo echo "Options:" echo " -h Display help." @@ -27,7 +26,7 @@ function usage() { while getopts ":uh" arg; do case $arg in h) usage ;; - u) UPGRADE_PACKAGES=true ;; + u) upgrade_packages=true ;; :) echo "$0: Must supply an argument to -$OPTARG." >&2 exit 1 @@ -56,7 +55,7 @@ function is_laptop() { # Returns a comma-separated list of packages for one or more targets. # The packages file may contain multiple rows with the same target name. function get_packages() { - local pkg_file="$SCRIPT_DIR/.installer/packages" + local pkg_file="$script_dir/.installer/packages" for target in "$@"; do while read -r row; do @@ -155,7 +154,7 @@ function setup_brew_formulas() { for package in $(get_packages "${targets[@]}"); do if brew list --full-name | grep -Eq "(^| )$package($| )" >/dev/null; then - if $UPGRADE_PACKAGES; then + if $upgrade_packages; then echo "Package '$package' will be upgraded." brew upgrade "$package" || return 2 else @@ -191,7 +190,7 @@ function setup_krew_plugins() { for package in $(get_packages "${targets[@]}"); do if kubectl-krew list | grep -q "^$package$" >/dev/null; then - if $UPGRADE_PACKAGES; then + if $upgrade_packages; then echo "Package '$package' will be upgraded." else echo "Package '$package' already exists." @@ -246,7 +245,7 @@ function setup_arch_with_yay() { for package in $(get_packages "${targets[@]}"); do if pacman -Qs "^$package$" >/dev/null; then - if $UPGRADE_PACKAGES; then + if $upgrade_packages; then echo "Package '$package' will be upgraded." else echo "Package '$package' already exists."