Last active
December 18, 2015 22:18
-
-
Save miekg/5853200 to your computer and use it in GitHub Desktop.
zbundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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