commit f6376837232f0648dbc1e0255ec070473b359f93 Author: ray Date: Mon Feb 17 13:59:52 2020 +0000 initial commit diff --git a/notify-updates b/notify-updates new file mode 100755 index 0000000..34db54c --- /dev/null +++ b/notify-updates @@ -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 diff --git a/pacman-update-count.sh b/pacman-update-count.sh new file mode 100755 index 0000000..9e6e013 --- /dev/null +++ b/pacman-update-count.sh @@ -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"