Wednesday, October 23, 2013

How to Create a Self-Extracting Installer in Bash

The basic idea of creating a self-extracting installer in Bash is really straightforward. We just need to append the binary package, e.g. an archive file in our installer script. Here's a simple example on how to do that.
  1. Create an installer script
  2. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    #!/bin/bash
     
    echo "Running self-extracting installer"
     
    ARCHIVE=`awk '/^__START_HERE__/ {print NR + 1; exit 0; }' $0`
    echo $ARCHIVE
    tail -n+$ARCHIVE $0 | tar xzv
     
    exit 0
     
    __START_HERE__
  3. Append an archive file into an installer script
  4. cat myproject.tar.gz >> installer
    
  5. Give an executable permission
  6. chmod +x installer
    
  7. Execute the installer script
  8. ./installer
    

No comments:

Post a Comment