polybar: Fix archupdate display

Fixed archupdates to work even if `checkupdates` script returns an error
by falling back to `yay` to do its package update detection.
This commit is contained in:
Marty Oehme 2021-09-24 11:16:38 +02:00
parent 3bf5becbe2
commit 8234fdfdf0
Signed by: Marty
GPG key ID: B7538B8F50A1C800

View file

@ -6,25 +6,32 @@
# that polybar simply displays nothing. # that polybar simply displays nothing.
# #
# dependendies: yay, (pacman-contrib optional) # dependendies: yay, (pacman-contrib optional)
#
# Takes an optional integer argument, which is the minimum
# numer of package updates for an answer to be returned.
min_upd=${1:-0}
# prefer checkupdates since it allows checking w/o partial upgrade # prefer checkupdates since it allows checking w/o partial upgrade
if command -v "checkupdates" >/dev/null; then if command -v "checkupdates" >/dev/null; then
updates_repo="$(checkupdates | wc -l)" updates_repo="$(checkupdates 2>&1)"
# fall back to yay, but be aware it will not find everything
else
updates_repo="$(yay -Qun 2>/dev/null | wc -l)"
fi fi
# fall back to yay, but be aware it will not find everything
# if checkupdates finds nothing or returns an error
if [ "$updates_repo" = "" ] || [ -z "${updates_repo##*==> ERROR: Cannot fetch updates*}" ]; then
updates_repo="$(yay -Qun 2>/dev/null)"
fi
updates_repo=$(echo "$updates_repo" | wc -l)
updates_aur="$(yay -Qum 2>/dev/null | wc -l)" updates_aur="$(yay -Qum 2>/dev/null | wc -l)"
# if ! updates_aur=$(cower -u 2> /dev/null | wc -l); then # updates_aur=$(cower -u 2> /dev/null | wc -l)
# if ! updates_aur=$(trizen -Su --aur --quiet | wc -l); then # updates_aur=$(trizen -Su --aur --quiet | wc -l)
# if ! updates_aur=$(pikaur -Qua 2> /dev/null | wc -l); then # updates_aur=$(pikaur -Qua 2> /dev/null | wc -l)
# if ! updates_aur=$(rua upgrade --printonly 2> /dev/null | wc -l); then # updates_aur=$(rua upgrade --printonly 2> /dev/null | wc -l)
updates="$((updates_repo + updates_aur))" updates=$((updates_repo + updates_aur))
if [ "$updates" -gt "$min_upd" ]; then
if [ "$updates" -gt 0 ]; then echo "$updates"
echo "$updates"
else else
echo "" echo ""
fi fi