Self Installing Packages

From Zanecorpwiki

Jump to: navigation, search

A 'self installing script' is one that carries logic with one or more payloads, usually tar files. As part of the install logic, the payload is separated from the rest of the script and expanded into the files to be installed.

In the case of a single payload, there are only three steps.

  1. Append a marker to the end of the logic script; something like '__TAR_FOLLOWS__'. Typically, one has a 'base' install script and the payload is cat'ed onto the end of the base file with something like 'tar cz foo/* >> install_script.sh'
  2. In the install logic, you'll have a line like TAR_START=`cat $0 | awk '/^__TAR_FOLLOWS__/ { print NR }'` This will find the line where the tar file begins.
  3. Use tail to extract the payload: tail +$TAR_START $0 | tar xz -C install_location

If there's more than one payload, the extraction gets a little more complex, but you have the same idea.

  1. Append different markers to each payload at the beginning and end.
  2. Find the beginning and end with START=`cat $0 | awk '/^__TAR_FOLLOWS__/ { print NR }'` and END=`cat $0 | awk '/^__TAR_FOLLOWS__/ { print NR }'`
  3. We have to use awk to extract the more complex payloads: cat $0 | awk "NR > $START { print \$0 }; NR - 1 == $END { exit }" | tar xz -C install_dir
Personal tools