Last active
November 6, 2023 01:53
-
-
Save gregjhogan/bfcffe88ac9d6865efc5 to your computer and use it in GitHub Desktop.
self-extracting 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
# create files in an otherwise empty directory | |
mkdir files | |
cd files | |
touch setup.sh # entry point after extraction | |
touch file.txt # supporting data used by setup.sh | |
# create archive | |
tar -pczf ../archive.tar.gz * | |
cd .. | |
# create self-extracting script | |
cat <<EOF > install.sh | |
#!/bin/sh | |
cd \$(dirname \$0) && mkdir -p install && tail -n+4 \$0 | base64 -d | tar -pzxf - -C ./install && cd install && ./setup.sh >setup.log 2>&1 | |
exit \$? | |
EOF | |
# append archive | |
base64 -w 0 archive.tar.gz >> install.sh | |
chmod ug+x install.sh | |
# test | |
mkdir test | |
cp install.sh test/ | |
cd test | |
./install.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment