Tuesday, March 20, 2012

True Packager 2 Release 1.3.3 Features - Part 2

Passing Environment Variables

When you are running as the owner of a namespace when you attempt to install or remove a package the software will run the relevant programs natively; and hence have access to the current environment.

However if you are running as a user that is authorised (but does not own) the namespace in question, all activity is spawned via the daemon process. This has the following impact:

  • The actual process doing all the work is initiated by the daemon; the process in the terminal is simply relaying the information it receives in this instance.
  • Since the process installing the package is doing so via the daemon it is no access to the environment variables that the caller has available currently.
However from 1.3.3 onwards this problem can be overcome by making use of an additional optional section in the package configuration file, namely:

  <env>
    ENV_VAR1
    ENV_VAR2 
  </env>

The "env" element allows you to list a series of environment variables that the caller and the spawned install/remove session will pass between them. When such is part of the package those variables will be communicated from the calling shell and made available to the four following scripts:

preinstall
postinstall
preremove
postremove

Getting User Responses
This is still in the early stages of development but the idea is that the package should be able to configure a series of queries which the user can respond to and these responses are then made available to the two installation scripts; "preinstall" and "postinstall".

Again this is achieved via a new section in the package configuration file, namely the optional "response_info" element. This will have a separate "q" element for each query that the user is asked. Consider the following example:

  <response_info>
    <q text="Please enter your age" default="5" 
       type="integer" range="1 99" label="get_age"/>
    <q text="Please enter your email address" default="%USERNAME%@%HOSTNAME%" 
       type="text" label="get_email" pattern="^\S+@\S+" 
       hint="Please enter valid email address format"/>
  </response_info>

In this case two questions will be asked. The utility will attempt to perform validation and range checking for numbers, and for text queries it can optionally include a "pattern" attribute to ensure the response entered matches the pattern in question.

The "default" attribute is mandatory - this will allow installations to take default values if the user responses are not available. This is designed for headless installs; even though that is not yet available.

In such cases the preinstall and postinstall scripts have these values entered as part of the environment - these are in variables TP2_RESPONSE_label. Hence in the above example:

TP2_RESPONSE_get_age
TP2_RESPONSE_get_email

For more information see the available documentation on the google code downloads page: true packager 2 downloads.

No comments:

Post a Comment