From f287ecedc78c0cc8fb485c5995b8d1cfae9f0fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 20 Sep 2017 21:19:05 +0200 Subject: Commit current state --- utils/cleaner | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 utils/cleaner (limited to 'utils/cleaner') diff --git a/utils/cleaner b/utils/cleaner new file mode 100644 index 0000000..4919085 --- /dev/null +++ b/utils/cleaner @@ -0,0 +1,23 @@ +# vim:ft=sh:noexpandtab +# Functions for cleanups + +EXIT_CODE=0 + +do_cleanup() { + echo "$CLEANUP_ACTIONS" | while read CMD; do + eval "$CMD" + done + exit $EXIT_CODE +} + +trap do_cleanup EXIT INT QUIT TERM ABRT + +cleaner_add() { + CLEANUP_ACTIONS="$CLEANUP_ACTIONS +$@" +} + +cleaner_rm() { + # TODO this might be problematic with special characters + CLEANUP_ACTIONS="$(echo "$CLEANUP_ACTIONS" | sed "/^$@$/d")" +} -- cgit v1.2.3