diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Makefile | 28 | ||||
-rw-r--r--[-rwxr-xr-x] | bin/rndl.m4 (renamed from bin/rndl) | 16 | ||||
-rw-r--r--[-rwxr-xr-x] | bin/tlcs.m4 (renamed from bin/tlcs) | 16 | ||||
-rw-r--r--[-rwxr-xr-x] | bin/try.m4 (renamed from bin/try) | 18 | ||||
-rw-r--r--[-rwxr-xr-x] | bin/urlc.m4 (renamed from bin/urlc) | 14 | ||||
-rw-r--r-- | include/mktd.trap.sh | 15 |
7 files changed, 51 insertions, 60 deletions
@@ -1,6 +1,10 @@ +bin/rndl bin/sd2u bin/su2d +bin/tlcs +bin/try bin/unf +bin/urlc games/acq games/kvlt games/zs @@ -60,17 +60,25 @@ EMAIL := tom@sanctum.geek.nz KEY := 0xC14286EA77BB8872 SENDMAIL := /usr/bin/msmtp -all : bin/sd2u \ +all : bin/rndl \ + bin/sd2u \ bin/su2d \ + bin/tlcs \ + bin/try \ bin/unf \ + bin/urlc \ git/gitconfig \ gnupg/gpg.conf clean distclean : rm -f \ + bin/rndl \ bin/sd2u \ bin/su2d \ + bin/tlcs \ + bin/try \ bin/unf \ + bin/urlc \ games/acq \ games/kvlt \ games/zs \ @@ -80,6 +88,24 @@ clean distclean : mutt/muttrc \ tmux/tmux.conf +# shell scripts that need a templated trap to remove a temporary directory +bin/rndl : bin/rndl.m4 include/mktd.trap.sh + m4 bin/rndl.m4 > "$@" + chmod +x "$@" + +bin/tlcs : bin/tlcs.m4 include/mktd.trap.sh + m4 bin/tlcs.m4 > "$@" + chmod +x "$@" + +bin/try : bin/try.m4 include/mktd.trap.sh + m4 bin/try.m4 > "$@" + chmod +x "$@" + +bin/urlc : bin/urlc.m4 include/mktd.trap.sh + m4 bin/urlc.m4 > "$@" + chmod +x "$@" + +# sed scripts that need a pathed shebang bin/sd2u : bin/sd2u.sed bin/shb bin/sd2u.sed sed -f > "$@" chmod +x "$@" diff --git a/bin/rndl b/bin/rndl.m4 index 2ac3bf47..85b21545 100755..100644 --- a/bin/rndl +++ b/bin/rndl.m4 @@ -7,21 +7,7 @@ # file if we don't want to read all of the input into memory (!) if [ "$#" -eq 0 ] ; then - # Try to create the temporary directory with mktd(1) safely - 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 rndl) || exit - +include(`include/mktd.trap.sh') # We'll operate on stdin in the temp directory; write the script's stdin to # it with cat(1) set -- "$td"/stdin diff --git a/bin/tlcs b/bin/tlcs.m4 index dcd76c7d..ff01cc0d 100755..100644 --- a/bin/tlcs +++ b/bin/tlcs.m4 @@ -67,21 +67,7 @@ if [ "$((color_count >= 8))" -eq 1 ] ; then fi fi -# Temporary directory for the FIFOs -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 - +include(`include/mktd.trap.sh') # Execute the command, passing stdout and stderr to tl(1) calls as appropriate # via named pipes out=$td/out err=$td/err diff --git a/bin/try b/bin/try.m4 index f0ba317d..359a4280 100755..100644 --- a/bin/try +++ b/bin/try.m4 @@ -26,23 +26,9 @@ if [ "$#" -eq 0 ] ; then exit 2 fi -# Create a buffer file for the error output, and clean up the file when we exit -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 -errbuff=$td/errbuff - +include(`include/mktd.trap.sh') # Open a filehandle to the error buffer, just to save on file operations +errbuff=$td/errbuff exec 3>"$errbuff" # Keep trying the command, writing error output to the buffer file, and exit diff --git a/bin/urlc b/bin/urlc.m4 index 63f075bf..c49c1ecf 100755..100644 --- a/bin/urlc +++ b/bin/urlc.m4 @@ -5,21 +5,9 @@ self=urlc # cURL request timeout tm=${URLCHECK_TIMEOUT:-8} +include(`include/mktd.trap.sh') # Create buffer files for the headers and body content, to be cleaned up on # exit -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 list=$td/list head=$td/head body=$td/body # Iterate through input; ignore leading/trailing whitespace diff --git a/include/mktd.trap.sh b/include/mktd.trap.sh new file mode 100644 index 00000000..388eb9be --- /dev/null +++ b/include/mktd.trap.sh @@ -0,0 +1,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 |