fixed issue with apt check formatting

This commit is contained in:
alanweinstock 2025-02-26 22:43:23 -08:00
parent 0b9220e5da
commit b4a6cbfc1e

View file

@ -219,33 +219,58 @@ check_for_updates() {
case $package_manager in case $package_manager in
apt) apt)
if [ -f /usr/lib/update-notifier/apt-check ]; then if [ -f /usr/lib/update-notifier/apt-check ]; then
packages_available=$(/usr/lib/update-notifier/apt-check 2>&1 | cut -d';' -f1) # Capture both stdout and stderr, and handle malformed output
security_updates=$(/usr/lib/update-notifier/apt-check 2>&1 | cut -d';' -f2) apt_check_output=$(/usr/lib/update-notifier/apt-check 2>&1)
# Validate that we have a proper semicolon-separated output
if [[ "$apt_check_output" == *";"* ]]; then
packages_available=$(echo "$apt_check_output" | cut -d';' -f1)
security_updates=$(echo "$apt_check_output" | cut -d';' -f2)
# Validate that packages_available is a valid number
if [[ "$packages_available" =~ ^[0-9]+$ ]]; then
if [ $packages_available -gt 0 ]; then if [ $packages_available -gt 0 ]; then
packages="${packages_available} updates can be installed" packages="${packages_available} updates can be installed"
need_updates=true need_updates=true
else else
packages="0 updates available" packages="0 updates available"
fi fi
else
packages="Error parsing update count"
fi
# Validate that security_updates is a valid number
if [[ "$security_updates" =~ ^[0-9]+$ ]]; then
if [ $security_updates -gt 0 ]; then if [ $security_updates -gt 0 ]; then
supdates="${security_updates} security updates" supdates="${security_updates} security updates"
need_updates=true need_updates=true
else else
supdates="0 security updates" supdates="0 security updates"
fi fi
else
supdates="Error parsing security updates"
fi
else
packages="Invalid update-notifier output"
fi
else else
# If apt-check isn't available, try an alternative method # If apt-check isn't available, try an alternative method
if command -v apt >/dev/null 2>&1; then if command -v apt >/dev/null 2>&1; then
# This method requires root/sudo, will be empty if not available # This method requires root/sudo, will be empty if not available
packages_available=$(apt list --upgradable 2>/dev/null | grep -c upgradable || echo "unknown") apt_output=$(apt list --upgradable 2>/dev/null)
if [[ "$packages_available" != "unknown" && $packages_available -gt 0 ]]; then if [ $? -eq 0 ]; then
packages_available=$(echo "$apt_output" | grep -c "upgradable" || echo "0")
if [ "$packages_available" -gt 0 ]; then
packages="${packages_available} updates can be installed" packages="${packages_available} updates can be installed"
need_updates=true need_updates=true
else else
packages="unknown updates available" packages="0 updates available"
fi fi
else
packages="Need privileges to check updates"
fi
else
packages="apt not available"
fi fi
fi fi
;; ;;
@ -321,7 +346,6 @@ check_for_updates() {
fi fi
fi fi
} }
################################ ################################
# CPU Temperature # CPU Temperature
################################ ################################