If you wish to create packages of your own, you can manually create a structure that matches the exploded package format, ensuring you enter the correct checksums in the pkgmap file. Alternatively, Solaris provides a number of utilities that you can use to make things a little easier.
We will look at the latter method first, though it is not the most straightforward of procedures. In fact, writing a script to create a package would be a worthwhile project for anybody who will need to create a package.
Our package will comprise a number of scripts that have been developed to assist with the support and administration of a Solaris system. The package will be called DADWutils (Dom and Dave's utilities). It will be packaged as a relocatable package with a default location of /usr/local/utils. We won't be storing the files in a zip file within an archive directory as the Sun packages do; instead all the files to be delivered will be held under the reloc directory and therefore described in the pkgmap file.
To create the package, we will need to know where the master copy of the scripts that make up the package are located and we will need to create a work directory to use while we actually create the package. In this case, the master scripts are located in /export/master/utils with the same directory structure they will have when they are installed, and we will create the directory /export/pkgdir/work as our temporary work directory. The final package will be created in the directory /export/pkgdir/DADWutils (but we don't need to create it as it will be done for us later).
Once we have created the work directory, we need to create a reloc directory under it:
hydrogen# mkdir –p /export/pkgdir/work hydrogen# cd /export/pkgdir/work hydrogen# mkdir reloc hydrogen# ls –l total 2 drwxr-xr-x 2 root other 512 Apr 1 18:56 reloc hydrogen#
We should now create the pkginfo file in our work directory. Ours will be as follows:
PKG=DADWutils NAME=Administration and Support utilities ARCH=sparc VERSION=1.0.0.0 MAXINST=1 CATEGORY=application DESC=Dom and Dave's Support Utilities VENDOR=Dom and Dave HOTLINE=contact Dom and Dave [email protected] CLASSES=none BASEDIR=/usr/local/utils
The pkgmap file is not quite as simple to create, so it will be done in stages using a couple of Solaris utilities. (We have reduced the number of files that we will put in our DADWutils package so the outputs shown are not too cluttered.)
The next step is to copy the package files to the work reloc directory:
hydrogen# cd /export/master/utils hydrogen# ls -R .: bin lib logs logsToTidy ./bin: fswarn startPPP stopPPP tidyLogs ./lib: ./logs: hydrogen# find .|cpio -pvd /export/pkgdir/work/reloc /export/pkgdir/work/reloc/. /export/pkgdir/work/reloc/bin /export/pkgdir/work/reloc/bin/startPPP /export/pkgdir/work/reloc/bin/stopPPP /export/pkgdir/work/reloc/bin/tidyLogs /export/pkgdir/work/reloc/bin/fswarn /export/pkgdir/work/reloc/lib /export/pkgdir/work/reloc/logs /export/pkgdir/work/reloc/logsToTidy 11 blocks hydrogen#
Now we will create what is called a “prototype file” using the pkgproto command. This is an interim file used to help create the pkgmap file.
From the work directory (/export/pkgdir/work) we run the following pkgproto command:
hydrogen# cd /export/pkgdir/work hydrogen# pkgproto reloc=. >prototype hydrogen#
We now have a file called prototype, which has the following contents:
d none bin 0755 root other f none bin/startPPP=reloc/bin/startPPP 0744 root other f none bin/stopPPP=reloc/bin/stopPPP 0744 root other f none bin/tidyLogs=reloc/bin/tidyLogs 0744 root other f none bin/fswarn=reloc/bin/fswarn 0744 root other f none bin/fswarnLog=reloc/bin/fswarnLog 0644 root other d none lib 0755 root other d none logs 0755 root other f none logsToTidy=reloc/logsToTidy 0644 root other
This file does not need to be called prototype, but this is the convention. The prototype file will not actually be delivered as part of the package, but we will use it to help create the pkgmap file.
Before we can do this, we need to add the following line to the end of the prototype file:
i pkginfo=./pkginfo
Now we run the Solaris command pkgmk, which will use the prototype file and the other files we put in our work directory to create the initial version of our package, complete with a pkgmap file:
hydrogen# pkgmk -d /export/pkgdir -f prototype ## Building pkgmap from package prototype file. ## Processing pkginfo file. WARNING: parameter <PSTAMP> set to "hydrogen20010429200612" ## Attempting to volumize 8 entries in pkgmap. part 1 -- 26 blocks, 10 entries ## Packaging one part. /export/pkgdir/DADWutils/pkgmap /export/pkgdir/DADWutils/pkginfo /export/pkgdir/DADWutils/reloc/bin/fswarn /export/pkgdir/DADWutils/reloc/bin/startPPP /export/pkgdir/DADWutils/reloc/bin/stopPPP /export/pkgdir/DADWutils/reloc/bin/tidyLogs /export/pkgdir/DADWutils/reloc/logsToTidy ## Validating control scripts. ## Packaging complete. hydrogen#
This created the basic package for us in the directory /export/pkgdir/DADWutils. We didn't specify this directory in the previous command; we just specified the parent directory. But pkgmk looked in the pkgino file and created the directory with the same name as our package (i.e., the value assigned to PKG). The warning message we got was because we did not create a PSTAMP entry in our pkginfo file so pkgmk created one for us:
hydrogen# cd /export/pkgdir hydrogen# ls -l total 4 drwxr-xr-x 3 root other 512 Apr 1 17:49 DADWutils drwxr-xr-x 4 root other 512 Apr 1 17:24 work hydrogen# rm -r work hydrogne# cd DADWutils hydrogen# ls -l total 6 -rw-r--r-- 1 root other 302 Apr 1 17:49 pkginfo -rw-r--r-- 1 root other 420 Apr 1 17:49 pkgmap drwxr-xr-x 3 root other 512 Apr 1 17:49 reloc hydrogen# cat pkgmap : 1 26 1 d none bin 0755 root other 1 f none bin/fswarn 0755 root other 1034 14901 1017671085 1 f none bin/startPPP 0755 root other 698 58124 1017670893 1 f none bin/stopPPP 0755 root other 358 27164 1017670893 1 f none bin/tidyLogs 0755 root other 1594 33412 1017671035 1 d none lib 0755 root other 1 d none logs 0755 root other 1 f none logsToTidy 0644 root other 364 32935 1017671147 1 i pkginfo 302 25229 1017676159 hydrogen#
We have now removed the work directory, as it is no longer needed. All our files are now under the DADWutils directory. Because the pkgmap file contains checksums for each of the files in the package, we need to be aware that if we change any of them our pkgmap file will no longer be valid.
The package is in directory format and is now ready to install, but we may want to add some files that live in the install directory. For this example, we will add a copyright file and a postinstall script. If we needed to add a depend file, or any others, we would follow exactly the same principle.
First we will make the install directory and create the copyright file in it:
hydrogen# cd /export/pkg/DADWutils hydrogen# mkdir install hydrogen# cd install hydrogen# cat copyright This software is the property of Dom and Dave Enterprises. hydrogen#
Now we will create the postinstall script, which in this case will add a few entries to the root crontab file. We should also create a postremove script that will remove the entries when the package is removed; however, we won't bother for this example since it is exactly the same procedure as creating the postinstall script:
hydrogen# cat postinstall #!/bin/ksh # postinstall script for DADWutils crontab -l | grep -v tidyLogs | grep -v fswarn >/tmp/crontab.$$ echo "15 7 1 * * /usr/local/utils/bin/tidyLogs >/dev/null 2>&1" >>/tmp/crontab.$$ echo "0,15,30,45 * * * * /usr/local/utils/bin/fswarn >/dev/null 2>&1" >>/tmp/crontab.$$ crontab /tmp/crontab.$$ rm -f /tmp/crontab.$$ echo "DADWutil entries added to root crontab" exit 0 hydrogen#
We have almost finished now, but before we can install the package we need to add an entry to the pkgmap file for each of these two files. To do this, we need to get the checksum information for the files. This can be obtained using the Solaris commands sum and cksum:
hydrogen# sum * 5433 1 copyright 31110 1 postinstall hydrogen# cksum * 3976077735 59 copyright 2725132244 381 postinstall hydrogen#
From the above output we can work out the checksums and add the following two lines to the pkgmap file:
1 i copyright 59 5433 3976077735 1 i postinstall 381 31110 2725132244
The package is now ready to install. It is currently in directory format, but we will convert it to a single file so it can be transferred easily to our other servers for installation.
hydrogen# cd /export/pkgdir hydrogen# pkgtrans . /export/packages/dadutils.pkg DADWutils Transferring <DADWutils> package instance hydrogen#
We can now install DADWutils on all our other servers:
lithium# pkgadd -a local_admin -d dadutils.pkg all Processing package instance <DADWutils> from </export/packages/dadutils.pkg> Administration and Support utilities (sparc) 1.0.0.0 This software is the property of Dom and Dave Enterprises. Using </usr/local/utils> as the package base directory. ## Processing package information. ## Processing system information. ## Verifying disk space requirements. Installing Administration and Support utilities as <DADWutils> ## Installing part 1 of 1. /usr/local/utils/bin/fswarn /usr/local/utils/bin/fswarnLog /usr/local/utils/bin/startPPP /usr/local/utils/bin/stopPPP /usr/local/utils/bin/tidyLogs /usr/local/utils/logsToTidy [ verifying class <none> ] ## Executing postinstall script. DADWutil entries added to root crontab Installation of <DADWutils> was successful. lithium#
You will see that our copyright message is displayed at the appropriate point and the postinstall script is executed after the package files have been extracted from under the reloc directory.
We can now install version 1.0.0.0 of DADWutils on all our servers and know they all have a consistent set of support tools installed.