Skip to content

Instantly share code, notes, and snippets.

@mokrates
Last active April 28, 2023 00:14
Show Gist options
  • Save mokrates/382d63c82862c0d176edae8f75127261 to your computer and use it in GitHub Desktop.
Save mokrates/382d63c82862c0d176edae8f75127261 to your computer and use it in GitHub Desktop.
self extracting archive with bash
#!/bin/bash
if [ "${1::1}" == "/" ]; then
echo "refusing to archive absolute filenames" >&2
exit 1
fi
while [ "$1" != "" ]; do
if [ -d "$1" ]; then
"$0" "$1"/*
shift
else
if [ "$(dirname $1)" != "." ]; then
echo "mkdir -p '$(dirname $1)'"
fi
echo "base64 -d << '+++' | gunzip > '$1'"
cat "$1" | gzip | base64
echo +++
shift
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment