Creating Self-Extracting sources files

The idea is pretty simple : Embed all your tgz's below a place holder and count the lines to get each tgz and pipe tail and tar to extract them to required folder.


Step I Make a tgz file with all the source you have
Assuming we call the folder to be source, so the compressed file must be source.tgz and the source might contain any extractable files, even simple shell scripts.
Lets assume that our source folder has a script which takes care of installing each and every source.

Step 2 Make an extractor script as below

#Author : Hemanth 
echo ""
echo "Self Extracting Files"
echo ""
echo ""
echo "Extracting file into `pwd`/source"
#Count for source list
COUNT=`awk '/^__SOURCE__/ { print NR + 1; exit 0; }' $0`
#The current file
# take the tarfile and pipe it into tar
tail -n+$COUNT $FILE | tar -xz
echo "Finished"
cd sources to build and install the sources as per your need
#Remove the source folder
cd .. ; rm -rf sources
exit 0

Step 3 Final move
Make the file ready, that is embed the tgz below the
 cat source.tgz >

That's it run the to do whatever its intended to do

Share this