diff --git a/src/commandline.sh b/src/commandline.sh index 536fc16..5b27af6 100644 --- a/src/commandline.sh +++ b/src/commandline.sh @@ -7,10 +7,14 @@ help() { Usage: nightscout-tool [options] Description: - Nightscout-tool is a command-line tool for managing Nightscout. - In UI mode, tool provides a menu-driven interface for managing Nightscout server, its configuration, updates, cleanup, and diagnostics. - In watchdog mode, it can be used to monitor the status of Nightscout and send an email alert if the service is down. + Nightscout-tool is a command-line tool for managing Nightscout. + + In UI mode, tool provides a menu-driven interface for managing + Nightscout server, its configuration, updates, cleanup, and diagnostics. + + In watchdog mode, it can be used to monitor the status of Nightscout + and send an email alert if the service is down. Options: -w, --watchdog Run in watchdog mode @@ -28,7 +32,7 @@ parse_commandline_args() { load_update_channel - CMDARGS=$(getopt --quiet -o wvdpuc: --long watchdog,version,develop,production,update,channel: -n 'nightscout-tool' -- "$@") + CMDARGS=$(getopt --quiet -o wvldpuc:h --long watchdog,version,loud,develop,production,update,channel:,help -n 'nightscout-tool' -- "$@") # shellcheck disable=SC2181 if [ $? != 0 ]; then @@ -40,10 +44,12 @@ parse_commandline_args() { eval set -- "$CMDARGS" WATCHDOGMODE=false + NONINTERACTIVE_MODE=false while true; do case "$1" in -w | --watchdog) WATCHDOGMODE=true + NONINTERACTIVE_MODE=true shift ;; -v | --version) @@ -106,6 +112,8 @@ parse_commandline_args() { done if [ "$WATCHDOGMODE" = "true" ]; then + startup_version + startup_debug watchdog_check fi diff --git a/src/lib.sh b/src/lib.sh index c246959..f936dd4 100644 --- a/src/lib.sh +++ b/src/lib.sh @@ -42,6 +42,7 @@ DOCKER_DOWN_MAIL=604800 # == 7 days in seconds SCRIPT_VERSION="1.10.1" #auto-update SCRIPT_BUILD_TIME="2026.01.05" #auto-update FORCE_DEBUG_LOG="" +NONINTERACTIVE_MODE="false" #======================================= # DOWNLOAD CONFIG diff --git a/src/logic_app.sh b/src/logic_app.sh index 3e6d740..0caf170 100644 --- a/src/logic_app.sh +++ b/src/logic_app.sh @@ -4,7 +4,6 @@ update_logto() { if [[ "$UPDATE_CHANNEL" == "develop" || "$FORCE_DEBUG_LOG" == "1" ]]; then - msgok "Debug logging enabled - see: $DEBUG_LOG_FILE" LOGTO="$DEBUG_LOG_FILE" else LOGTO=/dev/null @@ -37,7 +36,6 @@ get_domain_status() { load_update_channel() { if [[ -f $UPDATE_CHANNEL_FILE ]]; then UPDATE_CHANNEL=$(cat "$UPDATE_CHANNEL_FILE") - msgok "Loaded update channel: $UPDATE_CHANNEL" update_logto fi } @@ -48,4 +46,13 @@ startup_version() { msgnote "build ${updateInstalled}" msgnote "$uni_copyright 2023-2026 Dominik Dzienia" msgnote "Licensed under CC BY-NC-ND 4.0" + if [[ -f $UPDATE_CHANNEL_FILE ]]; then + msgok "Loaded update channel: $UPDATE_CHANNEL" + fi +} + +startup_debug() { + if [[ "$UPDATE_CHANNEL" == "develop" || "$FORCE_DEBUG_LOG" == "1" ]]; then + msgdebug "Debug logging enabled - see: $DEBUG_LOG_FILE" + fi } diff --git a/src/logic_watchdog.sh b/src/logic_watchdog.sh index fd7a9ef..83c6886 100644 --- a/src/logic_watchdog.sh +++ b/src/logic_watchdog.sh @@ -150,7 +150,9 @@ get_watchdog_status() { } watchdog_check() { - echo "Nightscout Watchdog mode" + echo "---------------------------" + echo " Nightscout Watchdog mode" + echo "---------------------------" WATCHDOG_LAST_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") WATCHDOG_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") @@ -302,4 +304,4 @@ watchdog_check() { echo "$WATCHDOG_STATUS" >"$WATCHDOG_STATUS_FILE" exit 0 -} \ No newline at end of file +} diff --git a/src/screen_formaters.sh b/src/screen_formaters.sh index 6e67277..7c69dbc 100644 --- a/src/screen_formaters.sh +++ b/src/screen_formaters.sh @@ -25,6 +25,7 @@ emoji_check="\U2705" emoji_ok="\U1F197" emoji_err="\U274C" emoji_note="\U1F4A1" +emoji_debug="\U1F4DC" uni_bullet=" $(printf '\u2022') " uni_copyright="$(printf '\uA9\uFE0F')" diff --git a/src/setup.sh b/src/setup.sh index 88b20d9..78bcf97 100755 --- a/src/setup.sh +++ b/src/setup.sh @@ -28,8 +28,9 @@ if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi # MAIN SCRIPT #======================================= -startup_version parse_commandline_args "$@" +startup_version +startup_debug # check_interactive check_git check_docker diff --git a/src/utils_console.sh b/src/utils_console.sh index 2f13777..840a751 100644 --- a/src/utils_console.sh +++ b/src/utils_console.sh @@ -17,29 +17,70 @@ chomp() { } ohai() { - printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")" + if [ "$NONINTERACTIVE_MODE" = "true" ]; then + # shellcheck disable=SC2059 + printf "==> %s\n" "$(shell_join "$@")" + else + printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")" + fi } msgok() { - # shellcheck disable=SC2059 - printf "$emoji_ok $1\n" + if [ "$NONINTERACTIVE_MODE" = "true" ]; then + # shellcheck disable=SC2059 + printf "$1\n" + else + # shellcheck disable=SC2059 + printf "$emoji_ok $1\n" + fi } msgnote() { - # shellcheck disable=SC2059 - printf "$emoji_note $1\n" + if [ "$NONINTERACTIVE_MODE" = "true" ]; then + # shellcheck disable=SC2059 + printf "$1\n" + else + # shellcheck disable=SC2059 + printf "$emoji_note $1\n" + fi } msgcheck() { - # shellcheck disable=SC2059 - printf "$emoji_check $1\n" + if [ "$NONINTERACTIVE_MODE" = "true" ]; then + # shellcheck disable=SC2059 + printf "$1\n" + else + # shellcheck disable=SC2059 + printf "$emoji_check $1\n" + fi } msgerr() { - # shellcheck disable=SC2059 - printf "$emoji_err $1\n" + if [ "$NONINTERACTIVE_MODE" = "true" ]; then + # shellcheck disable=SC2059 + printf "$1\n" + else + # shellcheck disable=SC2059 + printf "$emoji_err $1\n" + fi +} + +msgdebug() { + if [[ "$UPDATE_CHANNEL" == "develop" || "$FORCE_DEBUG_LOG" == "1" ]]; then + if [ "$NONINTERACTIVE_MODE" = "true" ]; then + # shellcheck disable=SC2059 + printf "$1\n" + else + printf "$emoji_debug $1\n" + fi + fi } warn() { - printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" >&2 + if [ "$NONINTERACTIVE_MODE" = "true" ]; then + # shellcheck disable=SC2059 + printf "Warning: %s\n" "$(chomp "$1")" >&2 + else + printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" >&2 + fi }