aboutsummaryrefslogtreecommitdiff
path: root/utils/cleaner
blob: 4919085e687a1d946351c5942aa16a54e5db9114 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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")"
}