get oldInstallDir/oldVersion on Linux

Answered

Comments

2 comments

  • Avatar
    wojciechka

    You can store the values in a pre-defined file - such as /etc/${project.vendor}-${project.shortName}.ini.

    And then after installation store it by doing:

    <postInstallationActionList>
      <iniFileSet>
        <file>/etc/${project.vendor}-${project.shortName}.ini</file>
        <key>installdir</key>
        <section>details</section>
        <value>${installdir}</value>
      </iniFileSet>
      <iniFileSet>
        <file>/etc/${project.vendor}-${project.shortName}.ini</file>
        <key>version</key>
        <section>details</section>
        <value>${project.version}</value>
      </iniFileSet>
    </postInstallationActionList>
    

    And reading it can be done by doing:

    <preInstallationActionList>
      <iniFileGet>
        <file>/etc/${project.vendor}-${project.shortName}.ini</file>
        <key>installdir</key>
        <section>details</section>
        <variable>oldInstallDir</variable>
      </iniFileGet>
      <iniFileGet>
        <file>/etc/${project.vendor}-${project.shortName}.ini</file>
        <key>version</key>
        <section>details</section>
        <variable>oldVersion</variable>
      </iniFileGet>
    </preInstallationActionList>
    

    Finally deleting the file can be done as:

    <postUninstallationActionList>
      <deleteFile>
        <path>/etc/${project.vendor}-${project.shortName}.ini</path>
      </deleteFile>
    </postUninstallationActionList>
    

    This approach can be used on all Unix systems including Mac OS X.

  • Avatar
    Martin Pecuch

    Thanks! My final solution is:

       <preInstallationActionList>
            <foreach>
                <values>version oldVersion installdir oldInstalldir</values>
                <variables>name variable</variables>
                <actionList>
                    <setInstallerVariable name="${variable}" value=""/>
                    <iniFileGet>
                        <file>/etc/${project.vendor}-${project.shortName}.ini</file>
                        <key>${name}</key>
                        <section>details</section>
                        <variable>${variable}</variable>
                        <ruleList>
                            <fileTest condition="exists" path="/etc/${project.vendor}-${project.shortName}.ini"/>
                        </ruleList>
                    </iniFileGet>
                </actionList>
                <ruleList>
                    <platformTest negate="1" type="windows"/>
                </ruleList>
            </foreach>
        </preInstallationActionList>
    
    <postInstallationActionList>
        <foreach>
            <values>version ${project.version} installdir ${installdir}</values>
            <variables>name variable</variables>
            <actionList>
                <iniFileSet>
                    <file>/etc/${project.vendor}-${project.shortName}.ini</file>
                    <key>${name}</key>
                    <section>details</section>
                    <value>${variable}</value>
                </iniFileSet>
            </actionList>
            <ruleList>
                <platformTest negate="1" type="windows"/>
            </ruleList>
        </foreach>
        <addFilesToUninstaller files="/etc/${project.vendor}-${project.shortName}.ini"/>
    </postInstallationActionList>
    

Please sign in to leave a comment.