update-notifier/notify-updates

68 lines
1.8 KiB
Plaintext
Raw Normal View History

2020-02-17 13:59:52 +00:00
#!/bin/sh
_target_file="/tmp/pacman-update-count"
# if set to 1 then also notify if no updates available
_notify_none=0
_error_code=0
_show_help=0
2020-02-17 16:33:11 +00:00
_hostname=$(hostname)
_config_file="$HOME/.config/notify-updates/notify-updates.config"
2020-02-17 13:59:52 +00:00
if ! [ -f "$_target_file" ] ;
then
2020-02-17 14:34:22 +00:00
echo "notify-updates: cannot access '$_target_file': File not found"
echo "notify-updates: try executing 'pacman-update-count.sh'"
2020-02-17 13:59:52 +00:00
exit 1
fi
for _arg in "$@" ; do
if [ "$_arg" = "-h" ] || [ "$_arg" = "--help" ] ; then
_show_help=1
elif [ "$_arg" = "-n" ] || [ "$_arg" = "--notify-none" ] ; then
_notify_none=1
else
_error_code="5"
_show_help=1
echo "notify-updates: invalid option -- $_arg"
fi
done
if [ "$_show_help" -eq 1 ] ; then
echo "Options:"
echo " -h, --help show this message and exit"
echo " -n, --notify-none notify if no updates available"
exit "$_error_code"
fi
if [ "$_error_code" -gt 0 ] ; then
exit "$_error_code"
fi
# TODO use $XDG_CONFIG_HOME
if [ -f "$_config_file" ] ; then
# shellcheck source=notify-updates.config
. "$_config_file"
else
echo "notify-updates: warning - config file not found: $_config_file"
fi
if [ "$notify_if_none" = "true" ] ; then
_notify_none=1
elif [ "$notify_if_none" = "false" ] ; then
_notify_none=0
fi
2020-02-17 13:59:52 +00:00
_updates_available=$(cat $_target_file)
if [ "$_updates_available" -gt 0 ] ; then
_plural="s"
if [ "$_updates_available" -lt 2 ] ; then
_plural=""
fi
2020-02-17 16:33:11 +00:00
echo "Attention please: Update required for $_hostname: $_updates_available package$_plural" | festival --tts
2020-02-17 13:59:52 +00:00
notify-send "Update Notifier" "Update required: $_updates_available package$_plural"
elif [ "$_notify_none" -eq 1 ] ; then
2020-02-17 16:33:11 +00:00
echo "Attention please: No package updates required for $_hostname" | festival --tts
2020-02-17 13:59:52 +00:00
notify-send -u low "Update Notifier" "No updates required"
fi