use traps

This commit is contained in:
James Barnett
2017-02-02 18:36:20 -06:00
parent a15ad6c820
commit 9e94c24007

View File

@@ -10,17 +10,25 @@
version="0.3"
name="snap-sync"
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 -a $name 'Error' 'Check journal for more information.' --icon=dialog-error
done
printf "\nExited due to error.\n" | tee $PIPE
exit 1
}
function kill_exit
{
printf "\nExited due to user intervention.\n" | tee $PIPE
exit 1
}
trap error_exit ERR
trap kill_exit SIGTERM SIGINT
while [[ $# -gt 0 ]]; do
key="$1"
case $key in