Add a whitespace rule for the "elixir" lexer.
[vis.git] / shar.sh
blobc7a532c70c41965119a48318ad0afcef4db655a9
1 #!/bin/sh
2 # Modified version of https://shiz.me/junk/code/fun/shar.sh
3 # The generated shell archive is automatically extracted to a
4 # temporary directory and the first archive member is executed.
5 set -e
7 if test $# -lt 2 ; then
8 echo "usage: $0 <output> <files>"
9 exit 1
12 save() {
13 for i ; do
14 printf "%s\n" "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"
15 done
16 echo " "
19 octal_mode() {
20 local mode
22 mode="$(ls -ld "$1" | awk '{ print $1 }' | tr '[A-Z]' '-' | cut -c2-)"
23 for i in 1 2 3 ; do
24 i=0
25 case "$mode" in r??*) i=$((i + 4)) ;; esac
26 case "$mode" in ?w?*) i=$((i + 2)) ;; esac
27 case "$mode" in ??-*) ;; ???*) i=$((i + 1)) ;; esac
28 printf "%d" "$i"
29 mode=$(echo "$mode" | cut -c4-)
30 done
33 out=$1
34 tmpout=$1.tmp
35 exe=$2
36 shift
38 rm -f "$tmpout"
39 for f ; do
40 if test -f "$f" ; then
41 cat "$f" >> "$tmpout"
43 done
44 trap 'rm "$tmpout"' EXIT
46 clear=
48 for f ; do
49 if test -z "$clear" ; then
50 set --
51 clear=1
54 mode=$(octal_mode "$f")
55 if test -f "$f" ; then
56 size=$(wc -c "$f" | awk '{ print $1 }')
57 echo "adding: $f (mode $mode, $size bytes)"
58 set -- "$@" "f+$mode+$size:$f"
59 elif test -d "$f" ; then
60 echo "adding directory: $f (mode $mode)"
61 set -- "$@" "d+$mode:$f"
62 else
63 echo "can't add unknown file type $f" >&2
65 done
67 cat >"$out"<<HEADER
68 #!/bin/sh
69 set -e
71 outdir="\$(mktemp -d -p "\${TMPDIR:-/tmp}" .unshar-XXXXXX)"
72 if test \$? -ne 0 -o ! -d "\$outdir" ; then
73 echo "failed to create temporary directory"
74 exit 1
76 trap 'rm -rf "\$outdir"' EXIT INT QUIT TERM HUP
77 argc=\$#
79 self="\$0"
80 set -- $(save "$@") "\$@"
82 exec 3<"\$self"
83 while read -r l ; do
84 test "\$l" = "exit 0;" && break
85 done <&3
87 while test \$# -gt \$argc ; do
88 file="\$1"
89 shift
90 meta="\${file%%:*}"
91 fn="\${file#*:}"
92 type="\${meta%%+*}"
93 meta="\${meta#*+}"
94 mode="\${meta%%+*}"
95 size="\${meta#*+}"
96 base="\${fn%/*}"
98 case "\$type" in
100 echo "unpacking: \$fn (mode \$mode, \$size bytes)"
101 test "\$base" != "\$fn" && mkdir -p "\$outdir/\$base"
102 dd of="\$outdir/\$fn" bs="\$size" count=1 >/dev/null <&3
105 echo "creating: \$fn (mode \$mode)"
106 mkdir -p "\$outdir/\$fn"
108 esac
109 chmod "\$mode" "\$outdir/\$fn" || :
110 done >/dev/null 2>&1
112 PATH="\$outdir:\$PATH" "\$outdir/$exe" "\$@"
113 exit \$?
115 exit 0;
116 HEADER
118 cat "$tmpout" >> "$out"
119 chmod +x "$out"