From f0dff674104f832eaf54a49b21c33887bd34c588 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 25 Feb 2020 07:49:16 +0100 Subject: [PATCH] [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. --- .../.config/polybar/scripts/poly-archupdates | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/polybar/.config/polybar/scripts/poly-archupdates b/polybar/.config/polybar/scripts/poly-archupdates index b99a3ad..475a4ca 100755 --- a/polybar/.config/polybar/scripts/poly-archupdates +++ b/polybar/.config/polybar/scripts/poly-archupdates @@ -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"