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.
7 if test $# -lt 2 ; then
8 echo "usage: $0 <output> <files>"
14 printf "%s\n" "$i" |
sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"
22 mode
="$(ls -ld "$1" | awk '{ print $1 }' | tr '[A-Z]' '-' | cut -c2-)"
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
29 mode
=$
(echo "$mode" | cut
-c4-)
40 if test -f "$f" ; then
44 trap 'rm "$tmpout"' EXIT
49 if test -z "$clear" ; then
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"
63 echo "can't add unknown file type $f" >&2
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"
76 trap 'rm -rf "\$outdir"' EXIT INT QUIT TERM HUP
80 set -- $(save "$@") "\$@"
84 test "\$l" = "exit 0;" && break
87 while test \$# -gt \$argc ; do
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"
109 chmod "\$mode" "\$outdir/\$fn" || :
112 PATH="\$outdir:\$PATH" "\$outdir/$exe" "\$@"
118 cat "$tmpout" >> "$out"