From 4eec7a0c6eec10492c33288b8cc1cb966aa43567 Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Mon, 2 Nov 2026 17:35:28 -0700 Subject: [PATCH] Add Updates section to health-check.sh --- health-check.sh | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/health-check.sh b/health-check.sh index 779549c..6f90261 100755 --- a/health-check.sh +++ b/health-check.sh @@ -228,6 +228,59 @@ check_hub() { echo "" } +check_updates() { + header "Updates" + + local now last_raw last_epoch last_days boot_raw boot_epoch boot_days + now=$(date +%s) + + last_raw=$(grep -h '^Start-Date' /var/log/apt/history.log 2>/dev/null | tail -1 | cut -d' ' -f2- || true) + if [ -z "$last_raw" ]; then + last_raw=$(zgrep -h '^Start-Date' /var/log/apt/history.log.*.gz 2>/dev/null | sort | tail -1 | cut -d' ' -f2- || true) + fi + + if [ -n "$last_raw" ]; then + last_raw=$(echo "$last_raw" | tr -s ' ') + last_epoch=$(date -d "$last_raw" +%s 2>/dev/null || echo "") + else + last_epoch="" + fi + + if [ -n "$last_epoch" ]; then + last_days=$(( (now - last_epoch) / 86400 )) + if [ "$last_days" -ge 30 ]; then + warn "Last updated $(date -d "@$last_epoch" '+%b %d, %Y %I:%M %p') (${last_days} days ago)" + else + ok "Last updated $(date -d "@$last_epoch" '+%b %d, %Y %I:%M %p') (${last_days} days ago)" + fi + else + warn "Could not determine last update time" + fi + + boot_raw=$(uptime -s 2>/dev/null || true) + if [ -n "$boot_raw" ]; then + boot_epoch=$(date -d "$boot_raw" +%s 2>/dev/null || echo "") + else + boot_epoch="" + fi + + if [ -n "$boot_epoch" ]; then + boot_days=$(( (now - boot_epoch) / 86400 )) + ok "Last rebooted $(date -d "@$boot_epoch" '+%b %d, %Y %I:%M %p') (${boot_days} days ago)" + else + warn "Could not determine last reboot time" + fi + + if [ -f /var/run/reboot-required ]; then + warn "Reboot required" + if [ -f /var/run/reboot-required.pkgs ]; then + sort -u /var/run/reboot-required.pkgs | sed 's/^/ /' + fi + else + ok "No reboot required" + fi +} + check_common check_disk @@ -239,4 +292,6 @@ if [ "$IS_HUB" = true ]; then check_hub fi +check_updates + echo ""