2023-05-26 14:51:07 +02:00
|
|
|
#!/bin/sh
|
2023-05-27 17:53:26 +02:00
|
|
|
count_file=/tmp/waybar/module/pacman/count
|
|
|
|
|
threshold_date="$(date -d 'now - 15 seconds' +%s)"
|
|
|
|
|
|
|
|
|
|
while pgrep checkupdates | grep -v $$; do
|
|
|
|
|
sleep 1
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ -f "$count_file" ]; then
|
|
|
|
|
last_update="$(stat --format='%Y' "$count_file")"
|
|
|
|
|
if [ "$last_update" -ge "$threshold_date" ]; then
|
|
|
|
|
count="$(cat "$count_file")"
|
|
|
|
|
else
|
|
|
|
|
count="$(checkupdates-with-aur | wc -l)"
|
|
|
|
|
mkdir -p /tmp/waybar/module/pacman
|
|
|
|
|
echo "$count" > /tmp/waybar/module/pacman/count
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
count="$(checkupdates-with-aur | wc -l)"
|
|
|
|
|
mkdir -p /tmp/waybar/module/pacman
|
|
|
|
|
echo "$count" > /tmp/waybar/module/pacman/count
|
|
|
|
|
fi
|
|
|
|
|
|
2023-05-26 14:51:07 +02:00
|
|
|
|
|
|
|
|
class="ok"
|
|
|
|
|
if [ "$count" -gt 0 ]; then
|
|
|
|
|
class="urgent"
|
|
|
|
|
elif [ "$count" -gt 10 ]; then
|
|
|
|
|
class="warning"
|
|
|
|
|
fi
|
|
|
|
|
|
2023-05-27 22:22:18 +02:00
|
|
|
[ "$class" = "ok" ] && echo && exit
|
|
|
|
|
|
2023-05-26 14:51:07 +02:00
|
|
|
echo '{"text": "'$count'", "tooltip": "Updates pending: '$count'", "class": "'$class'"}'
|