Difference between revisions of "Variables"

From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search
(shortened code lines)
Line 9: Line 9:
  
 
=== In which order are they applied ===
 
=== In which order are they applied ===
 +
==== WPKG 1.2.x and below ====
 
The level below another will overwrite the previous definition.
 
The level below another will overwrite the previous definition.
  
Line 36: Line 37:
  
 
     <variable name="PKG_VER" value="1.2.0"/>
 
     <variable name="PKG_VER" value="1.2.0"/>
 +
</package>
 +
</source>
 +
 +
==== WPKG 1.3.x and above ====
 +
The level below another will overwrite the previous definition.
 +
 +
# operating system
 +
# WPKG client
 +
# host
 +
# profile
 +
# package
 +
 +
For example, if a variable is defined at the package and the profile level, the definition of the package will be used.
 +
<source lang="xml">
 +
<profile id="TestPC">
 +
    <variable name="PKG_VER" value="1.2.3"/>
 +
 +
    <package package-id="WpkgSettings"/>
 +
</profile>
 +
</source>
 +
 +
<source lang="xml">
 +
<package
 +
    id="WpkgSettings"
 +
    name="WPKG Client Settings"
 +
    revision="%PKG_VER%"
 +
    priority="999"
 +
    reboot="false"
 +
    execute="once">
 +
 +
    <variable name="PKG_VER" value="1.2.0"/>
 +
</package>
 +
</source>
 +
 +
To get the behavior of WPKG 1.2.x with WPKG 1.3.x, you need to check if the variable is set and only apply the current change if the variable is not set.
 +
 +
<source lang="xml">
 +
<profile id="TestPC">
 +
    <variable name="PKG_VER" value="1.2.3"/>
 +
 +
    <package package-id="WpkgSettings"/>
 +
</profile>
 +
</source>
 +
 +
<source lang="xml">
 +
<package
 +
    id="WpkgSettings"
 +
    name="WPKG Client Settings"
 +
    revision="%PKG_VER%"
 +
    priority="999"
 +
    reboot="false"
 +
    execute="once">
 +
 +
    <variable name="PKG_VER" value="1.2.0">
 +
        <condition>
 +
            <check type="host" condition="environment" value="PKG_VER=^$"
 +
        </condition>
 +
    </variable>
 
</package>
 
</package>
 
</source>
 
</source>

Revision as of 19:04, 20 January 2012

Variables

Where can they be set

  • At operating system level
  • Through WPKG client
  • Through the host definition
  • Through the profile definition
  • Through the package definition

In which order are they applied

WPKG 1.2.x and below

The level below another will overwrite the previous definition.

  1. operating system
  2. WPKG client
  3. package
  4. profile
  5. host

For example, if a variable is defined at the package and the profile level, the definition of the profile will be used.

<profile id="TestPC">
    <variable name="PKG_VER" value="1.2.3"/>

    <package package-id="WpkgSettings"/>
</profile>
<package
    id="WpkgSettings"
    name="WPKG Client Settings"
    revision="%PKG_VER%"
    priority="999"
    reboot="false"
    execute="once">

    <variable name="PKG_VER" value="1.2.0"/>
</package>

WPKG 1.3.x and above

The level below another will overwrite the previous definition.

  1. operating system
  2. WPKG client
  3. host
  4. profile
  5. package

For example, if a variable is defined at the package and the profile level, the definition of the package will be used.

<profile id="TestPC">
    <variable name="PKG_VER" value="1.2.3"/>

    <package package-id="WpkgSettings"/>
</profile>
<package
    id="WpkgSettings"
    name="WPKG Client Settings"
    revision="%PKG_VER%"
    priority="999"
    reboot="false"
    execute="once">

    <variable name="PKG_VER" value="1.2.0"/>
</package>

To get the behavior of WPKG 1.2.x with WPKG 1.3.x, you need to check if the variable is set and only apply the current change if the variable is not set.

<profile id="TestPC">
    <variable name="PKG_VER" value="1.2.3"/>

    <package package-id="WpkgSettings"/>
</profile>
<package
    id="WpkgSettings"
    name="WPKG Client Settings"
    revision="%PKG_VER%"
    priority="999"
    reboot="false"
    execute="once">

    <variable name="PKG_VER" value="1.2.0">
        <condition>
            <check type="host" condition="environment" value="PKG_VER=^$"
        </condition>
    </variable>
</package>

Why use variables

  • To easily change multiple occurrences of a value in the install, upgrade, downgrade and remove commands
  • To use one version variable for package revision, checks and installer executable name
  • To apply different versions of a package based on host groups and profiles


Replacing multiple occurrences

<package id="WpkgClient"
        name="WPKG Client"
        revision="%PKG_VER%"
        reboot="false"
        priority="999">

    <variable name="PKG_VER"     value="1.3.14" />
    <variable name="PKG_EXE_VER" value="1.0.0.22" />
    <variable name="PKG_SOURCE"  value="%SOFTWARE%\WPKG\WPKG Client\WPKG Client %PKG_VER%-%PROCESSOR_ARCHITECTURE%.msi" />

    <check type="uninstall" condition="versiongreaterorequal" path="WPKG"  value="%PKG_VER%"/>
    <check type="file" condition="versiongreaterorequal" path="%ProgramFiles%\wpkg\wpkginst.exe" value="%PKG_EXE_VER%" />

    <!-- replace x32 with x86 and x64 with AMD64 in the installer file name -->
    <install cmd='msiexec /norestart /passive /log "%TMP%\WpkgClient.log" /i "%PKG_SOURCE%" ALLUSERS=1 SETTINGSFILE="%WPKG_ROOT%\settings.xml"' >
        <exit code="1641" />
        <exit code="3010" reboot="false"/>
    </install>

    <upgrade cmd='msiexec /norestart /passive /log "%TMP%\WpkgClient.log" /i "%PKG_SOURCE%" ALLUSERS=1 SETTINGSFILE="%WPKG_ROOT%\settings.xml"' >
        <exit code="1641" />
        <exit code="3010" reboot="false"/>
    </upgrade>

    <remove cmd='MsiExec.exe /norestart /passive /log "%TMP%\WpkgClient.log" /x "%PKG_SOURCE%"' />
</package>

Applying different versions

Below find the host definition for two computers, where the host definition for TestPC is overwriting some variables.

<host name="TestPC" profile-id="DesktopPC" >
    <variable name="PKG_VER" value="1.3.14" />
</host>

<host name="OfficePC" profile-id="DesktopPC" />

Both computers use the same profile.

<profile id="DesktopPC">
    <package package-id="WpkgClient"/>
</profile>

Both computers use the same package.

<package id="WpkgClient"
        name="WPKG Client"
        revision="%PKG_VER%"
        reboot="false"
        priority="999">

    <variable name="PKG_VER" value="1.3.9" />
    <variable name="PKG_SOURCE"  value="%SOFTWARE%\WPKG\WPKG Client\WPKG Client %PKG_VER%-%PROCESSOR_ARCHITECTURE%.msi" />

    <check type="uninstall" condition="versiongreaterorequal" path="WPKG"  value="%PKG_VER%"/>

    <!-- replace x32 with x86 and x64 with AMD64 in the installer file name -->
    <install cmd='msiexec /norestart /passive /log "%TMP%\WpkgClient.log" /i "%PKG_SOURCE%" ALLUSERS=1 SETTINGSFILE="%WPKG_ROOT%\settings.xml"' >
        <exit code="1641" />
        <exit code="3010" reboot="false"/>
    </install>

    <upgrade cmd='msiexec /norestart /passive /log "%TMP%\WpkgClient.log" /i "%PKG_SOURCE%" ALLUSERS=1 SETTINGSFILE="%WPKG_ROOT%\settings.xml"' >
        <exit code="1641" />
        <exit code="3010" reboot="false"/>
    </upgrade>

    <remove cmd='MsiExec.exe /norestart /passive /log "%TMP%\WpkgClient.log" /x "%PKG_SOURCE%"' />
</package>

In the end the computer OfficePC gets revision 1.3.9 of the package installed, where TestPC gets revision 1.3.14 installed.