Developers, Developers, Developers! Maksim Sorokin IT Blog

27Jul/10Off

IzPack: Thoughts on Using Environmental Variables in Silent Installation

IzPack is pretty powerful installation tool. However, silent installation (or the call it Automated Installers) lacks some flexibility. One of the things, which I lack, is a possibility to provide environmental variables in silent installation configuration files (auto-install.xml). Here I will provide some tricks which would help making your installer "eat" silent installation configuration files with environmental variables.

To start with, I will notice that in installpath you can always use IzPack way of interpreting environmental variables. For example:

<installpath>${ENV[APPDATA]}\3Dfacto\installers\glassfish</installpath>

Next, ordinary IzPack variables to be used in BAT files.
In your silent configuration files you would like to see something like:

<AutomatedInstallation langpack="eng">
   ...
  <com.izforge.izpack.panels.UserInputPanel id="UNKNOWN (com.izforge.izpack.panels.UserInputPanel)">
    <userInput>
      <entry key="myVar" value="%HOMEDRIVE%\location\file.txt"/>
   ...
</AutomatedInstallation>

Here are some ideas which may help you make it work.

Now, when you use ProcessPanel to launch your bat file, you pass a environmental variable inside a variable. Once you realize it, it is easy to make small trick to make everything work. For example, if in silent installation configuration file (in example above), you provide environmental variable to myVar variable. And then you pass it to the bat file with ProcessPanel in processPanelSpec.xml:

<processing>
  <job name="Install configuratorPortal">
    <executefile name="$INSTALL_PATH/script.bat">
      <env>myVar=$myVar</env>
  ...
</processing>

When ProcessPanel launches that bat file, your myVar will be substituted once. But you need to get it substituted two times! What you may do is to simply add shell call command in front of the expression, where myVar is used. In this case, variable will be substituted twice.
However, it will not work in some cases, for example:

call echo hi> %myVar%

or

call if exist %myVar% echo "hi"

What you can do in this case is to use a wrapper. For instance, if you want to call echo command to substitute variable twice:

call echo hi> %myVar%

Then create a helper parameterDumper.bat:

echo off

:: %1 -- what
:: %2 -- where

call echo %~1&gt;&gt; %~2

Include it into installation and simply call that instead:

call "%INSTALL_PATH%\parameterDumper.bat" "hi" "%myVar%"

Then two call commands will be executed and the parameter will be evaluated twice.

Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.