Skip to content

Instantly share code, notes, and snippets.

@0wwafa
Forked from alexradzin/selftar.sh
Last active September 16, 2024 17:52
Show Gist options
  • Save 0wwafa/5864c61b373700c1e04fe32db85a2e13 to your computer and use it in GitHub Desktop.
Save 0wwafa/5864c61b373700c1e04fe32db85a2e13 to your computer and use it in GitHub Desktop.
Script that creates self extracting executable script from tar.gz file.
#!/bin/sh
if [ $# -eq 0 ]; then
echo "This script creates self extractable executable"
echo Usage: $0 TAR.GZ [COMMAND]
exit;
fi
if [ $# -gt 0 ]; then
TAR_FILE=$1
fi
EXIT_COMMAND=exit
if [ $# -gt 1 ]; then
EXIT_COMMAND="exec $2"
fi
SELF_EXTRACTABLE="$TAR_FILE.self"
echo '#!/bin/sh' > $SELF_EXTRACTABLE
echo 'dd status=none bs=`head -3 $0 | wc -c` skip=1 if=$0 | gunzip -c | tar -x' >> $SELF_EXTRACTABLE
echo "$EXIT_COMMAND" >> $SELF_EXTRACTABLE
cat $TAR_FILE >> $SELF_EXTRACTABLE
chmod a+x $SELF_EXTRACTABLE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment