Skip to content

Instantly share code, notes, and snippets.

@miekg
Last active December 18, 2015 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miekg/5853200 to your computer and use it in GitHub Desktop.
Save miekg/5853200 to your computer and use it in GitHub Desktop.
zbundle
#!/bin/bash
set -e
getopts "s" show && shift
if [[ $show == "s" ]]; then
while read line; do
hex="$(echo $line | od -N4 -x | head -1)"
byte=(${hex})
if [[ ${byte[1]} == "4b50" && ${byte[2]} == "0403" ]]; then
break
fi
fragment="$fragment$newline$line"
newline="\n"
done < ${1:-/dev/stdin}
echo -e $fragment
exit
fi
if [[ -z "$1" ]]; then
cat << EOF
$0 FILE...
$0 -s [FILE]
Prefix the zip file created of FILEs with a shell fragment.
The zip file is self extracting and after doing so it executes the shell fragment.
The name of the zip file is FILE.zip.
-s show the contents of shell fragment on standard output
EOF
exit
fi
fragment=$(mktemp)
cat << EOF > $fragment
#!/bin/bash
unzip -qo \$0 2>/dev/null
exit
EOF
trap "rm $fragment" EXIT
${EDITOR:-vi} $fragment
cat $fragment <(zip - "$@") > "$1".zip && chmod +x "$1".zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment