diff --git a/bin/snap-sync b/bin/snap-sync index 5cbfc2f..30dafac 100755 --- a/bin/snap-sync +++ b/bin/snap-sync @@ -11,6 +11,15 @@ version="0.3" set -e +function error_exit +{ + for u in $(users); do + notify_cmd="sudo -u $u DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus notify-send" + $notify_cmd 'Error in snap-sync backups. Check journal for more information.' --icon=dialog-error + done + exit 1 +} + while [[ $# -gt 0 ]]; do key="$1" case $key in @@ -56,6 +65,15 @@ description=${description:-"latest incremental backup"} uuid_cmdline=${uuid_cmdline:-"none"} noconfirm=${noconfirm:-"no"} +for u in $(users); do + notify_cmd="sudo -u $u DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus notify-send" + if [[ "$uuid_cmdline" != "none" ]]; then + $notify_cmd 'Starting snap-sync backups to '$uuid_cmdline'...' --icon=dialog-information + else + $notify_cmd 'Starting snap-sync backups. Use command line menu to select disk.' --icon=dialog-information + fi +done + if [[ $EUID -ne 0 ]]; then printf "Script must be run as root.\n" exit @@ -121,7 +139,7 @@ if [[ -f /etc/conf.d/snapper ]]; then source /etc/conf.d/snapper else printf "ERROR: /etc/conf.d/snapper does not exist!\n" - exit 1 + error_exit fi selected_configs=${selected_configs:-$SNAPPER_CONFIGS} @@ -135,7 +153,7 @@ for x in $selected_configs; do source /etc/snapper/configs/$x else printf "ERROR: Selected snapper configuration $x does not exist.\n" - exit 1 + error_exit fi if [[ $SNAP_SYNC_EXCLUDE == "yes" ]]; then @@ -156,7 +174,7 @@ for x in $selected_configs; do BACKUPDIR="$selected_mnt/$mybackupdir" if [[ ! -d $BACKUPDIR ]]; then printf "ERROR: %s is not a directory on %s.\n" "$BACKUPDIR" "$selected_uuid" - exit 1 + error_exit fi fi BACKUPDIRS_ARRAY[$x]=$BACKUPDIR @@ -176,7 +194,7 @@ for x in $selected_configs; do source /etc/snapper/configs/$x else printf "ERROR: Selected snapper configuration $x does not exist.\n" - exit 1 + error_exit fi if [[ $SNAP_SYNC_EXCLUDE == "yes" ]]; then @@ -250,3 +268,12 @@ done printf "\nDone!\n" exec 3>&- + +for u in $(users); do + notify_cmd="sudo -u $u DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus notify-send" + if [[ "$uuid_cmdline" != "none" ]]; then + $notify_cmd 'snap-sync backups to '$1' complete!' --icon=dialog-information + else + $notify_cmd 'snap-sync backups complete!' --icon=dialog-information + fi +done diff --git a/bin/snap-sync-wrapper b/bin/snap-sync-wrapper deleted file mode 100755 index d9ea48d..0000000 --- a/bin/snap-sync-wrapper +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -# Notifies all users that a backup is running - -for u in $(users); do - - notify_cmd="sudo -u $u DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(sudo -u $u id -u)/bus notify-send" - $notify_cmd 'Starting snap-sync backups to '$1'...' --icon=dialog-information - - /usr/bin/snap-sync --UUID $1 --noconfirm - if [[ $? == 0 ]]; then - $notify_cmd 'snap-sync backups to '$1' complete!' --icon=dialog-information - else - $notify_cmd 'Error in snap-sync backups. Check journal for more information.' --icon=dialog-error - fi - -done diff --git a/systemd/snap-sync@.service b/systemd/snap-sync@.service index dfbbd1f..b3317e1 100644 --- a/systemd/snap-sync@.service +++ b/systemd/snap-sync@.service @@ -6,4 +6,4 @@ WantedBy=multi-user.target [Service] Type=simple -ExecStart=/usr/bin/snap-sync-wrapper %i +ExecStart=/usr/bin/snap-sync --UUID %i --noconfirm