diff options
author | Robin Obůrka <r.oburka@gmail.com> | 2016-08-23 20:47:19 +0200 |
---|---|---|
committer | Robin Obůrka <r.oburka@gmail.com> | 2016-08-23 20:47:19 +0200 |
commit | 2456c6aa5e83a1264e522a33a1a8a8d4eb683840 (patch) | |
tree | d633348289dd49fffe71f999161a78a148e640ae | |
parent | get_size: Use simpler command to extract size (diff) | |
download | backuper-2456c6aa5e83a1264e522a33a1a8a8d4eb683840.tar.xz |
Unify error and die functions. They are almost the same
-rw-r--r-- | backuper.sh | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/backuper.sh b/backuper.sh index 684778e..ae9e289 100644 --- a/backuper.sh +++ b/backuper.sh @@ -88,13 +88,8 @@ compute_gpg_recipients() { ## Program control error() { - echo "ERROR: $1" >&2 - kill -6 "$$" -} - -die() { if [ -n "$1" ]; then - echo "DIE: $1" >&2 + echo "ERROR: $1" >&2 fi ## -6 ~ SIGABRT ## This is the only SIGNAL that cleanup doesn't reset @@ -241,7 +236,7 @@ cleanup() { backup_done() { if [ -n "$AFTER" ]; then title "After backup hook" - echo "$AFTER" | /usr/bin/time -f "$(time_fmt "Command took")" sh -s || die "After-backup hook failed" + echo "$AFTER" | /usr/bin/time -f "$(time_fmt "Command took")" sh -s || error "After-backup hook failed" fi } @@ -257,7 +252,7 @@ add_stage() { [ ! -p "$RUNDIR"/fifo_"$NEXTSTAGE" ] && mkfifo "$RUNDIR"/fifo_"$NEXTSTAGE" ## Run requested command and store PID - $@ > "$RUNDIR"/fifo_"$NEXTSTAGE" < "$RUNDIR"/fifo_"$STAGE" || die "One of the pipeline commands failed" & + $@ > "$RUNDIR"/fifo_"$NEXTSTAGE" < "$RUNDIR"/fifo_"$STAGE" || error "One of the pipeline commands failed" & echo "$!" >> "$RUNDIR"/"$PID_FILE" ## Process started - increment @@ -297,10 +292,10 @@ EOT ## While loop is executed in subshell - this hack keeps variables fi - start_store || die "Store command failed" & + start_store || error "Store command failed" & PID_STORE=$! - start_command || die "Backup command failed" & + start_command || error "Backup command failed" & PID_GENERATE=$! wait "$PID_STORE" "$PID_GENERATE" |