Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Embed TAR file in a shell script
#!/bin/bash
# Instructions:
# 1) Create your TAR archive
# tar -czpf file.tar <file1> <file2> ... <fileN>
# 2) Append the TAR file contents to the script
# cat file.tar >> embeddedPayload.sh
# 3) Run script. (./embeddedPayload.sh)
echo "Bash Source: "${BASH_SOURCE[0]}
# Script Varibles
SCRIPT_DIR="$(cd -P "$( dirname "${BASH_SOURCE[0]}" )" ; pwd)"
SKIP=$(awk '/^__TARFILE_FOLLOWS__/ { print NR + 1; exit 0; }' $0)
echo "Script Dir: " $SCRIPT_DIR
echo "Skip: "$SKIP
# Extract
echo "Extracting install ... "
tail -n +${SKIP} $0 | tar -zpvx
exit 0
# NOTE: Don't place any newline characters after the last line below.
__TARFILE_FOLLOWS__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.