aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-16 19:49:35 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-16 19:49:35 +1200
commit6cbb1755813b9fd3ad016aafc202a36eda37718a (patch)
treed7d985980ef5fa78572f13b867d6b0bdfd9f3a24
parentApply suffix rules for games/bin building (diff)
downloaddotfiles-6cbb1755813b9fd3ad016aafc202a36eda37718a.tar.gz
dotfiles-6cbb1755813b9fd3ad016aafc202a36eda37718a.zip
Reverse .m4 translation for binscripts
Either this is overengineering, or I don't understand m4 well enough.
-rw-r--r--.gitignore4
-rw-r--r--Makefile16
-rwxr-xr-x[-rw-r--r--]bin/rndl (renamed from bin/rndl.m4)17
-rwxr-xr-x[-rw-r--r--]bin/tlcs (renamed from bin/tlcs.m4)17
-rwxr-xr-x[-rw-r--r--]bin/try (renamed from bin/try.m4)17
-rwxr-xr-x[-rw-r--r--]bin/urlc (renamed from bin/urlc.m4)17
-rw-r--r--include/mktd.trap.sh15
7 files changed, 65 insertions, 38 deletions
diff --git a/.gitignore b/.gitignore
index cd8f5170..45f195cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,10 +1,6 @@
-bin/rndl
bin/sd2u
bin/su2d
-bin/tlcs
-bin/try
bin/unf
-bin/urlc
games/acq
games/kvlt
games/zs
diff --git a/Makefile b/Makefile
index a8b448d5..696f33fb 100644
--- a/Makefile
+++ b/Makefile
@@ -62,25 +62,17 @@ EMAIL := tom@sanctum.geek.nz
KEY := 0xC14286EA77BB8872
SENDMAIL := /usr/bin/msmtp
-all : bin/rndl \
- bin/sd2u \
+all : 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 \
@@ -117,12 +109,6 @@ tmux/tmux.conf : tmux/tmux.conf.m4
m4 -D TMUX_COLOR="$(TMUX_COLOR)" \
tmux/tmux.conf.m4 > tmux/tmux.conf
-# shell scripts that need a templated trap to remove a temporary directory
-.m4 :
- m4 "$<" > "$@"
- chmod +x "$@"
-
-# sed scripts that need a pathed shebang
.sed :
bin/shb "$<" sed -f > "$@"
chmod +x "$@"
diff --git a/bin/rndl.m4 b/bin/rndl
index 536f5c21..7d5cb6b7 100644..100755
--- a/bin/rndl.m4
+++ b/bin/rndl
@@ -8,7 +8,22 @@ self=rndl
# file if we don't want to read all of the input into memory (!)
if [ "$#" -eq 0 ] ; then
-include(`include/mktd.trap.sh')
+ # 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
+
# 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.m4 b/bin/tlcs
index ff01cc0d..30068303 100644..100755
--- a/bin/tlcs.m4
+++ b/bin/tlcs
@@ -67,7 +67,22 @@ if [ "$((color_count >= 8))" -eq 1 ] ; then
fi
fi
-include(`include/mktd.trap.sh')
+# 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
+
# 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.m4 b/bin/try
index 359a4280..7d6d57a8 100644..100755
--- a/bin/try.m4
+++ b/bin/try
@@ -26,7 +26,22 @@ if [ "$#" -eq 0 ] ; then
exit 2
fi
-include(`include/mktd.trap.sh')
+# 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
+
# Open a filehandle to the error buffer, just to save on file operations
errbuff=$td/errbuff
exec 3>"$errbuff"
diff --git a/bin/urlc.m4 b/bin/urlc
index c49c1ecf..e306d48f 100644..100755
--- a/bin/urlc.m4
+++ b/bin/urlc
@@ -5,7 +5,22 @@ self=urlc
# cURL request timeout
tm=${URLCHECK_TIMEOUT:-8}
-include(`include/mktd.trap.sh')
+# 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
+
# Create buffer files for the headers and body content, to be cleaned up on
# exit
list=$td/list head=$td/head body=$td/body
diff --git a/include/mktd.trap.sh b/include/mktd.trap.sh
deleted file mode 100644
index 388eb9be..00000000
--- a/include/mktd.trap.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-# 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