Code cleanup

develop
Dominik Dzienia 3 weeks ago
parent 31ce3ccc4e
commit 3994ed2165

@ -16,7 +16,7 @@
# This file is automatically generated. Do not modify it directly! # This file is automatically generated. Do not modify it directly!
# Instead, modify the source files in the src directory and run the build script! # Instead, modify the source files in the src directory and run the build script!
# #
# Build time: 2026.01.06 01:30 # Build time: 2026.01.06 15:22
@ -65,6 +65,7 @@ SCRIPT_VERSION="1.10.2" #auto-update
SCRIPT_BUILD_TIME="2026.01.06" #auto-update SCRIPT_BUILD_TIME="2026.01.06" #auto-update
FORCE_DEBUG_LOG="" FORCE_DEBUG_LOG=""
NONINTERACTIVE_MODE="false" NONINTERACTIVE_MODE="false"
EXECUTED="true"
#======================================= #=======================================
# DOWNLOAD CONFIG # DOWNLOAD CONFIG
@ -75,6 +76,10 @@ GITEA_BASE_URL="https://gitea.dzienia.pl/shared/mikrus-installer/raw/branch"
GITHUB_UNAVAILABLE="" # Empty string = GitHub is available, set to "1" if GitHub fails GITHUB_UNAVAILABLE="" # Empty string = GitHub is available, set to "1" if GitHub fails
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# SETUP # SETUP
#======================================= #=======================================
@ -142,6 +147,11 @@ fi
# shellcheck disable=SC2148
# shellcheck disable=SC2155
# shellcheck disable=SC2034
#======================================= #=======================================
# FORMATERS # FORMATERS
#======================================= #=======================================
@ -200,6 +210,11 @@ uni_watchdog_ok="$(printf '\U1F415') Nightscout działa"
# shellcheck disable=SC2148
# shellcheck disable=SC2155
# shellcheck disable=SC2059
#
#======================================= #=======================================
# CONSOLE OUTPUT UTILS # CONSOLE OUTPUT UTILS
#======================================= #=======================================
@ -214,72 +229,83 @@ shell_join() {
done done
} }
all_join() {
local arg
printf "$1"
shift
for arg in "$@"; do
printf " "
printf "${arg}"
done
}
chomp() { chomp() {
printf "%s" "${1/"$'\n'"/}" printf "%s" "${1/"$'\n'"/}"
} }
ohai() { ohai() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "==> %s\n" "$(shell_join "$@")" printf "==> %s\n" "$(shell_join "$@")"
else else
printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")" printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")"
fi fi
} }
msgprint() { msgprint() {
printf "%s\n" "$(shell_join "$@")" #shellcheck disable=SC2046
printf $(all_join "$@")
} }
msgok() { msgok() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$1\n" printf "$1\n"
else else
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$emoji_ok $1\n" printf "$emoji_ok $1\n"
fi fi
} }
msgnote() { msgnote() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$1\n" printf "$1\n"
else else
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$emoji_note $1\n" printf "$emoji_note $1\n"
fi fi
} }
msgcheck() { msgcheck() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$1\n" printf "$1\n"
else else
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$emoji_check $1\n" printf "$emoji_check $1\n"
fi fi
} }
msgerr() { msgerr() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$1\n" printf "$1\n"
else else
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$emoji_err $1\n" printf "$emoji_err $1\n"
fi fi
} }
msgdebug() { msgdebug() {
if [[ "$UPDATE_CHANNEL" == "develop" || "$FORCE_DEBUG_LOG" == "1" ]]; then if [[ "$UPDATE_CHANNEL" == "develop" || "$FORCE_DEBUG_LOG" == "1" ]]; then
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$1\n" printf "$1\n"
else else
printf "$emoji_debug $1\n" printf "$emoji_debug $1\n"
fi fi
fi fi
} }
hline() { hline() {
@ -292,15 +318,19 @@ hline() {
warn() { warn() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "Warning: %s\n" "$(chomp "$1")" >&2 printf "Warning: %s\n" "$(chomp "$1")" >&2
else else
printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" >&2 printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" >&2
fi fi
} }
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# UTILS # UTILS
#======================================= #=======================================
@ -371,6 +401,10 @@ read_or_default() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# STRING UTILS # STRING UTILS
#======================================= #=======================================
@ -469,6 +503,10 @@ pad_multiline() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# SCREEN DIALOGS # SCREEN DIALOGS
#======================================= #=======================================
@ -590,6 +628,10 @@ MIKRUS_APIKEY=''
MIKRUS_HOST='' MIKRUS_HOST=''
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# EVENTS MARKERS LOGIC # EVENTS MARKERS LOGIC
#======================================= #=======================================
@ -664,7 +706,7 @@ event_label() {
} }
event_count() { event_count() {
if [ ! -f ${EVENTS_DB} ]; then if [ ! -f "${EVENTS_DB}" ]; then
echo "0" echo "0"
else else
local eventsJSON=$(dotenv-tool parse -r -f "${EVENTS_DB}") local eventsJSON=$(dotenv-tool parse -r -f "${EVENTS_DB}")
@ -715,7 +757,7 @@ event_count() {
} }
event_list() { event_list() {
if [ ! -f ${EVENTS_DB} ]; then if [ ! -f "${EVENTS_DB}" ]; then
echo "Nie odnotowano zdarzeń" echo "Nie odnotowano zdarzeń"
else else
local eventsJSON=$(dotenv-tool parse -r -f "${EVENTS_DB}") local eventsJSON=$(dotenv-tool parse -r -f "${EVENTS_DB}")
@ -853,6 +895,11 @@ get_events_status() {
} }
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# SETUP # SETUP
#======================================= #=======================================
@ -1020,7 +1067,7 @@ setup_firewall() {
# Extract the last 3 digits from the hostname # Extract the last 3 digits from the hostname
port_number=$(echo "$host" | grep -oE '[0-9]{3}$') port_number=$(echo "$host" | grep -oE '[0-9]{3}$')
ohai "Firewall port: $port_number" ohai "Firewall port: $port_number"
port1=$((10000 + port_number)) port1=$((10000 + port_number))
port2=$((20000 + port_number)) port2=$((20000 + port_number))
@ -1073,6 +1120,10 @@ uninstall_cron() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# SETUP CHECKS # SETUP CHECKS
#======================================= #=======================================
@ -1104,10 +1155,10 @@ add_if_not_ok_compose() {
msgcheck "$1 installed" msgcheck "$1 installed"
else else
ohai "Installing $1..." ohai "Installing $1..."
mkdir -p "~/.docker/cli-plugins" >> "$LOGTO" 2>&1 mkdir -p "~/.docker/cli-plugins" >>"$LOGTO" 2>&1
curl -SL "https://github.com/docker/compose/releases/download/v2.29.7/docker-compose-linux-x86_64" -o "~/.docker/cli-plugins/docker-compose" >> "$LOGTO" 2>&1 curl -SL "https://github.com/docker/compose/releases/download/v2.29.7/docker-compose-linux-x86_64" -o "~/.docker/cli-plugins/docker-compose" >>"$LOGTO" 2>&1
chmod +x "~/.docker/cli-plugins/docker-compose" >> "$LOGTO" 2>&1 chmod +x "~/.docker/cli-plugins/docker-compose" >>"$LOGTO" 2>&1
msgcheck "Installing $1 successfull" msgcheck "Installing $1 successfull"
fi fi
} }
@ -1178,6 +1229,11 @@ check_diceware() {
} }
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# PATCH OLDER CONFIGS # PATCH OLDER CONFIGS
#======================================= #=======================================
@ -1198,6 +1254,8 @@ patch_docker_compose() {
if grep -q "bitnami/mongodb" "$DOCKER_COMPOSE_FILE"; then if grep -q "bitnami/mongodb" "$DOCKER_COMPOSE_FILE"; then
ohai "Patching docker-compose.yml MongoDB image..." ohai "Patching docker-compose.yml MongoDB image..."
# Replace bitnami/mongodb with official mongo image # Replace bitnami/mongodb with official mongo image
# This is BY PURPOSE left as var in yaml - as it is replaced wit env vars
# shellcheck disable=SC2016
sed -i -E 's|image:\s*"*(bitnami/)?mongodb:.*"|image: "mongo:${NS_MONGODB_TAG}"|g' "$DOCKER_COMPOSE_FILE" sed -i -E 's|image:\s*"*(bitnami/)?mongodb:.*"|image: "mongo:${NS_MONGODB_TAG}"|g' "$DOCKER_COMPOSE_FILE"
patched=1 patched=1
fi fi
@ -1213,10 +1271,10 @@ patch_docker_compose() {
msgcheck "Docker compose file patched" msgcheck "Docker compose file patched"
# Restart containers only if they were already running # Restart containers only if they were already running
if [ "$containers_running" -eq 1 ]; then if [ "$containers_running" -eq 1 ]; then
do_cleanup_sys do_cleanup_sys
ohai "Restarting containers to apply patched configuration..." ohai "Restarting containers to apply patched configuration..."
update_containers update_containers
do_cleanup_docker do_cleanup_docker
msgcheck "Containers restarted" msgcheck "Containers restarted"
fi fi
fi fi
@ -1224,6 +1282,11 @@ patch_docker_compose() {
} }
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# DOCKER # DOCKER
#======================================= #=======================================
@ -1238,12 +1301,21 @@ get_docker_status() {
} }
install_containers() { install_containers() {
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE up --no-recreate -d >>"$LOGTO" 2>&1 if [[ "$FORCE_DEBUG_LOG" == "1" && "$NONINTERACTIVE_MODE" = "true" ]]; then
docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" up --no-recreate -d
else
docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" up --no-recreate -d >>"$LOGTO" 2>&1
fi
} }
update_containers() { update_containers() {
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE pull >>"$LOGTO" 2>&1 if [[ "$FORCE_DEBUG_LOG" == "1" && "$NONINTERACTIVE_MODE" = "true" ]]; then
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE up -d >>"$LOGTO" 2>&1 docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" pull
docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" up -d
else
docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" pull >>"$LOGTO" 2>&1
docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" up -d >>"$LOGTO" 2>&1
fi
} }
install_containers_progress() { install_containers_progress() {
@ -1254,7 +1326,11 @@ install_containers_progress() {
} }
uninstall_containers() { uninstall_containers() {
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE down >>"$LOGTO" 2>&1 if [[ "$FORCE_DEBUG_LOG" == "1" && "$NONINTERACTIVE_MODE" = "true" ]]; then
docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" down
else
docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" down >>"$LOGTO" 2>&1
fi
} }
uninstall_containers_progress() { uninstall_containers_progress() {
@ -1311,6 +1387,10 @@ get_container_status_code() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# APP # APP
#======================================= #=======================================
@ -1322,6 +1402,10 @@ get_space_info() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# WATCHDOG LOGIC # WATCHDOG LOGIC
#======================================= #=======================================
@ -1475,7 +1559,7 @@ get_watchdog_status() {
watchdog_check() { watchdog_check() {
echo "---------------------------" echo "---------------------------"
echo " Nightscout Watchdog mode" echo " Nightscout Watchdog mode"
echo "---------------------------" echo "---------------------------"
WATCHDOG_LAST_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") WATCHDOG_LAST_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
@ -1632,6 +1716,10 @@ watchdog_check() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# CLEANUP LOGIC # CLEANUP LOGIC
#======================================= #=======================================
@ -1716,25 +1804,28 @@ cleanup_stats() {
savedTxt="---" savedTxt="---"
fi fi
hline hline
printf " Dostępne: %s\n Zwolniono: %s\n Zajęte: %s (z %s)\n" "${remainingTxt}" "${savedTxt}" "${fixedPerc}" "${totalTxt}" printf " Dostępne: %s\n Zwolniono: %s\n Zajęte: %s (z %s)\n" "${remainingTxt}" "${savedTxt}" "${fixedPerc}" "${totalTxt}"
hline hline
} }
do_cleanup_all() { do_cleanup_all() {
echo "Sprzątanie..." echo "Sprzątanie..."
lastTimeSpaceInfo=$(get_space_info) lastTimeSpaceInfo=$(get_space_info)
hline hline
do_cleanup_container_logs do_cleanup_container_logs
do_cleanup_sys do_cleanup_sys
do_cleanup_docker do_cleanup_docker
do_cleanup_db do_cleanup_db
do_cleanup_diagnostics
cleanup_stats cleanup_stats
} }
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# CONFIGURATION # CONFIGURATION
#======================================= #=======================================
@ -1748,6 +1839,11 @@ source_admin() {
} }
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# UPGRADE # UPGRADE
#======================================= #=======================================
@ -1892,6 +1988,152 @@ download_if_needed() {
fi fi
} }
download_update_forced() {
local timestampNow=$(date +%s)
local lastDownload=$(read_or_default "$UPDATES_DIR/downloaded" "")
echo "$timestampNow" >"$UPDATES_DIR/timestamp"
ohai "Downloading updates..."
local url=$(get_url "updated")
local onlineUpdated=$(curl -fsSL "$url" 2>>"$LOGTO")
if [[ -z "$onlineUpdated" && -z "$GITHUB_UNAVAILABLE" ]]; then
mark_github_unavailable
url=$(get_url "updated")
ohai "GitHub failed, retrying with Gitea (version check)..."
onlineUpdated=$(curl -fsSL "$url" 2>>"$LOGTO")
fi
if [ "$onlineUpdated" == "$lastDownload" ]; then
msgdebug "Downloaded update will be the same as last downloaded"
fi
# we downlaod it anyway
download_updates
}
#shellcheck disable=SC2154
do_update_tool() {
download_update_forced
local lastDownload=$(read_or_default "$UPDATES_DIR/downloaded" "???")
local updateInstalled=$(read_or_default "$UPDATES_DIR/updated" "???")
if [ "$lastDownload" == "error" ]; then
msgerr "Aktualizacja niemożliwa"
msgerr "Nie można w tej chwili aktualizować narzędzia.${TL}Spróbuj ponownie później.${NL}Jeśli problem nie ustąpi - sprawdź konfigurację kanału aktualizacji"
else
if [ "$UPDATE_CHANNEL" == "master" ] && [[ "$lastDownload" < "$updateInstalled" ]]; then
warn "Downgrade na produkcyjnym kanale aktualizacji!"
fi
local changed=0
local redeploy=0
local instOnlineVer=$(extract_version "$(<"$UPDATES_DIR/install.sh")")
local depEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/deployment.env")")
local nsEnvOnlineVer=$(extract_version "$(<"$UPDATES_DIR/nightscout.env")")
local compOnlineVer=$(extract_version "$(<"$UPDATES_DIR/docker-compose.yml")")
local instLocalVer=$(extract_version "$(<"$TOOL_FILE")")
local depEnvLocalVer=$(extract_version "$(<"$ENV_FILE_DEP")")
local nsEnvLocalVer=$(extract_version "$(<"$ENV_FILE_NS")")
local compLocalVer=$(extract_version "$(<"$DOCKER_COMPOSE_FILE")")
local msgInst="$(printf "\U1F7E2") $instLocalVer"
local msgDep="$(printf "\U1F7E2") $depEnvLocalVer"
local msgNs="$(printf "\U1F7E2") $nsEnvLocalVer"
local msgComp="$(printf "\U1F7E2") $compLocalVer"
if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then
changed=$((changed + 1))
msgInst="$(printf "\U1F534") $instLocalVer $(printf "\U27A1") $instOnlineVer"
fi
if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then
changed=$((changed + 1))
redeploy=$((redeploy + 1))
msgDep="$(printf "\U1F534") $depEnvLocalVer $(printf "\U27A1") $depEnvOnlineVer"
fi
if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then
changed=$((changed + 1))
redeploy=$((redeploy + 1))
msgNs="$(printf "\U1F534") $nsEnvLocalVer $(printf "\U27A1") $nsEnvOnlineVer"
fi
if ! [ "$compLocalVer" == "$compOnlineVer" ]; then
changed=$((changed + 1))
redeploy=$((redeploy + 1))
msgComp="$(printf "\U1F534") $compLocalVer $(printf "\U27A1") $compOnlineVer"
fi
local okTxt=""
if [ "$redeploy" -gt 0 ]; then
okTxt="${TL}${uni_warn} Aktualizacja zrestartuje i zaktualizuje kontenery ${uni_warn}"
fi
local versionMsg="${TL}Build: ${updateInstalled}"
if [ ! "$lastDownload" == "$updateInstalled" ]; then
versionMsg="$(pad_multiline "${TL}Masz build: ${updateInstalled}${NL} Dostępny: ${lastDownload}")"
fi
hline
echo -e "Aktualizacja plików:" "${versionMsg}" \
"$(
pad_multiline \
"${TL}${uni_bullet}Skrypt instalacyjny: $msgInst" \
"${NL}${uni_bullet}Konfiguracja deploymentu: $msgDep" \
"${NL}${uni_bullet}Konfiguracja Nightscout: $msgNs" \
"${NL}${uni_bullet}Kompozycja usług: $msgComp${NL}"
)" \
"$okTxt"
hline
clear_last_time "update_needed"
if [ "$redeploy" -gt 0 ]; then
ohai "Redeploy - uninstalling containers"
uninstall_containers
fi
if ! [ "$compOnlineVer" == "$compLocalVer" ]; then
ohai "Updating $DOCKER_COMPOSE_FILE"
cp -fr "$UPDATES_DIR/docker-compose.yml" "$DOCKER_COMPOSE_FILE"
fi
if ! [ "$depEnvLocalVer" == "$depEnvOnlineVer" ]; then
ohai "Updating $ENV_FILE_DEP"
dotenv-tool -pr -o "$ENV_FILE_DEP" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_DEP"
fi
if ! [ "$nsEnvLocalVer" == "$nsEnvOnlineVer" ]; then
ohai "Updating $ENV_FILE_NS"
dotenv-tool -pr -o "$ENV_FILE_NS" -i "$UPDATES_DIR/deployment.env" "$ENV_FILE_NS"
fi
echo "$lastDownload" >"$UPDATES_DIR/updated"
if ! [ "$instOnlineVer" == "$instLocalVer" ] || ! [ "$lastDownload" == "$updateInstalled" ]; then
ohai "Updating $TOOL_FILE"
cp -fr "$UPDATES_DIR/install.sh" "$TOOL_FILE"
fi
if [ "$redeploy" -gt 0 ]; then
ohai "Redeploy - installing containers"
install_containers
fi
hline
msgok "Aktualizacja zakończona"
# fi
fi
}
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
@ -2026,6 +2268,11 @@ retry_diagnostics() {
} }
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# APP LOGIC # APP LOGIC
#======================================= #=======================================
@ -2034,6 +2281,7 @@ update_logto() {
if [[ "$UPDATE_CHANNEL" == "develop" || "$FORCE_DEBUG_LOG" == "1" ]]; then if [[ "$UPDATE_CHANNEL" == "develop" || "$FORCE_DEBUG_LOG" == "1" ]]; then
LOGTO="$DEBUG_LOG_FILE" LOGTO="$DEBUG_LOG_FILE"
else else
#shellcheck disable=SC2034
LOGTO=/dev/null LOGTO=/dev/null
fi fi
} }
@ -2076,7 +2324,7 @@ startup_version() {
msgnote "Licensed under CC BY-NC-ND 4.0" msgnote "Licensed under CC BY-NC-ND 4.0"
if [[ -f $UPDATE_CHANNEL_FILE ]]; then if [[ -f $UPDATE_CHANNEL_FILE ]]; then
msgok "Loaded update channel: $UPDATE_CHANNEL" msgok "Loaded update channel: $UPDATE_CHANNEL"
fi fi
} }
startup_debug() { startup_debug() {
@ -2085,9 +2333,27 @@ startup_debug() {
fi fi
} }
do_restart() {
msgnote "Restarting containers..."
uninstall_containers
install_containers
msgok "Restarted"
}
do_update_ns() {
msgnote "Updating Nightscout and Mongo containers (downloading latest images)..."
uninstall_containers
update_containers
msgok "Updated"
}
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# OTHER UI # OTHER UI
#======================================= #=======================================
@ -2143,6 +2409,11 @@ admin_panel_promo() {
} }
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# SETUP PROMPT DIALOGS # SETUP PROMPT DIALOGS
#======================================= #=======================================
@ -2283,6 +2554,10 @@ prompt_api_secret() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# SETUP UI # SETUP UI
#======================================= #=======================================
@ -2405,6 +2680,11 @@ domain_setup() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# REMINDERS # REMINDERS
#======================================= #=======================================
@ -2556,6 +2836,10 @@ update_background_check() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# COMMANDLINE PARSER # COMMANDLINE PARSER
#======================================= #=======================================
@ -2566,7 +2850,8 @@ Usage: nightscout-tool [options]
Description: Description:
Nightscout-tool is a command-line tool for managing Nightscout. Nightscout-tool is a command-line tool for managing Nightscout instance
and its containers on mikr.us hosting.
In UI mode, tool provides a menu-driven interface for managing In UI mode, tool provides a menu-driven interface for managing
Nightscout server, its configuration, updates, cleanup, and diagnostics. Nightscout server, its configuration, updates, cleanup, and diagnostics.
@ -2577,12 +2862,15 @@ Description:
Options: Options:
-w, --watchdog Run in watchdog mode -w, --watchdog Run in watchdog mode
-v, --version Show version -v, --version Show version
-l, --loud Enable debug logging -l, --loud Enable debug logging (UI) or verbose mode (non-int.)
-d, --develop Switch to DEVELOP update channel -d, --develop Switch to DEVELOP update channel
-p, --production Switch to PRODUCTION update channel -p, --production Switch to PRODUCTION update channel
-u, --update Force update check -u, --update Perform unattended update of tool
-c, --channel Switch to specified update channel -c, --channel Switch to specified update channel
-s, --cleanup Perform cleanup -s, --cleanup Perform cleanup
-r, --restart Restart containers
--update-ns Update Nightscout and Mongo containers
--force-check Force update check in UI mode
-h, --help Show this help message -h, --help Show this help message
EOF EOF
} }
@ -2591,7 +2879,10 @@ parse_commandline_args() {
load_update_channel load_update_channel
CMDARGS=$(getopt --quiet -o wvldpuc:sh --long watchdog,version,loud,develop,production,update,channel:,cleanup,help -n 'nightscout-tool' -- "$@") CMDARGS=$(getopt --quiet \
-o wvldpuc:srh \
--long watchdog,version,loud,develop,production,update,force-check,channel:,cleanup,restart,update-ns,help \
-n 'nightscout-tool' -- "$@")
# shellcheck disable=SC2181 # shellcheck disable=SC2181
if [ $? != 0 ]; then if [ $? != 0 ]; then
@ -2603,7 +2894,11 @@ parse_commandline_args() {
eval set -- "$CMDARGS" eval set -- "$CMDARGS"
WATCHDOGMODE=false WATCHDOGMODE=false
NONINTERACTIVE_MODE=false NONINTERACTIVE_MODE=false
local action=""
local new_channel=""
# First pass: gather configuration and determine action
while true; do while true; do
case "$1" in case "$1" in
-w | --watchdog) -w | --watchdog)
@ -2612,60 +2907,62 @@ parse_commandline_args() {
shift shift
;; ;;
-v | --version) -v | --version)
echo "$SCRIPT_VERSION" action="version"
exit 0 shift
;; ;;
-l | --loud) -l | --loud)
warn "Loud mode, enabling debug logging" FORCE_DEBUG_LOG="1"
FORCE_DEBUG_LOG="1"
update_logto
shift shift
;; ;;
-d | --develop) -d | --develop)
warn "Switching to DEVELOP update channel" new_channel="develop"
UPDATE_CHANNEL=develop
forceUpdateCheck=1 forceUpdateCheck=1
echo "$UPDATE_CHANNEL" >"$UPDATE_CHANNEL_FILE"
update_logto
shift shift
;; ;;
-p | --production) -p | --production)
warn "Switching to PRODUCTION update channel" new_channel="master"
UPDATE_CHANNEL=master
forceUpdateCheck=1 forceUpdateCheck=1
echo "$UPDATE_CHANNEL" >"$UPDATE_CHANNEL_FILE"
update_logto
shift shift
;; ;;
-u | --update) -f | --force-check)
warn "Forcing update check"
forceUpdateCheck=1 forceUpdateCheck=1
shift shift
;; ;;
-u | --update)
NONINTERACTIVE_MODE=true
action="update"
shift
;;
-c | --channel) -c | --channel)
shift # The arg is next in position args shift # The arg is next in position args
UPDATE_CHANNEL_CANDIDATE=$1 new_channel=$1
forceUpdateCheck=1 forceUpdateCheck=1
[[ ! "$UPDATE_CHANNEL_CANDIDATE" =~ ^[a-z]{3,}$ ]] && { [[ ! "$new_channel" =~ ^[a-z]{3,}$ ]] && {
echo "Incorrect channel name provided: $UPDATE_CHANNEL_CANDIDATE" echo "Incorrect channel name provided: $new_channel"
exit 1 exit 1
} }
warn "Switching to $UPDATE_CHANNEL_CANDIDATE update channel"
UPDATE_CHANNEL="$UPDATE_CHANNEL_CANDIDATE"
echo "$UPDATE_CHANNEL" >"$UPDATE_CHANNEL_FILE"
update_logto
shift shift
;; ;;
-s | --cleanup) -s | --cleanup)
NONINTERACTIVE_MODE=true NONINTERACTIVE_MODE=true
do_cleanup_all action="cleanup"
exit 0 shift
;; ;;
-r | --restart)
NONINTERACTIVE_MODE=true
action="restart"
shift
;;
--update-ns)
#shellcheck disable=SC2034
NONINTERACTIVE_MODE=true
action="update-ns"
shift
;;
-h | --help) -h | --help)
help action="help"
exit 0 shift
;; ;;
--) --)
shift shift
@ -2675,17 +2972,65 @@ parse_commandline_args() {
esac esac
done 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
;;
esac
if [ "$WATCHDOGMODE" = "true" ]; then if [ "$WATCHDOGMODE" = "true" ]; then
startup_version startup_version
startup_debug startup_debug
watchdog_check watchdog_check
fi fi
} }
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# WATCHDOG UI # WATCHDOG UI
#======================================= #=======================================
@ -2729,6 +3074,10 @@ show_watchdog_logs() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# CLEANUP UI # CLEANUP UI
#======================================= #=======================================
@ -2846,6 +3195,11 @@ cleanup_menu() {
} }
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# CONFIG AND MANAGEMENT UI # CONFIG AND MANAGEMENT UI
#======================================= #=======================================
@ -3070,6 +3424,10 @@ uninstall_menu() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# UPDATE UI # UPDATE UI
#======================================= #=======================================
@ -3246,6 +3604,10 @@ update_menu() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# DIAGNOSTICS UI # DIAGNOSTICS UI
#======================================= #=======================================
@ -3319,6 +3681,10 @@ send_diagnostics() {
# shellcheck disable=SC2148
# shellcheck disable=SC2155
#======================================= #=======================================
# MAIN APP UI # MAIN APP UI
#======================================= #=======================================
@ -3445,6 +3811,7 @@ main_menu() {
install_or_menu() { install_or_menu() {
STATUS_NS=$(get_docker_status "ns-server") STATUS_NS=$(get_docker_status "ns-server")
#shellcheck disable=SC2034
lastTimeSpaceInfo=$(get_space_info) lastTimeSpaceInfo=$(get_space_info)
if [ "$STATUS_NS" = "missing" ]; then if [ "$STATUS_NS" = "missing" ]; then

@ -135,6 +135,7 @@ main_menu() {
install_or_menu() { install_or_menu() {
STATUS_NS=$(get_docker_status "ns-server") STATUS_NS=$(get_docker_status "ns-server")
#shellcheck disable=SC2034
lastTimeSpaceInfo=$(get_space_info) lastTimeSpaceInfo=$(get_space_info)
if [ "$STATUS_NS" = "missing" ]; then if [ "$STATUS_NS" = "missing" ]; then
@ -162,4 +163,4 @@ install_or_menu() {
msgok "Wykryto uruchomiony Nightscout" msgok "Wykryto uruchomiony Nightscout"
main_menu main_menu
fi fi
} }

@ -61,4 +61,4 @@ admin_panel_promo() {
"${TL}Znajdziesz go klikając na ikonkę serwera w menu strony Nightscout" \ "${TL}Znajdziesz go klikając na ikonkę serwera w menu strony Nightscout" \
"${NL}lub dodając /mikrus na końcu swojego adresu Nightscout")" \ "${NL}lub dodając /mikrus na końcu swojego adresu Nightscout")" \
12 75 12 75
} }

@ -127,4 +127,4 @@ domain_setup() {
fi fi
done done
} }

@ -124,6 +124,7 @@ parse_commandline_args() {
shift shift
;; ;;
--update-ns) --update-ns)
#shellcheck disable=SC2034
NONINTERACTIVE_MODE=true NONINTERACTIVE_MODE=true
action="update-ns" action="update-ns"
shift shift

@ -3,29 +3,85 @@
# shellcheck disable=SC2155 # shellcheck disable=SC2155
# shellcheck disable=SC2034 # shellcheck disable=SC2034
if [ "EXECUTED" != "true" ]; then if [ "$EXECUTED" != "true" ]; then
msgerr "Headers USED!" echo "Headers USED!"
#======================================= #=======================================
# HEADERS # HEADERS
#======================================= #=======================================
#--------------------------------------- #---------------------------------------
# GLOBAL VARS # GLOBAL VARS
#--------------------------------------- #---------------------------------------
packages=() packages=()
aptGetWasUpdated=0 aptGetWasUpdated=0
freshInstall=0 freshInstall=0
cachedMenuDomain='' cachedMenuDomain=''
lastTimeSpaceInfo=0 lastTimeSpaceInfo=0
diagnosticsSizeOk=0 diagnosticsSizeOk=0
forceUpdateCheck=0 forceUpdateCheck=0
MIKRUS_APIKEY='' MIKRUS_APIKEY=''
MIKRUS_HOST='' MIKRUS_HOST=''
else #---------------------------------------
msgdebug "Headers ignored" # UNICODE LITERALS
#---------------------------------------
emoji_check="\U2705"
emoji_ok="\U1F197"
emoji_err="\U274C"
emoji_note="\U1F4A1"
emoji_debug="\U1F4DC"
uni_bullet=" $(printf '\u2022') "
uni_copyright="$(printf '\uA9\uFE0F')"
uni_bullet_pad=" "
uni_warn="$(printf "\U26A0")"
uni_exit=" $(printf '\U274C') Wyjdź "
uni_start=" $(printf '\U1F984') Zaczynamy "
uni_menu=" $(printf '\U1F6E0') Menu "
uni_finish=" $(printf '\U1F984') Zamknij "
uni_reenter=" $(printf '\U21AA') Tak "
uni_noenter=" $(printf '\U2716') Nie "
uni_back=" $(printf '\U2B05') Wróć "
uni_select=" Wybierz "
uni_excl="$(printf '\U203C')"
uni_confirm_del=" $(printf '\U1F4A3') Tak "
uni_confirm_ch=" $(printf '\U1F199') Zmień "
uni_confirm_upd=" $(printf '\U1F199') Aktualizuj "
uni_confirm_ed=" $(printf '\U1F4DD') Edytuj "
uni_install=" $(printf '\U1F680') Instaluj "
uni_resign=" $(printf '\U1F6AB') Rezygnuję "
uni_send=" $(printf '\U1F4E7') Wyślij "
uni_delete=" $(printf '\U1F5D1') Usuń "
uni_leave_logs=" $(printf '\U1F4DC') Zostaw "
uni_ns_ok="$(printf '\U1F7E2') działa"
uni_leave_logs=''
uni_back=''
uni_resign=''
uni_confirm_del=''
uni_confirm_ch=''
uni_confirm_ed=''
uni_select=''
uni_bullet=''
uni_bullet_pad=''
uni_warn=''
uni_send=''
uni_watchdog_ok=''
uni_exit=''
uni_ns_ok=''
uni_start=''
uni_install=''
uni_noenter=''
tty_blue=''
tty_red=''
tty_bold=''
tty_reset=''
fi fi
#dev-end #dev-end

@ -156,4 +156,3 @@ MIKRUS_HOST=''
#include app_update.sh #include app_update.sh
#include app_diagnostics.sh #include app_diagnostics.sh
#include app_main.sh #include app_main.sh

@ -17,6 +17,7 @@ update_logto() {
if [[ "$UPDATE_CHANNEL" == "develop" || "$FORCE_DEBUG_LOG" == "1" ]]; then if [[ "$UPDATE_CHANNEL" == "develop" || "$FORCE_DEBUG_LOG" == "1" ]]; then
LOGTO="$DEBUG_LOG_FILE" LOGTO="$DEBUG_LOG_FILE"
else else
#shellcheck disable=SC2034
LOGTO=/dev/null LOGTO=/dev/null
fi fi
} }
@ -59,7 +60,7 @@ startup_version() {
msgnote "Licensed under CC BY-NC-ND 4.0" msgnote "Licensed under CC BY-NC-ND 4.0"
if [[ -f $UPDATE_CHANNEL_FILE ]]; then if [[ -f $UPDATE_CHANNEL_FILE ]]; then
msgok "Loaded update channel: $UPDATE_CHANNEL" msgok "Loaded update channel: $UPDATE_CHANNEL"
fi fi
} }
startup_debug() { startup_debug() {
@ -80,4 +81,4 @@ do_update_ns() {
uninstall_containers uninstall_containers
update_containers update_containers
msgok "Updated" msgok "Updated"
} }

@ -93,15 +93,15 @@ cleanup_stats() {
savedTxt="---" savedTxt="---"
fi fi
hline hline
printf " Dostępne: %s\n Zwolniono: %s\n Zajęte: %s (z %s)\n" "${remainingTxt}" "${savedTxt}" "${fixedPerc}" "${totalTxt}" printf " Dostępne: %s\n Zwolniono: %s\n Zajęte: %s (z %s)\n" "${remainingTxt}" "${savedTxt}" "${fixedPerc}" "${totalTxt}"
hline hline
} }
do_cleanup_all() { do_cleanup_all() {
echo "Sprzątanie..." echo "Sprzątanie..."
lastTimeSpaceInfo=$(get_space_info) lastTimeSpaceInfo=$(get_space_info)
hline hline
do_cleanup_container_logs do_cleanup_container_logs
do_cleanup_sys do_cleanup_sys
do_cleanup_docker do_cleanup_docker

@ -19,4 +19,4 @@ source_admin() {
source "$ENV_FILE_ADMIN" source "$ENV_FILE_ADMIN"
msgok "Imported admin config" msgok "Imported admin config"
fi fi
} }

@ -138,4 +138,4 @@ retry_diagnostics() {
msgok "Raport ma rozmiar ${currentTxt} i mieści się w limicie ${allowedTxt} dla usługi pusher-a" msgok "Raport ma rozmiar ${currentTxt} i mieści się w limicie ${allowedTxt} dla usługi pusher-a"
fi fi
fi fi
} }

