initial commit

This commit is contained in:
ray 2020-02-17 13:59:52 +00:00
commit f637683723
2 changed files with 70 additions and 0 deletions

50
notify-updates Executable file
View File

@ -0,0 +1,50 @@
#!/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
if ! [ -f "$_target_file" ] ;
then
echo "Error - file not found: $_target_file"
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
_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: $_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" | festival --tts
notify-send -u low "Update Notifier" "No updates required"
fi

20
pacman-update-count.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/sh
_updates_available="0"
_target_file="/tmp/pacman-update-count"
_user="ray"
sudo pacman -Sy
_query_output=$(sudo pacman -Qu)
# TODO - get update count from above
echo "$_query_output"
# check $_updates_available is algebraically equal to itself (i.e., is a number)
# https://unix.stackexchange.com/a/151655
if ! [ "$_updates_available" -eq "$_updates_available" ] 2> /dev/null ; then
_updates_available="-1"
fi
echo "$_updates_available" > "$_target_file"
chown "$_user": "$_target_file"