---
title: "Creating Self-Extracting Sources Files"
description: "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."
url: "https://h3manth.com/scribe/creating-self-extracting-sources-files/"
canonical_url: "https://h3manth.com/scribe/creating-self-extracting-sources-files/"
markdown_url: "https://h3manth.com/scribe/blog/creating-self-extracting-sources-files.md"
publishDate: "2009-12-10T00:00:00.000Z"
author: "Hemanth HM"
category: "linux"
tags: ["bash"]
word_count: 223
reading_time_minutes: 2
x_markdown_tokens: 406
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# 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.

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.

**Steps**

**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 build.sh script which takes care of installing each and every source.

**Step 2** _Make an extractor script as below_ **``**

## !/bin/bash

## 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

FILE=`pwd`/$0

## take the tarfile and pipe it into tar

tail -n+$COUNT $FILE | tar -xz

echo "Finished" cd sources

## build.sh to build and install the sources as per your need

./build.sh

## Remove the source folder

cd .. ; rm -rf sources exit 0

**SOURCE**

**Step 3** _Final move_ Make the file ready, that is embed the tgz below the extractor.sh **`cat source.tgz extractor.sh> install.sh ` **

**That's it run the install.sh to do whatever its intended to do**
