trace errors

Fixes #39.
This commit is contained in:
James Barnett
2017-05-31 12:10:13 -04:00
parent 70d39d08e1
commit ccfb4c1209

View File

@@ -7,6 +7,8 @@
# snapshot created on your system since that will be used to determine the # snapshot created on your system since that will be used to determine the
# difference for the next incremental snapshot. # difference for the next incremental snapshot.
set -o errtrace
version="0.4" version="0.4"
name="snap-sync" name="snap-sync"
@@ -16,14 +18,6 @@ mkfifo $PIPE
systemd-cat -t "$name" < $PIPE & systemd-cat -t "$name" < $PIPE &
exec 3>$PIPE exec 3>$PIPE
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
}
notify_error() { notify_error() {
for u in $(users); do for u in $(users); do
sudo -u $u DISPLAY=:0 \ sudo -u $u DISPLAY=:0 \
@@ -47,7 +41,12 @@ die() {
} }
traperror() { traperror() {
die "Exited due to error." out "==> ERROR: Exited due to error on line" $1
out "exit status:" "$2"
out "command:" "$3"
out "bash line:" "$4"
out "function name:" "$5"
exit 1
} }
trapkill() { trapkill() {
@@ -56,6 +55,17 @@ trapkill() {
[[ $EUID -ne 0 ]] && die "Script must be run as root." [[ $EUID -ne 0 ]] && die "Script must be run as root."
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() { usage() {
cat <<EOF cat <<EOF
$name $version $name $version
@@ -77,10 +87,8 @@ Options:
EOF EOF
} }
trap traperror ERR
trap trapkill SIGTERM SIGINT
ssh=""
ssh=""
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
key="$1" key="$1"
case $key in case $key in