diff options
author | Aaditya Dhruv <[email protected]> | 2023-01-09 17:26:50 +0530 |
---|---|---|
committer | Aaditya Dhruv <[email protected]> | 2023-01-09 17:26:50 +0530 |
commit | 38dd1f11e49e4ebb06eca086aa4d36ae146f47b7 (patch) | |
tree | 40262a0ba0f619eafd0289c005f0e4789e2383fa /.config/polybar/scripts/updates.sh | |
parent | 5c67b2115716d77952f1127bbeaa3769bb9c7d91 (diff) |
polybar restructure
Diffstat (limited to '.config/polybar/scripts/updates.sh')
-rwxr-xr-x | .config/polybar/scripts/updates.sh | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/.config/polybar/scripts/updates.sh b/.config/polybar/scripts/updates.sh new file mode 100755 index 0000000..70edf26 --- /dev/null +++ b/.config/polybar/scripts/updates.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +NOTIFY_ICON=/usr/share/icons/Papirus/32x32/apps/system-software-update.svg + +get_total_updates() { UPDATES=$(checkupdates 2>/dev/null | wc -l); } + +while true; do + get_total_updates + + # notify user of updates + if hash notify-send &>/dev/null; then + if (( UPDATES > 50 )); then + notify-send -u critical -i $NOTIFY_ICON \ + "You really need to update!!" "$UPDATES New packages" + elif (( UPDATES > 25 )); then + notify-send -u normal -i $NOTIFY_ICON \ + "You should update soon" "$UPDATES New packages" + elif (( UPDATES > 2 )); then + notify-send -u low -i $NOTIFY_ICON \ + "$UPDATES New packages" + fi + fi + + # when there are updates available + # every 10 seconds another check for updates is done + while (( UPDATES > 0 )); do + if (( UPDATES == 1 )); then + echo "$UPDATES" + elif (( UPDATES > 1 )); then + echo "$UPDATES" + else + echo "None" + fi + sleep 10 + get_total_updates + done + + # when no updates are available, use a longer loop, this saves on CPU + # and network uptime, only checking once every 30 min for new updates + while (( UPDATES == 0 )); do + echo "None" + sleep 1800 + get_total_updates + done +done |