Last active
July 1, 2024 20:08
-
-
Save ChrisCarini/d3e97c4bc7878524fa11 to your computer and use it in GitHub Desktop.
Embed TAR file in a shell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
what does TARFILE_FOLLOWS last line of the script mean?