fixed funky apt output breaking update checks
This commit is contained in:
parent
b4495f39a9
commit
e9d021c268
1 changed files with 64 additions and 25 deletions
|
|
@ -257,14 +257,24 @@ 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")
|
||||||
packages="${packages_available} updates can be installed"
|
|
||||||
need_updates=true
|
# 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"
|
||||||
|
need_updates=true
|
||||||
|
else
|
||||||
|
packages="0 updates available"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
packages="0 updates available"
|
packages="Error checking updates"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
packages="Need privileges to check updates"
|
packages="Need privileges to check updates"
|
||||||
|
|
@ -278,12 +288,19 @@ 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
|
||||||
if [ $packages_available -gt 0 ]; then
|
check_output=$($update_check_cmd)
|
||||||
packages="${packages_available} updates can be installed"
|
if [[ "$check_output" =~ ^[0-9]+$ ]]; then
|
||||||
need_updates=true
|
packages_available=$check_output
|
||||||
|
|
||||||
|
if [ $packages_available -gt 0 ]; then
|
||||||
|
packages="${packages_available} updates can be installed"
|
||||||
|
need_updates=true
|
||||||
|
else
|
||||||
|
packages="0 updates available"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
packages="0 updates available"
|
packages="Error checking updates"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
packages="Need root to check updates"
|
packages="Need root to check updates"
|
||||||
|
|
@ -292,12 +309,19 @@ 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
|
||||||
if [ $packages_available -gt 0 ]; then
|
check_output=$(pacman -Qu | wc -l)
|
||||||
packages="${packages_available} updates can be installed"
|
if [[ "$check_output" =~ ^[0-9]+$ ]]; then
|
||||||
need_updates=true
|
packages_available=$check_output
|
||||||
|
|
||||||
|
if [ $packages_available -gt 0 ]; then
|
||||||
|
packages="${packages_available} updates can be installed"
|
||||||
|
need_updates=true
|
||||||
|
else
|
||||||
|
packages="0 updates available"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
packages="0 updates available"
|
packages="Error checking updates"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
packages="Need to run 'pacman -Sy' to check updates"
|
packages="Need to run 'pacman -Sy' to check updates"
|
||||||
|
|
@ -306,12 +330,19 @@ 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
|
||||||
if [ $packages_available -gt 0 ]; then
|
check_output=$(zypper list-updates | grep '^v ' | wc -l)
|
||||||
packages="${packages_available} updates can be installed"
|
if [[ "$check_output" =~ ^[0-9]+$ ]]; then
|
||||||
need_updates=true
|
packages_available=$check_output
|
||||||
|
|
||||||
|
if [ $packages_available -gt 0 ]; then
|
||||||
|
packages="${packages_available} updates can be installed"
|
||||||
|
need_updates=true
|
||||||
|
else
|
||||||
|
packages="0 updates available"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
packages="0 updates available"
|
packages="Error checking updates"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
packages="Need root to check updates"
|
packages="Need root to check updates"
|
||||||
|
|
@ -320,12 +351,19 @@ 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
|
||||||
if [ $packages_available -gt 0 ]; then
|
check_output=$(apk version -v | grep -c upgradable)
|
||||||
packages="${packages_available} updates can be installed"
|
if [[ "$check_output" =~ ^[0-9]+$ ]]; then
|
||||||
need_updates=true
|
packages_available=$check_output
|
||||||
|
|
||||||
|
if [ $packages_available -gt 0 ]; then
|
||||||
|
packages="${packages_available} updates can be installed"
|
||||||
|
need_updates=true
|
||||||
|
else
|
||||||
|
packages="0 updates available"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
packages="0 updates available"
|
packages="Error checking updates"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
packages="Need root to check updates"
|
packages="Need root to check updates"
|
||||||
|
|
@ -346,6 +384,7 @@ check_for_updates() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
################################
|
################################
|
||||||
# CPU Temperature
|
# CPU Temperature
|
||||||
################################
|
################################
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue