Self-extracting compressed files

Today I created a self-extracting, compressed file from a pdf document (disclosure.pdf). First I compressed the pdf file:

bzip2 disclosure.pdf

Then I create a text file (header.txt) with the following content:

!/bin/sh
echo ""
echo "MyPackage v99.99 - extracting archive with bunzip2... please wait"
echo ""
SKIP=`awk '/^__ARCHIVE_FOLLOWS__/ { print NR + 1; exit 0; }' $0`
#take the archive portion of this file and pipe it to bunzip2
tail +$SKIP $0 | bunzip2 > disclosure.pdf
exit 0
__ARCHIVE_FOLLOWS__

Then I concatenate both files (header.txt and disclosure.pdf.bzip2):

cat header.txt disclosure.pdf.bzip2 > disclosure.pdf.bzip2.sh

After this I just have to give the file execution privileges for everybody:

chmod a+x disclosure.pdf.bzip2.sh

To uncompress the file, I just type:

./disclosure.pdf.bzip2.sh

Of course the bunzip2 program has to be installed on the system of the recipient of this file; one can easily replace the bzip2 algorithm by any other, e.g. tar.