aboutsummaryrefslogtreecommitdiffstats
path: root/testing/scripts/function.sh
diff options
context:
space:
mode:
authorReto Buerki <reet@codelabs.ch>2012-12-06 19:17:30 +0100
committerTobias Brunner <tobias@strongswan.org>2013-01-17 15:22:11 +0100
commit9a045eef8e003b46fb93369a7888d65b01730a1d (patch)
tree440491fa5722d856fefc8b3dbfada2ababfebd69 /testing/scripts/function.sh
parent7c2ef58e86c10e0cf9846dc9211cc68c7e908f7f (diff)
downloadstrongswan-9a045eef8e003b46fb93369a7888d65b01730a1d.tar.bz2
strongswan-9a045eef8e003b46fb93369a7888d65b01730a1d.tar.xz
Provide do_on_exit() function
This function allows to register an exit action which executes when the calling script terminates.
Diffstat (limited to 'testing/scripts/function.sh')
-rwxr-xr-xtesting/scripts/function.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/testing/scripts/function.sh b/testing/scripts/function.sh
index 3e0560a46..d9f2054ef 100755
--- a/testing/scripts/function.sh
+++ b/testing/scripts/function.sh
@@ -86,6 +86,34 @@ log_status()
echo
}
+# the following two functions are stolen from [1]
+# [1] - http://www.linuxjournal.com/content/use-bash-trap-statement-cleanup-temporary-files
+
+declare -a on_exit_items
+
+# perform registered actions on exit
+on_exit()
+{
+ for i in "${on_exit_items[@]}"
+ do
+ eval $i >>$LOGFILE 2>&1
+ done
+ on_exit_items=""
+ trap - EXIT
+}
+
+# register a command to execute when the calling script terminates. The
+# registered commands are called in FIFO order.
+# $* - command to register
+do_on_exit()
+{
+ local n=${#on_exit_items[*]}
+ on_exit_items[$n]="$*"
+ if [ $n -eq 0 ]; then
+ trap on_exit EXIT
+ fi
+}
+
#############################################
# search and replace strings throughout a
# whole directory