From da4e2efb9249cb8cd1e382a7653da0140bb1c95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 31 Mar 2017 08:28:10 +0200 Subject: Use a minimal POSIX shar implementation for self extracting executable This only requires POSIX shell utilies for extraction. The resulting archive is bigger (it is not gzip compressed) and startup will be slower due to many spawned processes. --- GNUmakefile | 3 +- shar.sh | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vis-single.sh | 14 ------- 3 files changed, 121 insertions(+), 16 deletions(-) create mode 100755 shar.sh delete mode 100755 vis-single.sh diff --git a/GNUmakefile b/GNUmakefile index c19a64c..16635c0 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -256,10 +256,9 @@ standalone: clean PATH=$(DEPS_BIN):$$PATH $(MAKE) single: standalone - cp vis-single.sh vis-single for e in $(ELF); do \ ${STRIP} "$$e"; \ done - tar c $(EXECUTABLES) lua/ | gzip -9 >> vis-single + ./shar.sh vis-single $(EXECUTABLES) $$(find lua -name '*.lua') .PHONY: standalone local dependencies-common dependencies-local dependencies-clean diff --git a/shar.sh b/shar.sh new file mode 100755 index 0000000..c7a532c --- /dev/null +++ b/shar.sh @@ -0,0 +1,120 @@ +#!/bin/sh +# Modified version of https://shiz.me/junk/code/fun/shar.sh +# The generated shell archive is automatically extracted to a +# temporary directory and the first archive member is executed. +set -e + +if test $# -lt 2 ; then + echo "usage: $0 " + exit 1 +fi + +save() { + for i ; do + printf "%s\n" "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" + done + echo " " +} + +octal_mode() { + local mode + + mode="$(ls -ld "$1" | awk '{ print $1 }' | tr '[A-Z]' '-' | cut -c2-)" + for i in 1 2 3 ; do + i=0 + case "$mode" in r??*) i=$((i + 4)) ;; esac + case "$mode" in ?w?*) i=$((i + 2)) ;; esac + case "$mode" in ??-*) ;; ???*) i=$((i + 1)) ;; esac + printf "%d" "$i" + mode=$(echo "$mode" | cut -c4-) + done +} + +out=$1 +tmpout=$1.tmp +exe=$2 +shift + +rm -f "$tmpout" +for f ; do + if test -f "$f" ; then + cat "$f" >> "$tmpout" + fi +done +trap 'rm "$tmpout"' EXIT + +clear= + +for f ; do + if test -z "$clear" ; then + set -- + clear=1 + fi + + mode=$(octal_mode "$f") + if test -f "$f" ; then + size=$(wc -c "$f" | awk '{ print $1 }') + echo "adding: $f (mode $mode, $size bytes)" + set -- "$@" "f+$mode+$size:$f" + elif test -d "$f" ; then + echo "adding directory: $f (mode $mode)" + set -- "$@" "d+$mode:$f" + else + echo "can't add unknown file type $f" >&2 + fi +done + +cat >"$out"<
/dev/null <&3 + ;; + d) + echo "creating: \$fn (mode \$mode)" + mkdir -p "\$outdir/\$fn" + ;; + esac + chmod "\$mode" "\$outdir/\$fn" || : +done >/dev/null 2>&1 + +PATH="\$outdir:\$PATH" "\$outdir/$exe" "\$@" +exit \$? + +exit 0; +HEADER + +cat "$tmpout" >> "$out" +chmod +x "$out" + diff --git a/vis-single.sh b/vis-single.sh deleted file mode 100755 index e779b67..0000000 --- a/vis-single.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -set -e - -VISTMP="$(mktemp -d -p "${TMPDIR:-/tmp}" .vis-XXXXXX)" -trap 'rm -rf "$VISTMP"' EXIT INT QUIT TERM HUP - -sed '1,/^__TAR_GZ_ARCHIVE_BELOW__$/d' "$0" | gzip -d | tar xC "$VISTMP" - -PATH="$VISTMP:$PATH" "$VISTMP/vis" "$@" - -exit $? - -__TAR_GZ_ARCHIVE_BELOW__ -- cgit v1.2.3