Cleanup commandline menu

develop
Dominik Dzienia 3 weeks ago
parent caefc5c507
commit ed18d44d5f

@ -24,6 +24,7 @@ Options:
-p, --production Switch to PRODUCTION update channel -p, --production Switch to PRODUCTION update channel
-u, --update Force update check -u, --update Force update check
-c, --channel Switch to specified update channel -c, --channel Switch to specified update channel
-s, --cleanup Perform cleanup
-h, --help Show this help message -h, --help Show this help message
EOF EOF
} }
@ -32,7 +33,7 @@ parse_commandline_args() {
load_update_channel load_update_channel
CMDARGS=$(getopt --quiet -o wvldpuc:h --long watchdog,version,loud,develop,production,update,channel:,help -n 'nightscout-tool' -- "$@") CMDARGS=$(getopt --quiet -o wvldpuc:sh --long watchdog,version,loud,develop,production,update,channel:,cleanup,help -n 'nightscout-tool' -- "$@")
# shellcheck disable=SC2181 # shellcheck disable=SC2181
if [ $? != 0 ]; then if [ $? != 0 ]; then
@ -99,6 +100,11 @@ parse_commandline_args() {
update_logto update_logto
shift shift
;; ;;
-s | --cleanup)
NONINTERACTIVE_MODE=true
do_cleanup_all
exit 0
;;
-h | --help) -h | --help)
help help
exit 0 exit 0

@ -65,3 +65,42 @@ do_cleanup_app_logs() {
rm -f "$WATCHDOG_FAILURES_FILE" rm -f "$WATCHDOG_FAILURES_FILE"
rm -f "$WATCHDOG_CRON_LOG" rm -f "$WATCHDOG_CRON_LOG"
} }
cleanup_stats() {
local spaceInfo=$(get_space_info)
local remainingTxt=$(echo "$spaceInfo" | awk '{print $3}' | numfmt --to iec-i --suffix=B)
local totalTxt=$(echo "$spaceInfo" | awk '{print $2}' | numfmt --to iec-i --suffix=B)
local percTxt=$(echo "$spaceInfo" | awk '{print $4}')
local fixedPerc=${percTxt/[%]/=}
local nowB=$(echo "$spaceInfo" | awk '{print $3}')
local lastTimeB=$(echo "$lastTimeSpaceInfo" | awk '{print $3}')
local savedB=$((nowB - lastTimeB))
local savedTxt=$(echo "$savedB" | numfmt --to iec-i --suffix=B)
if ((savedB < 1)); then
savedTxt="---"
fi
local statusTitle="\n$(center_multiline 45 "$(
pad_multiline \
" Dostępne: ${remainingTxt}" \
"\n Zwolniono: ${savedTxt}" \
"\n Zajęte: ${fixedPerc} (z ${totalTxt})"
)")\n"
echo "\n---------------------------\n"
echo "$statusTitle"
echo "\n---------------------------\n"
}
do_cleanup_all() {
echo "Cleanup"
echo "\n---------------------------\n"
do_cleanup_container_logs
do_cleanup_sys
do_cleanup_docker
do_cleanup_db
do_cleanup_diagnostics
cleanup_stats
}
Loading…
Cancel
Save