From 6603a539a91d9bfc58183e952edba6b80c2aa88f Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Fri, 14 Jan 2022 00:03:10 -0300 Subject: [PATCH] Refactor and support long comm line options --- scripts/bootstrap.sh | 28 ++++++++++++++-------------- scripts/common.sh | 6 +++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 2314669..7313176 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -3,38 +3,38 @@ usage() { cat << EOF usage: ${0##*/} [command] - -h Print this help message. - -w Use whiptail. - -d Use dialog. - -l Log to CocoRice.log file. + -h | --help Print this help message. + -d | --dialog Use dialog. + -l | --log Log to CocoRice.log file. EOF } checkParameters() { - local counter=0 - while getopts ':hwdfp' flag; do - case $flag in - h) + while [ -n "$1" ]; do + case $1 in + -h | --help) usage exit 0 ;; - d) + -d | --dialog) + echo "dialog" checkForDependencies "dialog" setDialogBox "dialog" ;; - f) + -l | --log) checkForDependencies "libnewt" setDialogBox "whiptail" - setDebugToFile true + setLogToFile true ;; - p) + -p | --packages) installPackages=true ;; - ?) - printf '%s: invalid option -%s\n' "${0##*/}" "$OPTARG" + *) + printf '%s: invalid option %s\n' "${0##*/}" "$1" exit 1 ;; esac + shift done if [ -z "$(getDialogBox)" ]; then diff --git a/scripts/common.sh b/scripts/common.sh index 2ab7936..dc667aa 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -163,10 +163,10 @@ getDialogBox() { echo "$dialogBox" } -setDebugToFile() { - export debugFlagToFile=${1} +setLogToFile() { + export logToFile=${1} } debug() { - [[ -z ${debugFlagToFile+x} || $debugFlagToFile = true ]] && tee -a CocoRice.log > /dev/null + [[ -z ${logToFile+x} || $logToFile = true ]] && tee -a CocoRice.log > /dev/null }