Last active
June 11, 2023 03:45
-
-
Save logarytm/575263a76d22f29ef721f40b2785d5c8 to your computer and use it in GitHub Desktop.
package update notifications for Arch Linux, easily portable to other distros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Configuration | |
cache_file=$HOME/.updates | |
# function to check updates, must work without root privileges and print | |
# the number of updates to stdout. | |
function update_count { | |
checkupdates | wc -l; return $? | |
} | |
# notification function, called: notify TOTAL [NEW] | |
function notify { | |
if [ $# -eq 2 ]; then | |
notify-send "$2 new updates ($1 total)" "Run pacman -Syu to upgrade" | |
else | |
notify-send "$1 updates" "Run pacman -Syu to upgrade" | |
fi | |
} | |
count=$(update_count) | |
if [ -f "$cache_file" ] && [ $(<$cache_file) -ge 0 ]; then | |
last_count=$(cat $cache_file) | |
if [ $last_count -lt $count ]; then | |
notify $count $((count-last_count)) | |
echo $count > $cache_file | |
fi | |
elif [ $count -ge 0 ]; then | |
notify $count | |
echo $count > $cache_file | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment