Monday, 1 June 2009

My IzPack Installation Script

Izpack is a java installer that is very useful, dynamic and easy. Its free and open source. In a project I worked on, I have used it to create a very dynamic and complex installer that handles a lot of configurations and installation files based on conditions. Th dynamic nature is due to the fact that i have to handle integration into more than 10 third party systems and clients have the option to choose which ever third party they have acquired. This installer has made it so easy thanks to FOSS I want to share the script.

This will also help me in case I have to make references at some point in the future.

Enjoy!

Main Installer:


<installation version="1.0">
  <info>
    <appname>[APP-NAME]</appname>
    <appversion>[APP-VERSION]</appversion>
    <appsubpath>[APP-PATH]</appsubpath>
    <javaversion>[JAVA-VERSION]</javaversion>
    <url>[APP-URL]</url>
    <requiresjdk>yes</requiresjdk>
    <authors>
      <author name="[APP-AUTHOR]" email="[APP-CONTACT]"/>
    </authors>
  </info>
  <guiprefs width="640" height="480" resizable="no">
    <modifier key="useLabelIcons" value="no"/>
    <modifier key="useHeadingPanel" value="yes"/>
    <modifier key="headingLineCount" value="1"/>
    <modifier key="headingFontSize" value="1.5"/>
    <modifier key="useFlags" value="no"/>
    <modifier key="langDisplayType" value="native"/>
    <modifier key="allYGap" value="8"/>
    <modifier key="allXGap" value="4"/>
    <modifier key="labelGap" value="2"/>
    <modifier key="layoutAnchor" value="NORTHWEST"/>
    <modifier key="headingPanelCounter" value="progressbar"/>
    <modifier key="headingPanelCounterPos" value="inNavigationPanel"/>
  </guiprefs>
  <locale>
    <langpack iso3="eng"/>
  </locale>
  <native name="ShellLink.dll" type="izpack">
    <os family="windows"/>
  </native>
  <native name="COIOSHelper.dll" stage="both" type="3rdparty">
    <os family="windows"/>
  </native>
  <listeners>
    <listener installer="RegistryInstallerListener" uninstaller="RegistryUninstallerListener">
      <os family="windows"/>
    </listener>
  </listeners>
  <conditions>
    <condition type="variable" id="condition.qas.v1">
      <name>connector.type</name>
      <value>QAS</value>
    </condition>
    <condition type="variable" id="condition.qas.v2">
      <name>connector.type</name>
      <value>QAS_V2</value>
    </condition>
    <condition type="variable" id="start.addresshub">
      <name>start_addresshub</name>
      <value>true</value>
    </condition>
  </conditions>
  <dynamicvariables>
    <variable name="TOMCAT_HOME" value="$INSTALL_PATH\$TOMCAT_VER"/>
    <variable name="JDK_HOME" value="${jdk.home}"/>
    <variable name="TEMP_HOME" value="$INSTALL_PATH\temp"/>
    <variable name="QAS_DATA_DIR" value="${qas.data.dir}"/>
    <variable name="QAS_HOME" value="${qas.install.dir}"/>
    <variable name="CONNECTOR_TYPE" value="${connector.type}"/>
    <variable name="JDKPathPanel.minVersion" value="1.5"/>
    <variable name="JDKPathPanel.maxVersion" value="1.5"/>
    <variable name="JDKPathPanel.skipIfValid" value="yes"/>
    <variable name="SERVER_NAME" value="${server.name}"/>
    <variable name="SERVER_START_PORT" value="${server.start.port}"/>
    <variable name="SERVER_SHUTDOWN_PORT" value="${server.shutdown.port}"/>

    <!-- QAS -->
    <variable name="CONNECTOR_NAME" value="QAS" condition="condition.qas.v1"/>
    <variable name="CONNECTOR_NAME" value="QAS Version 2" condition="condition.qas.v2"/>
    <variable name="QAS_INI_FILE" value="$TOMCAT_HOME\shared\lib\qapro.ini" condition="condition.qas.v1"/>
    <variable name="OS_MULTIPLIER" value="10" condition="condition.qas.v2"/>
    <variable name="OS_MULTIPLIER" value="10" condition="condition.qas.v1"/>
    <variable name="CONNECTOR_VERSION" value="2.0"/>

    <!-- SQL CONNECTOR -->
    <variable name="CONNECTOR_NAME" value="SQL" condition="condition.sql"/>
    <variable name="JDBC_URL" value="${jdbcURL}" condition="condition.sql"/>
    <variable name="JDBC_DRIVER" value="${jdbcDriver}" condition="condition.sql"/>
    <variable name="DATABASE_VIEWNAME" value="${viewName}" condition="condition.sql"/>
    <variable name="USERNAME" value="${dbUserName}" condition="condition.sql"/>
    <variable name="PASSWORD" value="${dbPassword}" condition="condition.sql"/>
    <variable name="FILENAME" value="${filename}" condition="condition.sql"/>
    <variable name="OS_MULTIPLIER" value="10" condition="condition.sql"/>
    
  </dynamicvariables>
  <variables>
    <variable name="TOMCAT_VER" value="[CATALINA-VERSION]"/>
  </variables>
  <resources>
    <res src="installer/ProcessPanel.Spec.xml" id="ProcessPanel.Spec.xml"/>
    <res src="installer/shortcutSpec.xml" id="shortcutSpec.xml"/>
    <res src="installer/UserInput.Spec.xml" id="userInputSpec.xml"/>
    <res id="Heading.image" src="src/web/lalpac-logo-cms.png"/>
  </resources>
  <panels>
    <panel classname="HelloPanel"/>
    <panel classname="TargetPanel"/>
    <panel classname="JDKPathPanel"/>
    <panel classname="UserInputPanel" id="Connector.Select"/>
    <panel classname="UserInputPanel" id="Connector.QAS.v1.Conf" condition="condition.qas.v1"/>
    <panel classname="UserInputPanel" id="Connector.QAS.v2.Conf" condition="condition.qas.v2"/>
    <panel classname="PacksPanel"/>
    <panel classname="InstallPanel"/>
    <panel classname="ProcessPanel"/>
    <panel classname="ShortcutPanel"/>
    <panel classname="SimpleFinishPanel"/>
  </panels>
  <packs>
    <pack name="Tomcat" required="yes">
      <description>Tomcat Installation</description>
      <file targetdir="$INSTALL_PATH" src="[CATALINA-SOURCE]" unpack="true"/>
      <file targetdir="$INSTALL_PATH/temp" src="DEPLOY/lalpac-tomcat-customised.zip" unpack="true"/>
      <file targetdir="$INSTALL_PATH/temp" src="DEPLOY/lalpac-tomcat-nt-service.zip" unpack="true"/>
      <file targetdir="$INSTALL_PATH/temp/bin" src="runtime/sleep.exe"/>
      <file targetdir="$INSTALL_PATH/temp/bin" src="runtime/lalpacenv.bat"/>
      <file targetdir="$TEMP_HOME" src="installer/tomcatconfig.bat"/>
      <file targetdir="$INSTALL_PATH/temp/bin" src="runtime/restartlpah.bat"/>
      <file targetdir="$INSTALL_PATH/temp/bin" src="runtime/stoplpah.bat"/>
      <file targetdir="$INSTALL_PATH/temp/bin" src="runtime/runlpah.bat"/>
      <parsable type="shell" parse="yes" targetfile="$INSTALL_PATH/temp/bin/lalpacenv.bat"/>
      <parsable type="shell" targetfile="$TEMP_HOME/tomcatconfig.bat" parse="yes"/>
      <parsable type="shell" targetfile="$INSTALL_PATH/temp/bin/restartlpah.bat" parse="yes"/>
      <parsable type="shell" parse="yes" targetfile="$INSTALL_PATH/temp/bin/stoplpah.bat"/>
      <parsable type="shell" parse="yes" targetfile="$INSTALL_PATH/temp/bin/runlpah.bat"/>
    </pack>
    <pack name="Core" required="yes">
      <description>Core Files</description>
      <file targetdir="$INSTALL_PATH/temp" src="DEPLOY/lalpac-tomcat.zip" unpack="true"/>
      <file targetdir="$INSTALL_PATH/temp" src="installer/ConnectorInstall.bat"/>
      <singlefile os="windows" target="$INSTALL_PATH/temp/addresshub.properties" src="src/conf/win.addresshub.properties"/>
      <singlefile target="$INSTALL_PATH/temp/web.xml" src="src/conf/dist.web_1.xml"/>
      <singlefile target="$INSTALL_PATH/temp/server.xml" src="src/conf/dist.server.win.xml"/>
      <parsable type="shell" targetfile="$INSTALL_PATH/temp/ConnectorInstall.bat" parse="yes"/>
      <parsable type="plain" parse="yes" targetfile="$INSTALL_PATH/temp/addresshub.properties"/>
      <parsable type="xml" targetfile="$INSTALL_PATH/temp/web.xml" parse="yes"/>
      <parsable type="xml" parse="yes" targetfile="$INSTALL_PATH/temp/server.xml"/>
    </pack>
    <pack name="QAS Connector V1" preselected="no" os="windows" required="no" id="pack.qas.v1" condition="condition.qas.v1">
      <description>Install files required for QAS Version 1 Connector</description>
      <file targetdir="$INSTALL_PATH/temp/qas" src="src/conf/qas/QABSF.INI"/>
      <file targetdir="$INSTALL_PATH/temp/qas" src="src/conf/qas/QABSFED.DLL"/>
      <file targetdir="$INSTALL_PATH/temp/qas" src="src/conf/qas/QABSFED.REV"/>
      <file targetdir="$INSTALL_PATH/temp/qas" src="src/conf/qas/qabsfed.isu"/>
      <singlefile target="$INSTALL_PATH/temp/qas/qapro.ini" src="src/conf/qas/qapro.v1.ini"/>
      <file targetdir="$INSTALL_PATH/temp/qas" src="src/conf/qas/qapuieb.dll"/>
      <file targetdir="$INSTALL_PATH/temp/qas" src="src/conf/qas/qapuieb.rev"/>
      <parsable type="plain" targetfile="$INSTALL_PATH/temp/qas/qapro.ini" parse="yes"/>
    </pack>
    <pack name="QAS Connector V2" preselected="no" os="windows" required="no" id="pack.qas.v2" condition="condition.qas.v2">
      <description>Install files required for QAS Version 2 Connector</description>
      <file targetdir="$INSTALL_PATH/temp/qas" src="src/conf/qas/QAWSERVE.INI"/>
      <parsable type="plain" targetfile="$INSTALL_PATH/temp/qas/QAWSERVE.INI" parse="yes"/>
    </pack>
  </packs>
</installation>

My Processing Spec as required

<processing>
  <logfiledir>$INSTALL_PATH</logfiledir>
  <job name="Installing Configuration Files">
    <executefile name="$INSTALL_PATH/temp/tomcatconfig.bat">
    </executefile>
  </job>
  <job name="Installing Connectors">
    <executefile name="$INSTALL_PATH/temp/ConnectorInstall.bat">
      <env>AH_TYPE=$INSTALL_TYPE</env>
    </executefile>
  </job>

  <!-- Always install as windows service. Don't give user the option -->
  <job name="Installing Windows Services" conditionid="windows.service">
    <os family="windows" />
    <executefile name="$TOMCAT_HOME\bin\installService.bat">
    </executefile>
  </job>  
</processing>


and ShortcutSpec

<shortcuts>
    <skipIfNotSupported/>
    <programGroup location="applications" defaultName="$APP_NAME $APP_VER"/>
    <shortcut startMenu="no" name="Start" encoding="UTF-8" initialState="noShow" applications="no" startup="no" workingDirectory="$TOMCAT_HOME\bin" target="$TOMCAT_HOME\bin\runlpah.bat" programGroup="yes" description="Start Addresshub" iconIndex="0" desktop="no"/>
    <shortcut startMenu="no" name="Stop" encoding="UTF-8" initialState="noShow" applications="no" startup="no" workingDirectory="$TOMCAT_HOME\bin" target="$TOMCAT_HOME\bin\stoplpah.bat" programGroup="yes" description="Stop Addresshub" iconIndex="1" desktop="no"/>
    <!-- <shortcut startMenu="no" name="StartService" encoding="UTF-8" initialState="noShow" applications="no" startup="no" workingDirectory="$TOMCAT_HOME\bin" target="$TOMCAT_HOME\bin\installService.bat" programGroup="yes" description="Start Addresshub Windows Service" iconIndex="2" desktop="no"/> -->
    <shortcut startMenu="no" name="Restart" encoding="UTF-8" initialState="noShow" applications="no" startup="no" workingDirectory="$TOMCAT_HOME\bin" target="$TOMCAT_HOME\bin\restartlpah.bat" programGroup="yes" description="Restart Addresshub" iconIndex="2" desktop="no"/>
    <shortcut startMenu="no" name="Uninstaller" encoding="UTF-8" initialState="noShow" applications="no" startup="no" workingDirectory="$TOMCAT_HOME\bin" target="$TOMCAT_HOME\bin\removeService.bat" programGroup="yes" description="Remove Addresshub" iconIndex="3" desktop="no"/>
    <!-- <shortcut startMenu="no" name="Uninstaller" encoding="UTF-8" applications="no" commandLine="" startup="no" target="$INSTALL_PATH\Uninstaller\uninstaller.jar" programGroup="yes" description="Addresshub uninstaller" iconIndex="5" desktop="no"/> -->
</shortcuts>


And UserInputSpec.xml
<userInput>
  <panel order="0" id="Connector.Select">
    <field type="title" txt="Select Configuration File" bold="true" size="1" />
    <field type="divider" align="top"/>

    <field type="space"/>

    <field type="dir" align="left" variable="jdk.home">
        <spec txt="Java Install Directory" size="25" set=""/>
        <validator class="com.izforge.izpack.util.NotEmptyValidator" txt="You must select your Java Installation Directory!"/>
    </field>
    <field type="staticText" align="left" txt="Directory where Java Runtime has been installed to."/>

    <field type="space"/>

    <field type="staticText" align="left" txt="Supplied Addresshub Configuration file:"/>
    <field type="file" align="left" variable="addresshub.file">
        <spec txt="" size="30" set=""/>
        <validator class="com.izforge.izpack.util.NotEmptyValidator" txt="Please select the Addresshub Configuration file received from LalPac!"/>
    </field>

    <field type="space"/>


    <field type="combo" align="left" variable="connector.type">
      <spec txt="Available Connectors">
        <choice txt="" value="None"/>
        <choice txt="QAS Connector for V6 LPG" value="QAS_LPG_V6"/>
        <choice txt="QAS Connector for V6 GBR/Pointer" value="QAS_GBR_V6"/>
        <!-- <choice txt="Accolaid Connector Version 1" value="Acolaid"/>
        <choice txt="Accolaid Soap Connector" value="Acolaid_Soap"/>
        <choice txt="GGP Connector Version 1" value="GGP"/>
        <choice txt="GGP Soap Connector " value="GGP_Soap"/>
        <choice txt="SQL Connector " value="SQL"/>
        <choice txt="GWS Connector " value="GWS"/>
        <choice txt="SX3 Connector " value="SX3"/>-->
        <choice txt="MVM Connector " value="MVM"/>
        <!-- <choice txt="CAPS Connector " value="CAPS"/> -->
      </spec>
      <validator class="com.izforge.izpack.util.NotEmptyValidator" txt="You must select the Connector to be installed!"/>
    </field>
    <field type="staticText" align="left" txt="The type of LalPac Connector to be installed"/>

    <field type="space"/>
    
    <field type="divider" align="bottom"/>
  </panel>

  <panel order="0" id="Connector.QAS.v1.Conf">
    <field type="title" txt="Please select where your QAS Data is installed to " bold="true" size="1" />
    <field type="divider" align="top"/>
    <field type="dir" align="left" variable="qas.data.dir">
      <spec txt="QAS Data Folder" size="25" set="C:\qaddress\pafdata"/>
    </field>
    <field type="divider" align="bottom"/>
  </panel>

  <panel order="1" id="Connector.QAS.v2.Conf">
    <field type="title" txt="Please specify the following QAS Installation folders. " bold="true" size="1" />
    <field type="divider" align="top"/>
    <field type="dir" align="left" variable="qas.data.dir">
      <spec txt="LPG Data Directory" size="25" set="C:\Program Files\QAS\Data\Gbr.001"/>
    </field>
    <field type="dir" align="left" variable="qas.install.dir">
      <spec txt="QAS Install Folder" size="25" set="C:\Program Files\QAS\QuickAddress Pro API"/>
    </field>
    <field type="divider" align="bottom"/>
  </panel>

  <panel order="3" id="Connector.mvm.Conf">

    <field type="title" txt="Please specify the configuration parameters for your installation " bold="true" size="1" />

    <field type="space"/>
    
    <field type="divider" align="top"/>

    <field type="space"/>

    <field type="text" align="left" variable="endpoint">
      <spec txt="Endpoint" size="40" set=""/>
      <validator class="com.izforge.izpack.util.NotEmptyValidator" txt="No EndPoint Specified"/>
    </field>
    <field type="staticText" align="left" txt="The URL of the Address Data Source. See LalPac Configuration file for details."/>

    <field type="space"/>

    <field type="text" align="left" variable="namespace">
      <spec txt="Target-namespace" size="25" set=""/>
      <validator class="com.izforge.izpack.util.NotEmptyValidator" txt="Target-namespace is Required"/>
    </field>
    <field type="staticText" align="left" txt="The Target Namespace. See LalPac Configuration file for details."/>

    <field type="space"/>

    <field type="text" align="left" variable="os-multiplier">
      <spec txt="Multiplier" size="25" set=""/>
      <validator class="com.izforge.izpack.util.NotEmptyValidator" txt="Data Multiplier is Required"/>
    </field>
    <field type="staticText" align="left" txt="The Data Multplier. See LalPac Configuration file for details."/>

    <field type="space"/>
    
    <field type="divider" align="bottom"/>

    <field type="space"/>
    
    <field type="title" txt="The  LalPac Configuration file should be included with the package you received from LalPac Ltd. " bold="true" size="1" />

    <field type="space"/>
  </panel>
  
</userInput>


11 comments:

Mark "Cypher" Kotlyar said...

Hey man,

Can you also post your other XMLs?
Namely the process spec.

cameo said...

No Probs..I will do that on monday. For some reason I didn't get any notification of your comment. Sorry about that

Sasha said...

Hi, the question is:
How to detect, when Tomcat was also installed, and its home?

cameo said...

You can know tomcat folder by using CATALINA_HOME environment variable and using ant to pull in that environment variable during installation

bastien said...

sorry to post so late after your topic but i have to find tomcat's webapp folder for my izpack installer.

The problem is that (to know how doing this) i installed tomcat on my test computer and there is no CATALINA_HOME environment variable.

Do you know how to precess to do this?

maRt said...

Great! Thanks for this script.
It actually helps a lot, by finding an easy way top setup an izpack installer!
BTW: if the user is specifying a directory, that might be later on used in an processed bat file afterwards (-> for system variables export) how can I do that?
thanks in advance
martin

cameo said...

@Martin,
I havent been on izpack for a while but if I remember, i used exactly that trick. you can store it as an internal variable. if you scan my script you may find it.

Kind regards

webrell said...

Can you also please post the ConnectorInstall.bat script?

Thanks!

mei ann said...

Hi, i'm trying to create an installer using izpack. I need my installer to set an environment variable after unzipping the files. My flow is this: unzip sample.zip to dir, set SAMPLE_HOME = dir\sample

Can you help me with this? Thanks so much!

Mei Ann

Ankur Gupta said...
This comment has been removed by the author.
Ankur Gupta said...

You have installed tomcat as a service. But how do you manage to stop and uninstall tomcat service when uninstalling the application?