Skip to content

Instantly share code, notes, and snippets.

@nitrogenlogic
Last active October 23, 2016 00:41
Show Gist options
  • Save nitrogenlogic/1024317 to your computer and use it in GitHub Desktop.
Save nitrogenlogic/1024317 to your computer and use it in GitHub Desktop.
Quick-and-dirty script to create a quasi-self-extracting bzipped tar archive
#!/bin/bash
# Creates a base64-encoded self-extracting tar archive. The extracting system
# must have GNU tar, GNU coreutils (for base64), and bzip2 installed.
# Created June 2011 by Mike Bourgeous
# Released into the public domain, or if that is not possible, under CC0
function create_archive()
{
set -e
echo '#!/bin/sh'
echo 'cat << _SFX_EOF_ | base64 -d | tar -jxp'
tar -jcv -- "$@" | base64 -w 120
RESULT=${PIPESTATUS[0]}
echo '_SFX_EOF_'
return $RESULT
}
if [ "$1" = "" -o "$2" = "" ]; then
echo "Usage: $0 output_file input_files..."
echo "Use '-' for output_file to send to stdout"
exit 1
fi
OUTFILE="$1"
set -e
shift
if [ "$OUTFILE" = "-" ]; then
create_archive "$@"
else
create_archive "$@" > "$OUTFILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment