tg.sh: make sure temporary directory is removed on signal
Only /bin/bash seems to trap all signals and run an EXIT
trap before terminating a script because of an uncaught
signal. Other shells just die.
However, we rely on the EXIT trap to remove our temporary
directory. Fix this by explicitly trapping the signals
we expect could terminate the script and explicitly calling
exit in the handler which will guarantee the EXIT trap
runs and does its thing.
When a process run by the shell dies of a signal, the exit
status is 128+signal, so use that as the exit status for
the various signals we trap on.
Additionally, POSIX defines 7 well-known signal numbers
that can be used. We omit traps on ALRM and KILL.
Signed-off-by: Kyle J. McKay <mackyle@gmail.com>