Skip to content

Instantly share code, notes, and snippets.

@ChrisCarini
Last active February 27, 2024 05:41
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save ChrisCarini/d3e97c4bc7878524fa11 to your computer and use it in GitHub Desktop.
Save ChrisCarini/d3e97c4bc7878524fa11 to your computer and use it in GitHub Desktop.
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__
@Xphobia
Copy link

Xphobia commented May 18, 2021

what does TARFILE_FOLLOWS last line of the script mean?

@ChrisCarini
Copy link
Author

@Xphobia - it's a marker; see how it is used on line 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment