aboutsummaryrefslogtreecommitdiff
path: root/include/mktd.mi5
blob: 388eb9be83d90435591cccbd33c4d2c4f4680d6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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