Monday, March 8, 2010

How to create self-Extracting script

It involves 3 steps,
  1. Create Payload
  2. Create Installer script
  3. Packaging
Create Payload:
This is a tar ball  in which all the installable binaries, libraries, script files, configuration files, etc will be placed in the same file hierarchy of the target board considering the base directory of the tar ball is the installation directory on the target board.

periask@ubuntu:~$ mkdir -vp packaging/Payload
mkdir: created directory `packaging
mkdir: created directory `packaging/Payload'
periask@ubuntu:~$ cd packaging/Payload
periask@ubuntu:~/packaging/Payload$ cp --preserve=mode -rl <installables> .
periask@ubuntu:~/packaging/Payload$ tar zcf ../Payload.tar.gz .
periask@ubuntu:~/packaging/Payload$ cd ..
periask@ubuntu:~/packaging$

Create Installer Script:
Copy the below content and create "installer" file in "packaging" directory.

#!/bin/bash

# Get the starting point of the tar ball
SKIP=`awk '/^__ARCHIVE__/ { print NR + 1; exit 0; }' $0`

# Do pre-installation steps here.

# Extracting the tar ball Which is appended to this file
tail -n "+$SKIP" $0 >/dev/null 2>&1
if [ $? -eq 0 ]; then
    tail -n +$SKIP $0 | gunzip -c | tar -C / -xvf -
else
    tail +$SKIP $0 | gunzip -c | tar -C / -xvf - 
fi

# Do post-installation steps here.

exit 0

__ARCHIVE__

Note: There should not be any space  after "__ARCHIVE__" and should be a new line after "__ARCHIVE__".

Packaging:
Concatenate the file "installer" and "Payload.tar.gz" and create the package file.

periask@ubuntu:~/packaging$ cat installer Payload.tar.gz > Package-Version.sh
periask@ubuntu:~/packaging$ chmod +x Package-Version.sh

Installer for your package "Package-Version.sh" is ready.

Source: Linux Journal