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,9 +105,11 @@ updates () {
fedora=0
brew=0
flatpak=0
chk=0
# Check for updates from different places... wonder if there's a better way
updchk () {
# Check for APT
if command -v apt-get &> /dev/null; then
debian=$(apt-get -s dist-upgrade -V 2> /dev/null | grep '=>' | awk '{print$1}' | wc -l)
@ -140,11 +142,26 @@ updates () {
if command -v flatpak &> /dev/null && [ "$flatpakupd" = "on" ]; then
flatpak=$(flatpak remote-ls --updates 2> /dev/null | wc -l)
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
updates=$(($debian + $arch + $fedora + $flatpak + $brew))
# Check the update amounts and print them out
if [ $chk -lt 1 ]; then
echo -en "Update check timed out. "
else
if [ $updates -eq 1 ]; then
echo -en "You have ${NORM}1${NCOL} pending update. "
elif [ $updates -eq 0 ]; then
@ -152,6 +169,7 @@ updates () {
else
echo -en "You have ~${NORM}$updates${NCOL} pending updates. "
fi
fi
}
#=====Random Color=====#