@ -23,21 +23,21 @@ get_docker_status() {
} }
install_containers() { install_containers() {
if [[ "$FORCE_DEBUG_LOG" == "1" && "$NONINTERACTIVE_MODE" = "true" ]]; then if [[ "$FORCE_DEBUG_LOG" == "1" && "$NONINTERACTIVE_MODE" = "true" ]]; then
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE up --no-recreate -d docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" up --no-recreate -d
else else
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE up --no-recreate -d >>"$LOGTO" 2>&1 docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" up --no-recreate -d >>"$LOGTO" 2>&1
fi fi
} }
update_containers() { update_containers() {
if [[ "$FORCE_DEBUG_LOG" == "1" && "$NONINTERACTIVE_MODE" = "true" ]]; then if [[ "$FORCE_DEBUG_LOG" == "1" && "$NONINTERACTIVE_MODE" = "true" ]]; then
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE pull docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" pull
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE up -d docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" up -d
else else
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE pull >>"$LOGTO" 2>&1 docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" pull >>"$LOGTO" 2>&1
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE up -d >>"$LOGTO" 2>&1 docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" up -d >>"$LOGTO" 2>&1
fi fi
} }
install_containers_progress() { install_containers_progress() {
@ -48,10 +48,10 @@ install_containers_progress() {
} }
uninstall_containers() { uninstall_containers() {
if [[ "$FORCE_DEBUG_LOG" == "1" && "$NONINTERACTIVE_MODE" = "true" ]]; then if [[ "$FORCE_DEBUG_LOG" == "1" && "$NONINTERACTIVE_MODE" = "true" ]]; then
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE down docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" down
else else
docker compose --env-file $ENV_FILE_DEP -f $DOCKER_COMPOSE_FILE down >>"$LOGTO" 2>&1 docker compose --env-file "$ENV_FILE_DEP" -f "$DOCKER_COMPOSE_FILE" down >>"$LOGTO" 2>&1
fi fi
} }

@ -83,7 +83,7 @@ event_label() {
} }
event_count() { event_count() {
if [ ! -f ${EVENTS_DB} ]; then if [ ! -f "${EVENTS_DB}" ]; then
echo "0" echo "0"
else else
local eventsJSON=$(dotenv-tool parse -r -f "${EVENTS_DB}") local eventsJSON=$(dotenv-tool parse -r -f "${EVENTS_DB}")
@ -134,7 +134,7 @@ event_count() {
} }
event_list() { event_list() {
if [ ! -f ${EVENTS_DB} ]; then if [ ! -f "${EVENTS_DB}" ]; then
echo "Nie odnotowano zdarzeń" echo "Nie odnotowano zdarzeń"
else else
local eventsJSON=$(dotenv-tool parse -r -f "${EVENTS_DB}") local eventsJSON=$(dotenv-tool parse -r -f "${EVENTS_DB}")
@ -269,4 +269,4 @@ get_events_status() {
else else
printf "\U1F4C5 %s zdarzeń" "$count" printf "\U1F4C5 %s zdarzeń" "$count"
fi fi
} }

@ -29,6 +29,8 @@ patch_docker_compose() {
if grep -q "bitnami/mongodb" "$DOCKER_COMPOSE_FILE"; then if grep -q "bitnami/mongodb" "$DOCKER_COMPOSE_FILE"; then
ohai "Patching docker-compose.yml MongoDB image..." ohai "Patching docker-compose.yml MongoDB image..."
# Replace bitnami/mongodb with official mongo image # Replace bitnami/mongodb with official mongo image
# This is BY PURPOSE left as var in yaml - as it is replaced wit env vars
# shellcheck disable=SC2016
sed -i -E 's|image:\s*"*(bitnami/)?mongodb:.*"|image: "mongo:${NS_MONGODB_TAG}"|g' "$DOCKER_COMPOSE_FILE" sed -i -E 's|image:\s*"*(bitnami/)?mongodb:.*"|image: "mongo:${NS_MONGODB_TAG}"|g' "$DOCKER_COMPOSE_FILE"
patched=1 patched=1
fi fi
@ -44,12 +46,12 @@ patch_docker_compose() {
msgcheck "Docker compose file patched" msgcheck "Docker compose file patched"
# Restart containers only if they were already running # Restart containers only if they were already running
if [ "$containers_running" -eq 1 ]; then if [ "$containers_running" -eq 1 ]; then
do_cleanup_sys do_cleanup_sys
ohai "Restarting containers to apply patched configuration..." ohai "Restarting containers to apply patched configuration..."
update_containers update_containers
do_cleanup_docker do_cleanup_docker
msgcheck "Containers restarted" msgcheck "Containers restarted"
fi fi
fi fi
fi fi
} }

@ -176,7 +176,7 @@ setup_firewall() {
# Extract the last 3 digits from the hostname # Extract the last 3 digits from the hostname
port_number=$(echo "$host" | grep -oE '[0-9]{3}$') port_number=$(echo "$host" | grep -oE '[0-9]{3}$')
ohai "Firewall port: $port_number" ohai "Firewall port: $port_number"
port1=$((10000 + port_number)) port1=$((10000 + port_number))
port2=$((20000 + port_number)) port2=$((20000 + port_number))

@ -40,10 +40,10 @@ add_if_not_ok_compose() {
msgcheck "$1 installed" msgcheck "$1 installed"
else else
ohai "Installing $1..." ohai "Installing $1..."
mkdir -p "~/.docker/cli-plugins" >> "$LOGTO" 2>&1 mkdir -p "~/.docker/cli-plugins" >>"$LOGTO" 2>&1
curl -SL "https://github.com/docker/compose/releases/download/v2.29.7/docker-compose-linux-x86_64" -o "~/.docker/cli-plugins/docker-compose" >> "$LOGTO" 2>&1 curl -SL "https://github.com/docker/compose/releases/download/v2.29.7/docker-compose-linux-x86_64" -o "~/.docker/cli-plugins/docker-compose" >>"$LOGTO" 2>&1
chmod +x "~/.docker/cli-plugins/docker-compose" >> "$LOGTO" 2>&1 chmod +x "~/.docker/cli-plugins/docker-compose" >>"$LOGTO" 2>&1
msgcheck "Installing $1 successfull" msgcheck "Installing $1 successfull"
fi fi
} }
@ -111,4 +111,4 @@ test_diceware() {
check_diceware() { check_diceware() {
test_diceware test_diceware
add_if_not_ok "Secure Password Generator" "diceware" add_if_not_ok "Secure Password Generator" "diceware"
} }

@ -128,8 +128,7 @@ download_if_needed() {
local lastCheck=$(read_or_default "$UPDATES_DIR/timestamp") local lastCheck=$(read_or_default "$UPDATES_DIR/timestamp")
local lastDownload=$(read_or_default "$UPDATES_DIR/downloaded" "") local lastDownload=$(read_or_default "$UPDATES_DIR/downloaded" "")
local timestampNow=$(date +%s) local timestampNow=$(date +%s)
local updateCheck=$UPDATE_CHECK] local updateCheck=$UPDATE_CHECK
#shellcheck disable=SC2154
if (((timestampNow - lastCheck) > updateCheck)) || [ "$lastDownload" == "" ] || [ "$lastDownload" == "error" ] || ((forceUpdateCheck == 1)) || [ $# -eq 1 ]; then if (((timestampNow - lastCheck) > updateCheck)) || [ "$lastDownload" == "" ] || [ "$lastDownload" == "error" ] || ((forceUpdateCheck == 1)) || [ $# -eq 1 ]; then
echo "$timestampNow" >"$UPDATES_DIR/timestamp" echo "$timestampNow" >"$UPDATES_DIR/timestamp"
ohai "Checking if new version is available..." ohai "Checking if new version is available..."

@ -162,7 +162,7 @@ get_watchdog_status() {
watchdog_check() { watchdog_check() {
echo "---------------------------" echo "---------------------------"
echo " Nightscout Watchdog mode" echo " Nightscout Watchdog mode"
echo "---------------------------" echo "---------------------------"
WATCHDOG_LAST_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") WATCHDOG_LAST_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

@ -1,5 +1,6 @@
# shellcheck disable=SC2148 # shellcheck disable=SC2148
# shellcheck disable=SC2155 # shellcheck disable=SC2155
# shellcheck disable=SC2034
#dev-begin #dev-begin
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@ -1,6 +1,7 @@
# shellcheck disable=SC2148 # shellcheck disable=SC2148
# shellcheck disable=SC2155 # shellcheck disable=SC2155
# shellcheck disable=SC2059
#
#dev-begin #dev-begin
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# IMPORTS # IMPORTS
@ -38,67 +39,68 @@ chomp() {
} }
ohai() { ohai() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "==> %s\n" "$(shell_join "$@")" printf "==> %s\n" "$(shell_join "$@")"
else else
printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")" printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")"
fi fi
} }
msgprint() { msgprint() {
printf $(all_join "$@") #shellcheck disable=SC2046
printf $(all_join "$@")
} }
msgok() { msgok() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$1\n" printf "$1\n"
else else
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$emoji_ok $1\n" printf "$emoji_ok $1\n"
fi fi
} }
msgnote() { msgnote() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$1\n" printf "$1\n"
else else
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$emoji_note $1\n" printf "$emoji_note $1\n"
fi fi
} }
msgcheck() { msgcheck() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$1\n" printf "$1\n"
else else
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$emoji_check $1\n" printf "$emoji_check $1\n"
fi fi
} }
msgerr() { msgerr() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$1\n" printf "$1\n"
else else
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$emoji_err $1\n" printf "$emoji_err $1\n"
fi fi
} }
msgdebug() { msgdebug() {
if [[ "$UPDATE_CHANNEL" == "develop" || "$FORCE_DEBUG_LOG" == "1" ]]; then if [[ "$UPDATE_CHANNEL" == "develop" || "$FORCE_DEBUG_LOG" == "1" ]]; then
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "$1\n" printf "$1\n"
else else
printf "$emoji_debug $1\n" printf "$emoji_debug $1\n"
fi fi
fi fi
} }
hline() { hline() {
@ -111,9 +113,9 @@ hline() {
warn() { warn() {
if [ "$NONINTERACTIVE_MODE" = "true" ]; then if [ "$NONINTERACTIVE_MODE" = "true" ]; then
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "Warning: %s\n" "$(chomp "$1")" >&2 printf "Warning: %s\n" "$(chomp "$1")" >&2
else else
printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" >&2 printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" >&2
fi fi
} }

@ -1 +1 @@
2026-01-06T01:30:06.751Z 2026-01-06T15:22:16.552Z
Loading…
Cancel
Save