Add timeout for update check, 5 seconds

This commit is contained in:
g2 2022-09-30 08:30:45 -05:00
parent 05f0fd6ec8
commit df5d43dea3

View file

@ -105,52 +105,70 @@ updates () {
fedora=0 fedora=0
brew=0 brew=0
flatpak=0 flatpak=0
chk=0
# Check for updates from different places... wonder if there's a better way # Check for updates from different places... wonder if there's a better way
# Check for APT updchk () {
if command -v apt-get &> /dev/null; then # Check for APT
debian=$(apt-get -s dist-upgrade -V 2> /dev/null | grep '=>' | awk '{print$1}' | wc -l) if command -v apt-get &> /dev/null; then
fi debian=$(apt-get -s dist-upgrade -V 2> /dev/null | grep '=>' | awk '{print$1}' | wc -l)
fi
# Check for different Arch things # Check for different Arch things
if command -v yay &> /dev/null; then if command -v yay &> /dev/null; then
arch=$(yay -Qu 2> /dev/null | wc -l) arch=$(yay -Qu 2> /dev/null | wc -l)
elif command -v paru &> /dev/null; then elif command -v paru &> /dev/null; then
arch=$(paru -Quq 2> /dev/null | wc -l) arch=$(paru -Quq 2> /dev/null | wc -l)
elif command -v pacman &> /dev/null; then elif command -v pacman &> /dev/null; then
arch=$(pacman -Qu 2> /dev/null | wc -l) arch=$(pacman -Qu 2> /dev/null | wc -l)
fi fi
# Check for Fedora things # Check for Fedora things
if command -v dnf &> /dev/null; then if command -v dnf &> /dev/null; then
fedora=$(dnf list updates 2> /dev/null | wc -l) fedora=$(dnf list updates 2> /dev/null | wc -l)
fedora=$((fedora-1)) fedora=$((fedora-1))
elif command -v yum &> /dev/null; then elif command -v yum &> /dev/null; then
fedora=$(yum list updates 2> /dev/null | wc -l) fedora=$(yum list updates 2> /dev/null | wc -l)
fedora=$((fedora-1)) fedora=$((fedora-1))
fi fi
# Check for Brew updates # Check for Brew updates
if command -v brew &> /dev/null; then if command -v brew &> /dev/null; then
brew=$(brew outdated 2> /dev/null | wc -l) brew=$(brew outdated 2> /dev/null | wc -l)
fi fi
# Check for Flatpak # Check for Flatpak
if command -v flatpak &> /dev/null && [ "$flatpakupd" = "on" ]; then if command -v flatpak &> /dev/null && [ "$flatpakupd" = "on" ]; then
flatpak=$(flatpak remote-ls --updates 2> /dev/null | wc -l) flatpak=$(flatpak remote-ls --updates 2> /dev/null | wc -l)
fi fi
pkill -P $pid sleep
}
pid=$(echo $$)
updchk &
exec 3>&2
exec 2> /dev/null
sleep 5
chk=$(echo $?) &> /dev/null
exec 2>&3
exec 3>&-
# Add all update counts together # Add all update counts together
updates=$(($debian + $arch + $fedora + $flatpak + $brew)) updates=$(($debian + $arch + $fedora + $flatpak + $brew))
# Check the update amounts and print them out # Check the update amounts and print them out
if [ $updates -eq 1 ]; then if [ $chk -lt 1 ]; then
echo -en "You have ${NORM}1${NCOL} pending update. " echo -en "Update check timed out. "
elif [ $updates -eq 0 ]; then
echo -en "You have no pending updates. "
else else
echo -en "You have ~${NORM}$updates${NCOL} pending updates. " if [ $updates -eq 1 ]; then
echo -en "You have ${NORM}1${NCOL} pending update. "
elif [ $updates -eq 0 ]; then
echo -en "You have no pending updates. "
else
echo -en "You have ~${NORM}$updates${NCOL} pending updates. "
fi
fi fi
} }