#!/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 _hostname=$(hostname) _config_file="$HOME/.config/notify-updates/notify-updates.config" if ! [ -f "$_target_file" ] ; then echo "notify-updates: cannot access '$_target_file': File not found" echo "notify-updates: try executing 'pacman-update-count.sh'" 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 . "$_config_file" else echo "notify-updates: warning - config file not found: $_config_file" fi if [ "$notifynone" = "true" ] ; then _notify_none=1 elif [ "$notifynone" = "false" ] ; then _notify_none=0 fi _updates_available=$(cat $_target_file) if [ "$_updates_available" -gt 0 ] ; then _plural="s" if [ "$_updates_available" -lt 2 ] ; then _plural="" fi echo "Attention please: Update required for $_hostname: $_updates_available package$_plural" | festival --tts notify-send "Update Notifier" "Update required: $_updates_available package$_plural" elif [ "$_notify_none" -eq 1 ] ; then echo "Attention please: No package updates required for $_hostname" | festival --tts notify-send -u low "Update Notifier" "No updates required" fi