fixed funky apt output breaking update checks

This commit is contained in:
alanweinstock 2025-02-27 14:58:30 -08:00
parent b4495f39a9
commit e9d021c268

View file

@ -257,15 +257,25 @@ check_for_updates() {
# 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
# FIX: Properly capture and process the apt list output
apt_output=$(apt list --upgradable 2>/dev/null) apt_output=$(apt list --upgradable 2>/dev/null)
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
packages_available=$(echo "$apt_output" | grep -c "upgradable" || echo "0") # Only count lines that actually contain "upgradable" to avoid parsing errors
if [ "$packages_available" -gt 0 ]; then packages_count=$(echo "$apt_output" | grep -c "upgradable" || echo "0")
# Ensure we have a clean numeric value
if [[ "$packages_count" =~ ^[0-9]+$ ]]; then
packages_available=$packages_count
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 checking updates"
fi
else else
packages="Need privileges to check updates" packages="Need privileges to check updates"
fi fi
@ -278,13 +288,20 @@ check_for_updates() {
dnf|yum) dnf|yum)
# Check if we can run as non-root # Check if we can run as non-root
if timeout 5 $package_manager check-update -q &>/dev/null; then if timeout 5 $package_manager check-update -q &>/dev/null; then
packages_available=$($update_check_cmd) # Capture the output in a variable and ensure it's a valid number
check_output=$($update_check_cmd)
if [[ "$check_output" =~ ^[0-9]+$ ]]; then
packages_available=$check_output
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 checking updates"
fi
else else
packages="Need root to check updates" packages="Need root to check updates"
fi fi
@ -292,13 +309,20 @@ check_for_updates() {
pacman) pacman)
if pacman -Qu &>/dev/null; then if pacman -Qu &>/dev/null; then
packages_available=$(pacman -Qu | wc -l) # Ensure we get a clean numeric value
check_output=$(pacman -Qu | wc -l)
if [[ "$check_output" =~ ^[0-9]+$ ]]; then
packages_available=$check_output
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 checking updates"
fi
else else
packages="Need to run 'pacman -Sy' to check updates" packages="Need to run 'pacman -Sy' to check updates"
fi fi
@ -306,13 +330,20 @@ check_for_updates() {
zypper) zypper)
if timeout 5 zypper list-updates &>/dev/null; then if timeout 5 zypper list-updates &>/dev/null; then
packages_available=$(zypper list-updates | grep '^v ' | wc -l) # Ensure we get a clean numeric value
check_output=$(zypper list-updates | grep '^v ' | wc -l)
if [[ "$check_output" =~ ^[0-9]+$ ]]; then
packages_available=$check_output
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 checking updates"
fi
else else
packages="Need root to check updates" packages="Need root to check updates"
fi fi
@ -320,13 +351,20 @@ check_for_updates() {
apk) apk)
if timeout 5 apk version -v &>/dev/null; then if timeout 5 apk version -v &>/dev/null; then
packages_available=$(apk version -v | grep -c upgradable) # Ensure we get a clean numeric value
check_output=$(apk version -v | grep -c upgradable)
if [[ "$check_output" =~ ^[0-9]+$ ]]; then
packages_available=$check_output
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 checking updates"
fi
else else
packages="Need root to check updates" packages="Need root to check updates"
fi fi
@ -346,6 +384,7 @@ check_for_updates() {
fi fi
fi fi
} }
################################ ################################
# CPU Temperature # CPU Temperature
################################ ################################