Skip to content

Instantly share code, notes, and snippets.

@andrewpolidori
Forked from ChrisCarini/embeddedPayload.sh
Created April 29, 2019 19:08
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 andrewpolidori/bd0addccba475a2013784d6b1cc4f600 to your computer and use it in GitHub Desktop.
Save andrewpolidori/bd0addccba475a2013784d6b1cc4f600 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__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment