<?xml version="1.0" ?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.3//EN"
"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
<!ENTITY % elements SYSTEM "entities/elements.inc">
%elements;
<!ENTITY % authors SYSTEM "entities/authors.inc">
%authors;
<!ENTITY complete_package SYSTEM "generic/complete_package_example.xml">
]>
<!-- $Id: package_maker_guide.xml,v 1.18 2005/04/25 18:41:04 larkin Exp $ -->
<book>
<bookinfo>
  <title>ReST Packager's Guide</title>
  <subtitle>An introduction to creating ReST packages.</subtitle>
  <authorgroup>
    &jefflarkin.author;
    &ericmeek.author;
  </authorgroup>
  <abstract>
    <para>This document provides information for those interested in creating
    a ReST Installer package for a piece of software.  It provides information
    detailing the process of package creation.  It is assumed that the reader
    has at least a basic knowledge of the ReST project.</para>
  </abstract>
  <revhistory>
  <!--<revision>
    <revnumber>$Revision: 1.18 $</revnumber>
    <date>$Date: 2005/04/25 18:41:04 $</date>
    <revremark>Current CVS Version.</revremark>
  </revision>-->
  <revision>
    <revnumber>1.0</revnumber>
    <date>3/11/2005</date>
    <revremark>Initial Public Release</revremark>
  </revision>
  </revhistory>
</bookinfo>
<chapter>
<title>ReST Package Basics</title>
<para>Although used primarily by the ReST Installer, ReST packages are the means
by which the ReST Application Suite is customized for individual pieces of 
software.  The ReST package contains the software and metadata needed by the 
Installer to install software on remote machines.  The package metadata is used
by the Installer and Explorer to maintain the state of installed software and in 
future versions of ReST it will contain information needed to customize the 
Monitor to work with the installed packages. In order to produce a well-written 
package it is important to understand what is contained in the package and what 
conventions are expected by the ReST Suite.</para>
<section>
<title>The Package Structure</title>
<para>A ReST package is essentially a ZIP/JAR file containing two special files, 
a package XML file and a checksum file.  The package XML file, name package.xml 
inside the package, contains both basic metadata about the package and 
instructions on how to install the package from source or pre-compiled binaries.  
The checksum file, at this time must be created by the ReSTPackager program
contains checksums of each file within the package and is must pass before the 
Installer will run the package.  Details about the package sources are not
necessary, since they could be any file that is pertenant to the software being
installed.  Details about writing the package XML, including documentation of
each XML tag, and creating the package file appear later in this document.
</para>
</section>
<section>
<title>The Package XML</title>
<para>The package XML is what makes a ReST package special.  It includes 
metadata pertaining to the software package, instructions on installing the
contained software, and a list of <emphasis>actions</emphasis> that can be
performed once the software has been installed.  The XML file can be
thought of as an enhanced shell script, since it contains a list of commands
that are run sequentially to install the package.  It is more than a simple 
shell script, however, in that packagers are able to define options that
can be customized by the end user from the ReST Installer.</para>
<para>Commands in the package XML are broken into six 
<emphasis>steps</emphasis>, which simply provide a logical grouping of the 
commands that are run.  The six steps, in order, are 
<emphasis>Preparation</emphasis>, <emphasis>Configuration</emphasis>, 
<emphasis>Compilation</emphasis>, <emphasis>Installation</emphasis>,
<emphasis>Complettion</emphasis>, and <emphasis>Uninstallation</emphasis>,
with the last actually being optional.  Commands that need to be run first, before 
anything else can happen, such as extracting archives or creating directories 
should be placed in the perparation step.  Package sources will be sent to the 
remote machine and package directories will be created prior to this step.
Anything pertaining to configuring the software, such as running a 
<command>configure</command> script should be placed in the configuration step.  
Configuration files included in the package will be sent to the remote machine 
between these first two steps.  Commands related to compiling and installing the 
package should be placed in the next two steps respectively.  During the 
completion step the packager should clean up the build area however possible, 
such as deleting unneeded sources that remain.  Lastly, if a packager would like 
to provide a means for automatically uninstalling their software, commands 
pertaining to this should be placed in the uninstallation step.  Each step is 
essentially equal, but provides a logical way of organizing the package.  
Packagers are encouraged to group their commands using these logical step.  
Every step except the uninstallation step must be in the package XML, but may be 
empty if not needed.</para>
</section>
</chapter>
<chapter>
<title>Writing the package XML</title>
<para>Future versions of the ReST suite may contain a graphical application
for creating package XML files, but at the current time the file must be
written by hand.  For this reason it is crucial for the packager to gain an 
understanding of the package XML file to create a working package.  Package XML 
files can be written in any text editor so long as they obey the rules defined 
for ReST XML.  A definition of each XML tag is given in the reference sections 
at the end of this document.</para>
<section>
<title>Planning</title>
<para>The planning step is the most important part in successfully creating a 
working package.  Before writing the XML create a step-by-step list of how the 
software is installed.  If possible, walk through the installation in a clean 
/bin/bash environment, since this will more realistically reflect the environment 
in which ReST will install the software.  Once this list has been written, place 
a mark next to each command that would not need to be run on every machine in an 
homogeneous environment with a shared filesystem.  Now note command options that 
should be offered for each command, for example 
<command>./configure --with-foo</command>.  Try installing the software by
walking through this list one command at a time; if it works without problem
then fewer problems are likely to occur when the package is written.</para>
</section>
<section>
<title>Writing the XML</title>
<para>The sections below will provide an overview of how to write a package XML
file.  For more detailed information about the XML tags, including advanced
attributes, please see the reference section at the end of this document.</para>
<section>
<title>The Header</title>
<para>The package header contains metadata about the package that will be shared
among all of the ReST applications.  This metadata includes the name of the 
software, the author and version of the software, and information about the
packager.  Below is a basic package header.</para>
<example>
<title>Package Header</title>
<screen>
&lt;header&gt;
  &lt;title&gt;Example Package&lt;/title&gt;
  &lt;base&gt;example&lt;/base&gt;
  &lt;version&gt;1.0&lt;/version&gt;
  &lt;description&gt;This package is an example ReST package.&lt;/description&gt;
  &lt;uri>http://icl.cs.utk.edu/rest/&lt;/uri>
  &lt;licenseuri forceaccept="true"&gt;http://example.com/license.txt&lt;/licenseuri&gt;
  &lt;packager&gt;
    &lt;name&gt;Joe Devloper&lt;/name&gt;
    &lt;uri&gt;mailto:developer@example.com&lt;/uri&gt;
  &lt;/packager&gt;
&lt;/header&gt;
</screen>
</example>
<para>There are several important tags in the above example. The 
<sgmltag class="element">title</sgmltag> sets the package title that will 
appear in the Installer.  If the title is longer than 25 characters, a second,
shorter title may be set with the <sgmltag class="attribute">role</sgmltag>
attribute set to short.  If no short title is provided and the title is 
longer than 25 characters, then in space-constrained parts of the application
the long title will be truncated at 25 characters.  The 
<sgmltag class="element">base</sgmltag> element gives a way of grouping 
packages that should be installed in a similar area.  For example, packages
for the LAPACK and BLAS libraries have been written with a base of 
<emphasis>lib</emphasis> so that they, and other libraries, will be easy to 
find and use.  The <sgmltag class="element">base</sgmltag> should always be
set to a value that will be valid for the filesystem on all target 
machines.</para>
<para>The contents of the 
<sgmltag class="element">version</sgmltag> tag should be the version on the software in the 
package and not the version of the package itself.  The version of the package 
can be given as an attribute of the <sgmltag class="element">package</sgmltag> root element if 
desired.  Additional tags exist for the package header, including options for 
editing configuration files, added files to the package, and defining actions 
that can be performed once the package has been installed. All of these tags are 
defined with examples in a <link linkend="el_ref">reference section</link> at 
the end of this document.</para>
</section>
<section>
<title>The 6 Steps</title>
<para>As explained earlier, all commands for installing and uninstalling a 
package are organized into six logical steps: <code>preparation</code>,
<code>configuration</code>, <code>compilation</code>, 
<code>installation</code>, <code>completion</code>, and
<code>uninstallation</code>.  The <code>uninstallation</code> step is 
optional, but recommended.  These steps are essentially equal, except that
configuration files are sent to the remote machine between the 
<code>preparation</code> and <code>configuration</code> steps.  It is highly
recommended that packagers take advantage of the six steps for logically
grouping the package commands.  Future version of the the ReST suite may contain 
optimizations or changes in the handeling of these steps and forward 
compatibility is best ensured by using these steps.  Below is an example of the 
six steps appearing in a package.</para>
<example>
<title>The 6 Steps</title>
<screen>
&lt;preparation&gt;
  &lt;command value="tar -xf example.tar"&gt;
  &lt;command value="cd example/"&gt;
&lt;/preparation&gt;
&lt;configuration&gt;
  &lt;command value="./configure --prefix=$PWD"&gt;
&lt;/configuration&gt;
&lt;compilation&gt;
  &lt;command value="make all"&gt;
&lt;/compilation&gt;
&lt;installation&gt;
  &lt;command value="make install"&gt;
&lt;/installation&gt;
&lt;completion&gt;
  &lt;command value="make clean"&gt;
  &lt;command value="cd ..; /bin/rm -f example.tar"&gt;
&lt;/completion&gt;
&lt;uninstallation&gt;
  &lt;command value="cd example"&gt;
  &lt;command value="make uninstall"&gt;
  &lt;command value="cd ..; /bin/rm -rf example/"&gt;
&lt;/uninstallation&gt;
</screen>
</example>
</section>
<section>
<title>Command Options</title>
<para>Some commands may need to be configured by the user before they are run
on the remote machine.  For that reason the ReST XML allows 
<sgmltag class="element">command</sgmltag> tags to contain <sgmltag class="element">option</sgmltag> tags.  The
<sgmltag class="element">option</sgmltag> tags define command-line arguments for a given command
and can be configured by end users.  A good example of a command that will 
likely contain options is the <code>./configure</code> script, which is included 
in many source distributions.  It is common for this command to have many 
different command line options for properly configuring the build process.
Below is an example of the <code>./configure</code> command with options.</para>
<example>
<title>Command Options</title>
<screen>
&lt;command value="./configure" grouped="true"&gt;
  &lt;option name="foo" type="text" default="/usr/local/lib/libfoo.a" 
          truevalue="--with-libfoo="/&gt;
  &lt;option name="bar" type="boolean" default="false" 
          truevalue="--with-libbar" falsevalue="--without-libbar"/&gt;
  &lt;option name="ouputlevel" type="choice" choices="debug,view,none" default="none" 
          truevalue="--with-outputlevel "/&gt;
&lt;/command&gt;
</screen>
</example>
<para>The above example defines three possible options for the 
<code>./configure</code> command.  All of the options have four common 
attributes: name, type, default, and truevalue.  The name attribute is exactly
what would be expected, the name that the user will see when configuring this
option.  The type attribute may be either <code>text</code>, 
<code>boolean</code>, or <code>choice</code>.  The default attribute defines
what the value should be by default, which is required for installation in 
simple mode.  Finally the truevalue attribute defines what is appended to the
command if the option is enabled or if a option of type boolean is selected.  
For example, if option <code>foo</code> is enabled and the default value is left 
untouched the resulting string <code>--with-libfoo=/usr/local/lib/libfoo.a</code> 
will be appended to the command.  Packagers are encouraged to expose all 
possible command-line options to the users through ReST as the packager is more 
knowledgeable about the software included than the user.  Additional information 
about the <sgmltag class="element">option</sgmltag> tag can be found in the reference section at 
the end of this document.</para>
</section>
<section>
<title>Actions</title>
<para>ReST actions are commands that exist on systems after a software package has
been installed.  For a piece of server software, for example, this could include
starting, stopping, and restarting the server.  An <sgmltag class="element">action</sgmltag>
is simply a wrapper around one or more <sgmltag class="element">command</sgmltag> tags, much 
like each of the six steps described above, except that the  
<sgmltag class="element">action</sgmltag> tag requires a name for the action.  Actions can be 
run by the ReST Installer immediately after installation is complete or by the 
ReST Exploror at any time after package installation.  Below is an example of 
package actions.</para>
<example>
<title>Package Actions</title>
<screen>
&lt;actions>
  &lt;action name="Start Server" tooltip="Start a server."&gt;
    &lt;command value="/bin/bash ./start_server.sh" statusmsg="Starting Server"
             errormsg="Failed to start server."/&gt;
  &lt;/action&gt;
  &lt;action name="Kill Server" tooltip="Kill a server."&gt;
    &lt;command value="/bin/bash ./kill_server.sh" statusmsg="Killing Server"
             errormsg="Failed to kill server."/&gt;
  &lt;/action&gt;
  &lt;action name="Restart Server" tooltip="Restart a server.">
    &lt;command value="/bin/bash ./kill_server.sh" statusmsg="Killing Server"
             errormsg="Failed to kill server."/&gt;
    &lt;command value="/bin/bash ./start_server.sh" statusmsg="Starting Server"
             errormsg="Failed to start server."/&gt;
  &lt;/action&gt;
&lt;/actions&gt;
</screen>
</example>
</section>
<section>
<title>Configuration Files</title>
<para>Many software packages have configuration files that must be edited before
the software can be used.  To the developer of a software package writing the 
configuration files may be trivial, but this is often not the case for the end 
user.  For this reason, the ReST Installer may be used to edit configuration
files for the software package.  The package must include a stub configuration
file with a series of tokens to substitute.  Each token appears with a % 
character on either side of the one-word token, such as %token%.  With a 
stub file created the packager must define the substitutions for this file in
the package XML.  Below is an example stub file and matching package XML.</para>
<example>
<title>Stub Configuration File</title>
<screen>
FOO=%sub1%
</screen>
</example>
<example>
<title>Configuration File XML</title>
<screen>
&lt;configfile packagefile="example.cfg" 
            remotefile="example/example.cfg"
            description="Example Configuration File"&gt;
  &lt;sub name="sub1" description="First Substitution"
       default="My First Substitution" type="string"/&gt;
&lt;/configfile&gt;
</screen>
</example>
<para>In the above example just one substitution is made, but ReST will handle
as many substitutions as are needed.  Three types of substitions exist, 
<code>string</code> (no more than one line of text), <code>text</code>
(multiple lines of text), and <code>choice</code> (a defined set of choices, much
like available for command options).  The <sgmltag class="element">configfile</sgmltag> tag
has three attributes: packagefile (the location of the stub file in 
the package), remotefile (where the resulting configuration file should be
placed on the remote machine), and description (a simple description for the 
user).  Addtional information about the <sgmltag class="element">configfile</sgmltag> and
<sgmltag class="element">sub</sgmltag> tags, including additional attributes to each, can be
found in the reference section at the end of this document.</para>
</section>
</section>
</chapter>
<chapter>
<title>Creating and using the package file</title>
<para>Once the package XML has been written, stub configuration files have been 
created and source files have been gathered, it is time to combine all of the
files into a ReST package.  Part of the ReST suite is the ReST Packager 
utility.  This utility combines all of the necessary files into one package
for easy distribution.  Below is an example of how the ReST Packager
is used.</para>
<example>
<title>Running the ReST Packager.</title>
<screen>
&gt; java -jar ReSTPackager.jar -X examplepackage.xml -f example.rsp file1 file2 stub.cfg
</screen>
</example>
<para>In the above example, the user has run the ReST Packager, which is 
included in the ReST suite to create a package named example.rsp.  The 
<code>-X</code> argument tells the ReST Packager to use 
<code>examplepackage.xml</code> as the package XML file for this package.
The <code>-f</code> argument tells the packager the name of the file
to create.  The remaining arguments tell the Packager which files to include.
Every file that is declared in the package.xml must be included in the Packager
arguments.  The resulting file can be distributed by whatever means desired
and used with the ReST Installer.</para>
<para>Once the package file is created, it simply needs to be installed from the
ReST Installer.  To install the package, run the ReST Installer with the name of 
the package as an argument.  The package can be local or placed on a web server, 
although larger packages will run more quickly if they are local.  Here is an
example of our package being used by the ReST Installer.</para>
<example>
<title>Installing a Package</title>
<screen>
&gt; java -jar ReSTInstaller.jar example.rsp
</screen>
</example>
</chapter>
<!--<chapter>
<title>Distributing your package.</title>
<para><emphasis>INCOMPLETE</emphasis></para>
<para>The simplest means of distributing a package is making use of the 
Java Web Start(tm) technology.  Using the yet to be determined address the 
packager can define the url of the package and generate a package.jnlp.  The 
package.jnlp may then be placed on a web server allowing users to just click on a 
link off a web page to install the package. Future version of the installer will
verify the validity of a package against it's own signatures so the software 
destributer should sign both the package and the Installer</para>
</chapter>-->
<chapter>
<title>Conclusions</title>
<para>The ReST package specification was designed to give packagers a flexible
system for creating an application installer for their software.  This document
should have given you the basic knowledge needed to build a package for your
software.  More detailed information about the ReST package XML, including a 
full example can be found in the reference pages of this document.  For 
questions about ReST and to provide feedback or suggestions, please feel
encouraged to e-mail the authors of this document.</para>
</chapter>
&elements.ref;
<reference>
<title>Complete Package XML</title>
<refentry>
<refnamediv>
<refname>Complete Package XML Example</refname>
<refpurpose>Show the complete XML of a package.</refpurpose>
</refnamediv>
<refsection>
<title>Complete Package XML</title>
&complete_package;
</refsection>
</refentry>
</reference>
</book>
