Skip to content

Instantly share code, notes, and snippets.

@mike-bourgeous
Forked from nitrogenlogic/00_mk_sfx_moved.md
Created October 23, 2016 00:40
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 mike-bourgeous/a48f8e8c87be9f0875bed16980ab1775 to your computer and use it in GitHub Desktop.
Save mike-bourgeous/a48f8e8c87be9f0875bed16980ab1775 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