From: Alexander Schmidt <alex@treefish.org>
Date: Wed, 30 Jul 2014 15:23:52 +0000 (+0200)
Subject: Using only one cleanup function with abort switch.
X-Git-Url: http://git.treefish.org/~alex/backmeupscotty.git/commitdiff_plain/055e3ffadca7fb5b75a8625de2005f40c888afa9

Using only one cleanup function with abort switch.
---

diff --git a/backmeupscotty b/backmeupscotty
index 257c192..88a8739 100644
--- a/backmeupscotty
+++ b/backmeupscotty
@@ -111,19 +111,17 @@ function prepare {
 }
 
 function cleanup_abort {
-    scottyinfo "No cleanup_abort function was defined."
-}
-
-function _cleanup_abort {
     scottyerror "Caught exit signal! Cleaning up..."
 
-    cleanup_abort
+    cleanup ABORT
 
     if [ $(jobs -p) ]; then
 	scottyerror TERMinating remaining child processes...
 	kill $(jobs -p)
     fi
+
     deleteLock
+
     exit
 }
 
@@ -132,7 +130,8 @@ function prepare {
 }
 
 function cleanup_normal {
-    scottyinfo "No cleanup_normal function was defined."
+    cleanup
+    deleteLock
 }
 
 function printhelp {
@@ -167,13 +166,12 @@ function backmeupscotty {
 	exit 0
     fi
 
-    trap _cleanup_abort EXIT
+    trap cleanup_abort EXIT
 
     prepare
     scottysync
-    cleanup_normal
 
-    trap deleteLock EXIT
+    trap cleanup_normal EXIT
 
     exit 0
 }
diff --git a/backmeupscotty-example b/backmeupscotty-example
index 44d97cd..a028abe 100755
--- a/backmeupscotty-example
+++ b/backmeupscotty-example
@@ -12,14 +12,11 @@ SYNC_EXC="/gack,/gugu/*"
 
 function prepare {
     echo "prepare"
+    sleep 5
 }
 
-function cleanup_normal {
-    echo "cleanup"
-}
-
-function cleanup_abort {
-    echo "cleanup_abort"
+function cleanup {
+    [ -z "$1" ] && echo "normal cleanup" || echo "abort cleanup"
 }
 
 backmeupscotty $@