Last active
December 22, 2023 19:34
-
-
Save bneils/f82fdd2cf9487749f8ed2436b788ba36 to your computer and use it in GitHub Desktop.
Notifies you to upgrade your OS
This file contains hidden or 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
#!/bin/bash | |
### Checks the last APT upgrade and notifies if it was too long ago | |
# requires: libnotify-bin | |
NOTIF_DURATION=15000 | |
UPGRADE_DAYS=7 | |
notify() { | |
notify-send -u normal -t $NOTIF_DURATION "$1" | |
} | |
get_last_upgrade() { | |
grep -E "^Upgrade: " -B 5 | tail -5 | grep -E "^Start-Date: " | tr -s ' ' | cut -d ' ' -f2,3 | |
} | |
upgrade_date=$(cat "/var/log/apt/history.log" | get_last_upgrade) | |
if [ "$upgrade_date" = "" ] ; then | |
>&2 echo Falling back | |
upgrade_date=$(zcat "/var/log/apt/history.log.1.gz" | get_last_upgrade) | |
fi | |
days=$((($(date +%s) - $(date -d"$upgrade_date" +%s)) / 86400)) | |
if [ "$days" -ge $UPGRADE_DAYS ] ; then | |
notify "It's been $days days since your OS was updated." | |
fi | |
echo $days |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for the script. It is a great idea which, in my opinion, leads to other great possibilities such as initiating updates after n days.
Say, instead of (or after) invoking the libnotify-bin, it could trigger Nala fetch for newer or faster download mirrors or trigger apt updates etc.