#dev-begin # shellcheck disable=SC2148 # shellcheck disable=SC2155 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # IMPORTS #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # shellcheck source=./headers.sh source ./headers.sh #dev-end #======================================= # COMMANDLINE PARSER #======================================= help() { cat <&2 exit 1 fi # Note the quotes around '$TEMP': they are essential! eval set -- "$CMDARGS" WATCHDOGMODE=false NONINTERACTIVE_MODE=false local action="" local new_channel="" # First pass: gather configuration and determine action while true; do case "$1" in -w | --watchdog) WATCHDOGMODE=true NONINTERACTIVE_MODE=true shift ;; -v | --version) action="version" shift ;; -l | --loud) FORCE_DEBUG_LOG="1" shift ;; -d | --develop) new_channel="develop" forceUpdateCheck=1 shift ;; -p | --production) new_channel="master" forceUpdateCheck=1 shift ;; -f | --force-check) forceUpdateCheck=1 shift ;; -u | --update) NONINTERACTIVE_MODE=true action="update" shift ;; -c | --channel) shift # The arg is next in position args new_channel=$1 forceUpdateCheck=1 [[ ! "$new_channel" =~ ^[a-z]{3,}$ ]] && { echo "Incorrect channel name provided: $new_channel" exit 1 } shift ;; -s | --cleanup) NONINTERACTIVE_MODE=true action="cleanup" shift ;; -r | --restart) NONINTERACTIVE_MODE=true action="restart" shift ;; --update-ns) #shellcheck disable=SC2034 NONINTERACTIVE_MODE=true action="update-ns" shift ;; --uninstall) #shellcheck disable=SC2034 NONINTERACTIVE_MODE=true action="uninstall" shift ;; -h | --help) action="help" shift ;; --) shift break ;; *) break ;; esac done # Apply configuration if [ -n "$FORCE_DEBUG_LOG" ]; then warn "Loud mode, enabling debug logging" update_logto fi if [ -n "$new_channel" ]; then warn "Switching to $new_channel update channel" UPDATE_CHANNEL="$new_channel" echo "$UPDATE_CHANNEL" >"$UPDATE_CHANNEL_FILE" update_logto fi if [ "$forceUpdateCheck" = "1" ]; then warn "Forcing update check" fi # Second pass: execute action or continue case "$action" in version) echo "$SCRIPT_VERSION" exit 0 ;; help) help exit 0 ;; cleanup) do_cleanup_all exit 0 ;; restart) do_restart exit 0 ;; update) do_update_tool exit 0 ;; update-ns) do_update_ns exit 0 ;; uninstall) do_uninstall exit 0 ;; esac if [ "$WATCHDOGMODE" = "true" ]; then startup_version startup_debug watchdog_run fi }