2018-02-05 21:31:56 -06:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
BAR_ICON=""
|
2018-06-30 20:43:00 -05:00
|
|
|
NOTIFY_ICON=/usr/share/icons/gnome/32x32/apps/system-software-update.png
|
2018-02-05 21:31:56 -06:00
|
|
|
|
2018-12-02 22:19:37 -06:00
|
|
|
get_total_updates()
|
|
|
|
{
|
|
|
|
UPDATES=$(checkupdates 2>/dev/null | wc -l)
|
|
|
|
}
|
2018-05-12 13:00:19 -05:00
|
|
|
|
2018-02-05 21:31:56 -06:00
|
|
|
while true; do
|
2018-11-05 00:19:12 -06:00
|
|
|
# print the icon first to avoid gibberish in polybar
|
|
|
|
echo $BAR_ICON
|
|
|
|
|
2018-06-30 20:43:00 -05:00
|
|
|
get_total_updates
|
|
|
|
|
2018-07-19 20:52:19 -05:00
|
|
|
# notify user of updates
|
2018-11-05 00:19:12 -06:00
|
|
|
if hash notify-send >/dev/null 2>&1; then
|
2018-06-30 20:43:00 -05:00
|
|
|
if (( UPDATES > 50 )); then
|
2018-11-05 00:19:12 -06:00
|
|
|
notify-send -u critical -i $NOTIFY_ICON "Updates Available" "$UPDATES packages"
|
2018-06-30 20:43:00 -05:00
|
|
|
elif (( UPDATES > 25 )); then
|
2018-11-05 00:19:12 -06:00
|
|
|
notify-send -u normal -i $NOTIFY_ICON "Updates Available" "$UPDATES packages"
|
2018-06-30 20:43:00 -05:00
|
|
|
elif (( UPDATES > 2 )); then
|
2018-11-05 00:19:12 -06:00
|
|
|
notify-send -u low -i $NOTIFY_ICON "Updates Available" "$UPDATES packages"
|
2018-02-05 21:31:56 -06:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-07-19 20:52:19 -05:00
|
|
|
# when there are updates available
|
|
|
|
# every 10 seconds another check for updates is done
|
2018-06-30 20:43:00 -05:00
|
|
|
while (( UPDATES > 0 )); do
|
2018-11-05 00:19:12 -06:00
|
|
|
(( UPDATES == 1 )) && echo "$UPDATES Update" || { (( UPDATES > 1 )) && echo "$UPDATES Updates"; }
|
2018-05-12 13:00:19 -05:00
|
|
|
sleep 10
|
2018-06-30 20:43:00 -05:00
|
|
|
get_total_updates
|
2018-02-05 21:31:56 -06:00
|
|
|
done
|
|
|
|
|
2018-07-19 20:52:19 -05:00
|
|
|
# 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
|
2018-06-30 20:43:00 -05:00
|
|
|
while (( UPDATES == 0 )); do
|
2018-05-12 13:00:19 -05:00
|
|
|
sleep 1800
|
2018-06-30 20:43:00 -05:00
|
|
|
get_total_updates
|
2018-02-05 21:31:56 -06:00
|
|
|
done
|
|
|
|
done
|