Skip to content

Instantly share code, notes, and snippets.

@Orc
Created April 10, 2017 19:19
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 Orc/f12191fe71c7c36b3794bbf0371fc702 to your computer and use it in GitHub Desktop.
Save Orc/f12191fe71c7c36b3794bbf0371fc702 to your computer and use it in GitHub Desktop.
A tiny sharfile generator that uses base64 to encode/decode (for redhat Linux; base64 is in coreutils, which is an rpm prerequisite so it's more likely to always be there)
#! /bin/sh
#
# mkshar: make a shar file
#
usage() {
echo "usage: $0 [--rc file] payload [...]" 1>&2
exit 1
}
unset checksums
case X"$1" in
X-rc|X--rc) rc=$2
shift 2 ;;
X-md5|X--md5) checksums=Y
shift ;;
X-*) usage ;;
esac
cat - << \EOF
#! /bin/sh
# self extracting archive
# make a tempfile, go there to do the work
DEST=`mktemp -d /tmp/sb.XXXXXX`
test "$DEST" || exit 1
trap "cd /tmp; rm -rf $DEST" 1 2 3 9 15
cd $DEST || exit 1
EOF
# encode all the input files into base64, set up the script
# to unpack them into their basename in this directory
seq=1
for file in "$@"; do
echo
echo "# $seq: $file"
echo "base64 -d > `basename $file` << \EOF"
base64 "$file"
echo EOF
(( seq ++ ))
done
# want to do something with this tarball? Hope so!
if [ "$rc" ]; then
echo
echo "# process everything now that we're done with it"
cat "$rc"
elif [ "$checksums" ]; then
echo
echo 'md5sum *'
fi
cat - << \EOF
# clean up after we're finished
cd /tmp
rm -rf $DEST
EOF
echo "exit 0"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment