Creating Solaris packages

An excellent tool for automated Solaris package creation is gnutopkg. To manually create a package, read the steps below.

In this example, I build a Solaris 8 package for cfengine 2.1.21. I create the package with relocatable objects (i.e. relative path names in the package prototype file).

Although these steps may be applied to package other software, please read the Sunfreeware.com Creating pkgadd Software Packages under Solaris page or the Application Packaging Developer's Guide for additional information on creating Solaris packages.

1. Uncompress the source.
$ gzip -cd cfengine-2.1.21.tar.gz | tar xvf -

2. Create an alternate installation directory (i.e. instead of installing into /usr/local by default).
$ mkdir /tmp/pkg

3. Build and install the source, specifying the alternate installation directory when running configure.

$ cd cfengine-2.1.21
$ ./configure --with-docs --with-openssl=/usr/local/ssl --prefix=/tmp/pkg

$ make
$ make install

4. Create the package prototype file.

$ cd /tmp/pkg

$ echo 'i pkginfo' > prototype
$ find . | grep -v '^./prototype$' | pkgproto >> prototype

5. When the package is installed, I want the files to be owned by user root and group root rather than the user that ran make install.

Here is an example line from prototype:
f none sbin/cfagent 0755 hutchib sysadmin

The following awk one-line command will change ownership from hutchib:sysadmin to root:root.

$ awk '$5 == "hutchib" && $6 == "sysadmin" && NF == 6 { $5 = "root"; $6 = "root" } { print }' prototype > prototype.new
$ mv prototype.new prototype

6. Create the package pkginfo file. PKG, NAME, ARCH, VERSION, and CATEGORY are required. For a description of all possible values, see pkginfo(4).

$ vi pkginfo

PKG=BMHcfeng
NAME=cfengine
ARCH=sparc
VERSION=2.1.21
CATEGORY=application
DESC=cfengine 2.1.21
EMAIL=bhutch@gmail.com
BASEDIR=/usr/local


7. Create the package in file system format.
$ pkgmk -o -r . -d .

pkgmk reference:

     -o              Overwrites  the   same   instance;   package
                     instance  will  be overwritten if it already
                     exists.

     -r root_path    Uses the indicated root_path with the source
                     pathname  appended  to locate objects on the
                     source machine, using a  comma  (,)  as  the
                     separator  for  the  path  elements. If this
                     option is specified, look for the full  des-
                     tination  path  in  each  of the directories
                     specified.  If neither -b nor -r  is  speci-
                     fied,  look  for  the  leaf  filename in the
                     current directory.

     -d device       Creates the package on device. device can be
                     an  absolute directory pathname or the iden-
                     tifiers for a floppy disk or removable  disk
                     (for  example,  /dev/diskette).  The default
                     device is the installation  spool  directory
                     (/var/spool/pkg).

8. Translate the package into datastream format. The package will then be a single file, making distribution slightly easier.
$ pkgtrans -s . /tmp/BMHcfeng

I recommend preserving the files used to create the package to speed up any future package modifications.

Back to brandonhutchinson.com.
Last modified: 2006/12/01