18 October 2010

Package Builds in Solaris

This document details how to create a package on Solaris.  Only the
creation of a simple package is detailed in this doc.  For more elaborate
packages, see the relevant man pages.

The following assumptions are being made regarding the package build
described herein:

        - the program, etc, has already been installed on the host
          the package is to be built upon

        - for simplicity, the program, yourProg, and its relevant files
          are installed under /usr/local

        - you have root on the host (hostA) that the package is going
          to be created on

        - hostA's root shell prompt is:

                hostA [0]

Create a file, proto.input, in /tmp that contains the relative pathnames
of the files and directories relevant to yourProg.  Below is an example
of the potential contents of proto.input (no leading space necessary on
each line):

        bin
        bin/yourProg
        etc
        etc/yourProg.conf
        man
        man/man1
        man/man1/yourProg.1
        share
        share/doc
        share/doc/yourProg-4.17
        share/doc/yourProg-4.17/AUTHORS
        share/doc/yourProg-4.17/COPYING
        share/doc/yourProg-4.17/ChangeLog
        share/doc/yourProg-4.17/README
        share/doc/yourProg-4.17/yourProg.conf
        share/doc/yourProg-4.17/yourProg.detail

Now, cd into /usr/local, if you aren't already there, and run pkgproto
to create a prototype file:

        hostA [0] cd /usr/local
        hostA [0] cat /tmp/proto.input | /usr/bin/pkgproto > prototype

Open the prototype file in your favorite text editor (vi) and add the
following at the first line:

        i pkginfo=./pkginfo

Also, while editing prototype, ensure that permissions and user:group
ownerships are appropriate.  An example of the resulting file should
look similar to the following:

        i pkginfo=./pkginfo
        d none bin 0755 root other
        f none bin/yourProg 4755 root root
        d none etc 0755 bin bin
        f none etc/yourProg.conf 0600 root root
        d none man 0755 root other
        d none man/man1 0755 root other
        f none man/man1/yourProg.1 0644 root other
        d none share 0755 bin bin
        d none share/doc 0755 bin bin
        d none share/doc/yourProg-4.17 0755 root other
        f none share/doc/yourProg-4.17/AUTHORS 0644 root other
        f none share/doc/yourProg-4.17/COPYING 0644 root other
        f none share/doc/yourProg-4.17/ChangeLog 0644 root other
        f none share/doc/yourProg-4.17/README 0644 root other
        f none share/doc/yourProg-4.17/yourProg.conf 0644 root other
        f none share/doc/yourProg-4.17/yourProg.detail 0644 root other

For further information regarding the prototype file, see prototype(4).
Write the prototype file and create the pkginfo file, again, with your
favorite text editor (vi).  The following contents are normally fine:

        PKG="SEyourProg"
        NAME="yourProg"
        ARCH="sparc"
        VERSION="4.17"
        CATEGORY="application"
        VENDOR="Systems Engineering"
        EMAIL="systems@domain.com"
        PSTAMP="1194018748"
        BASEDIR="/usr/local"
        DESC="some description of yourProg up to 256 ASCII characters without line breaks."
        CLASSES="none"

For a brief breakdown of the above pkginfo parameters:

        PKG             =       the name you have chosen for the package;
                                since you are doing this for SE,
                                prepend SE to the name so that it may
                                be easily identifiable
        NAME            =       the program name
        ARCH            =       the operating system type
        VERSION         =       the version number for your program
        CATEGORY        =       the program is an application
        VENDOR          =       software distributor
        EMAIL           =       an email contact
        PSTAMP          =       any unique ID, such as epoch time of build
        BASEDIR         =       the base directory where the files install
        DESC            =       some description of yourProg up to 256 ASCII characters without line breaks
        CLASSES         =       just put none here

For further information on the pkginfo file, see pkginfo(4).  Write the
pkginfo file.  Next we create an installable package in directory format,
via pkgmk:

        hostA [0] pwd
        /usr/local
        hostA [0] /usr/bin/pkgmk -r `pwd`

This will create the necessary files for yourProg in /var/spool/pkg.
To translate the package to a datastream, usable by pkgadd, run pkgtrans
from /var/spool/pkg:

        hostA [0] cd /var/spool/pkg
        hostA [0] /usr/bin/pkgtrans -s `pwd` /tmp/yourProg-4.17

pkgtrans will prompt for which package to make, similar to how pkgadd
prompts for which package to install.  Select yourProg to continue.
After pkgtrans completes, a datastream file will be created as
/tmp/yourProg-4.17.  /tmp/yourProg-4.17 is a fully usable Sun package.
Optionally, at this point, you can gzip the file:

        hostA [0] /usr/bin/gzip /tmp/yourProg-4.17

For further reference, please see the relevant man pages:

        pkgproto(1)     pkgproto(4)     pkginfo(4)      pkgmk(1)
        pkgtrans(1)     cat(1)          gzip(1)         vi(1)

When I originally wrote this tip, I had used the details provided by
Steve Christensen's sunfreeware site as a guide and reference:

        http://sunfreeware.com/pkgadd.html

If you are not familiar with sunfreeware.com, please have a look as
Steve's work has been to the benefit of Solaris admins for the past
16 years.  Thanks Steve, and hopefully I didn't plagiarize your notes
too much.