[polybar] Add safer package update checking

Package updates in yay (as in pacman) will not be reported correctly
when the repository mirrors have not been updated recently.

However, updating only the mirrors without also synching the packages
locally is not recommended by arch. That means, essentially, we can't do
a dry-run to only 'check' for packages without running the danger of
performing a partial arch upgrade.

The program `checkupdates` in pacman-contrib package helps with this by
performing a check for the available updates without needing to pull
from the mirrors before. So, the polybar update script now checks for
its existence and uses it if available, falling back to the standard yay
procedure otherwise.
This commit is contained in:
Marty Oehme 2020-02-25 07:49:16 +01:00
parent 3f1443c546
commit f0dff67410
No known key found for this signature in database
GPG key ID: 0CCB0526EFB9611A

View file

@ -1,18 +1,27 @@
#!/bin/sh
#
# check for available archupdates and return their number
# checks both repositories and aur
# returns empty string when 0 packages are available, so
# that polybar simply displays nothing.
#
# dependendies: yay, bc, (pacman-contrib optional)
if ! updates_arch=$(yay -Qun 2>/dev/null | wc -l); then
updates_arch=0
# prefer checkupdates since it allows checking w/o partial upgrade
if command -v "checkupdates" >/dev/null; then
updates_repo="$(checkupdates | wc -l)"
# fall back to yay, but be aware it will not find everything
else
updates_repo="$(yay -Qun 2>/dev/null | wc -l)"
fi
if ! updates_aur=$(yay -Qum 2>/dev/null | wc -l); then
# if ! updates_aur=$(cower -u 2> /dev/null | wc -l); then
# if ! updates_aur=$(trizen -Su --aur --quiet | wc -l); then
# if ! updates_aur=$(pikaur -Qua 2> /dev/null | wc -l); then
# if ! updates_aur=$(rua upgrade --printonly 2> /dev/null | wc -l); then
updates_aur=0
fi
updates_aur="$(yay -Qum 2>/dev/null | wc -l)"
# if ! updates_aur=$(cower -u 2> /dev/null | wc -l); then
# if ! updates_aur=$(trizen -Su --aur --quiet | wc -l); then
# if ! updates_aur=$(pikaur -Qua 2> /dev/null | wc -l); then
# if ! updates_aur=$(rua upgrade --printonly 2> /dev/null | wc -l); then
updates=$(("$updates_arch" + "$updates_aur"))
updates="$(echo "$updates_repo + $updates_aur" | bc)"
if [ "$updates" -gt 0 ]; then
echo "$updates"