aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-16 18:38:49 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-16 18:38:49 +1200
commit0b1c99ffb1c3019e8afb9dcc542fbc5e868baef1 (patch)
tree9712aa161c25232e0f6561ee181b82eb42af347a /include
parentPut "all" subtargets on their own line (diff)
downloaddotfiles-0b1c99ffb1c3019e8afb9dcc542fbc5e868baef1.tar.gz
dotfiles-0b1c99ffb1c3019e8afb9dcc542fbc5e868baef1.zip
Template traps in scripts depending on mktd(1)
Diffstat (limited to 'include')
-rw-r--r--include/mktd.trap.sh15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/mktd.trap.sh b/include/mktd.trap.sh
new file mode 100644
index 00000000..388eb9be
--- /dev/null
+++ b/include/mktd.trap.sh
@@ -0,0 +1,15 @@
+# Create a temporary directory with name in $td, and handle POSIX-ish traps to
+# remove it when the script exits.
+td=
+cleanup() {
+ [ -n "$td" ] && rm -fr -- "$td"
+ if [ "$1" != EXIT ] ; then
+ trap - "$1"
+ kill "-$1" "$$"
+ fi
+}
+for sig in EXIT HUP INT TERM ; do
+ # shellcheck disable=SC2064
+ trap "cleanup $sig" "$sig"
+done
+td=$(mktd "$self") || exit