From a451654b1c96adfb6c29e86c4a9db467d000019d Mon Sep 17 00:00:00 2001 From: Tom Vincent Date: Sun, 9 Jul 2017 12:24:35 +0100 Subject: [PATCH] Prevent duplicate notifications Before, a notification would be sent for each login shell. Now, deduplicate the users list and abstract the notification function whilst we're at it. --- bin/snap-sync | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/snap-sync b/bin/snap-sync index 43bd23f..686fcb7 100755 --- a/bin/snap-sync +++ b/bin/snap-sync @@ -39,14 +39,22 @@ mkfifo $PIPE systemd-cat -t "$name" < $PIPE & exec 3>$PIPE -notify_error() { - for u in $(users); do +notify() { + for u in $(users | sed 's/ /\n/' | sort -u); do sudo -u $u DISPLAY=:0 \ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus \ - notify-send -a $name "$1" "$2" --icon=dialog-error + notify-send -a $name "$1" "$2" --icon="dialog-$3" done } +notify_info() { + notify "$1" "$2" "information" +} + +notify_error() { + notify "$1" "$2" "error" +} + error() { printf "==> ERROR: %s\n" "$@" notify_error 'Error' 'Check journal for more information.' @@ -76,14 +84,6 @@ trapkill() { trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR trap trapkill SIGTERM SIGINT -notify_info() { - for u in $(users); do - sudo -u $u DISPLAY=:0 \ - DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus \ - notify-send -a $name "$1" "$2" --icon=dialog-information - done -} - usage() { cat <