Never invent temp paths: mktemp gives an unpredictable name (no symlink
attacks, no collisions), and the EXIT trap removes it on normal exit and
set -e failure.
tmp=$(mktemp -d) && trap 'rm -rf "$tmp"' EXITtrap 'exit 130' INT TERM # dash and ash skip the EXIT trap on signals without thisWhere it breaks: bash runs the EXIT trap on Ctrl-C, but dash and busybox
ash do not, hence the second line, which turns the signal into an exit that
does. A shell has one EXIT trap; a second trap ... EXIT silently
replaces the first, so merge cleanups into one handler. kill -9 runs no
trap; nothing survives that, which is why installers still stage as .new.*
and rename into place.