Simplefy installation with bin file creation on Linux

While working at different company’s i needed to install the same software over and over … To make my life easier i use a Python script which creates a runable binary file. Like for example weblogic1035.bin. Run it an it will install without promt you anything…

  1. What do you need in the package directory?

install.sh which is the execution script for the specific installation, in this case, Oracle Weblogic Server 10.3.1.5

#!/bin/sh
BEA_HOME=/opt/oracle
JAVA_HOME=/opt/jdk1.7.0_01
JAVA=$JAVA_HOME/bin/java

$JAVA -jar wls1035_generic.jar -mode=silent -silent_xml=silent.xml -log=$BEA_HOME/wls_11g_install.log

–  All files needed to perform the installation, in this case a silent.xml


<?xml version="1.0" encoding="UTF-8"?>
<bea-installer>
  <input-fields>
    <data-value name="BEAHOME" value="/opt/oracle/11g" />
    <data-value name="WLS_INSTALL_DIR" value="/opt/oracle/11g/wlserver_10.3" />
    <data-value name="COMPONENT_PATHS" value="WebLogic Server"/>
  </input-fields>
</bea-installer>

– The product installer, in this case wls1035_generic.jar

– Once you put every install component in place, you can can invoke the makeinstaller script which is described below:


#!/usr/bin/python
import os
import os.path
import string
import sys

EXTRACT = """#!/bin/bash
EXTRACT_ONLY=0
if [ "$1" = "--extract" ];then
  EXTRACT_ONLY=1
fi
export TMPDIR="%s"
mkdir -p $TMPDIR
ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ {print NR + 1; exit 0;}' $0`

tail -n+$ARCHIVE $0 | tar xz -C $TMPDIR

if [ $EXTRACT_ONLY -eq 1 ]; then
  exit 0
fi

CHDIR=`pwd`
cd $TMPDIR
./install.sh
cd $CHDIR
rm -rf $TMPDIR
exit 0

__ARCHIVE_BELOW__
"""
def usage():
  print "Usage: makeinstaller.py <package_dir> [destination_dir]"
  sys.exit(-1)

def pack(path, dest):
  dir = string.split(path, "/")[-1]
  extract = EXTRACT % dir
  cdir = os.getcwd()
  os.chdir(path)
  os.system("tar chzf ../payload.tgz *")
  os.chdir("..")
  installer = dest + "/" + dir + ".bin"
  open(installer, "w").write(extract)
  os.system("cat payload.tgz >>" + installer)
  os.system("chmod a+x " + installer)
  os.system("rm -f payload.tgz")
  os.chdir(cdir)
  return

if __name__ == "__main__":
  if len(sys.argv) < 2 or len(sys.argv) > 3:
    usage()
  path = os.path.abspath(sys.argv[1])
  if len(sys.argv) == 3:
    dest = os.path.abspath(".")
  pack(path, dest)

– Put the script one level higher as the package dir and the destination dir.

– Run the script as follow:

makeinstaller.py <package_dir> [destination_dir]”

– Now you can run the created bin file, good luck !

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: