Building SVR4 Packages


Copyright 2002, 2003 Andy Barclay
OpenContent License (OPL)

Building an SVR4 Package
========================
This shows an example of creating a package that can be manipulated with
the SVR4 standard package commands:
	-pkgadd
	-pkgrm
	-pkgchk
	-pkgtrans, etc

This example creates a package for openssh 3.6p1

Download, extract and build the software from www.openssh.org
./configure --with-ssl-dir=/usr/local/ssl
make
touch /tmp/ssh.marker
sudo make install
cd /usr/local
find . -type f -newer /tmp/ssh.marker -print >/tmp/ssh.files
sudo tar cf /tmp/ssh.tar `cat /tmp/ssh.files`

Created a directory called /opt/packages/UPssh

cd /opt/packages/UPssh

sudo tar xpf /tmp/ssh.tar

Now, create the file pkginfo
------
PKG=UPssh
NAME=Openssh
ARCH=sparc
VERSION=3.6p1
CATEGORY=application
VENDOR=UNIXPeople
EMAIL=billy@buggs.junixpeople.com
CLASSES=none
BASEDIR=/usr/local
MAXINST=1
------

Now, I use a script that creates the prototype file and
changes the file type for the scripts and information files.

The script is called pkg.sh
---------
#!/bin/ksh
PSTAMP=`date +"%Y%m%d%k%M%S"`
PKGDIR=/space/packages/`uname -p`

if [ $# -gt 0 ]
then
	args="$*"
else
	echo "Usage: $0 pkgname" >&2
	exit 1
fi

for i in $args
do
	i=$PKGDIR/$i
	if [ -d $i ]
	then
		:
	else
		echo "$i is not a valid pkg directory" >&2
		exit 2
	fi
	cd $i 
	find . -print |pkgproto >/tmp/prototype.$$
	# filter out the extraneous stuff
	cat /tmp/prototype.$$ |
		grep -v "^f none pkginfo" |
		grep -v "^f none CHANGES" |
		grep -v "^f none scripts" |
		grep -v "^d none scripts" |
		grep -v "^f none depend" |
		grep -v "^f none notes.html" |
		grep -v "^f none space" |
		grep -v "^f none OWNER" |
		grep -v "^f none prototype" >prototype

	rm /tmp/prototype.$$

	# if the OWNER file exists, change the ownership of all
	# files in the prototypefile
	if [ -f OWNER ]
	then
		cat prototype |
			sed -e "s/^\([df].*\) .* .*/\1 `cat OWNER`/" >/tmp/p.$$
		cp /tmp/p.$$ prototype
		rm /tmp/p.$$
	fi

	# now append the necessary stuff to the prototype file
	(echo "i pkginfo=pkginfo"
	[ -f depend ] && echo "i depend=depend"
	[ -f scripts/request ] && echo "i request=scripts/request"
	[ -f scripts/preinstall ] && echo "i preinstall=scripts/preinstall"
	[ -f scripts/postinstall ] && echo "i postinstall=scripts/postinstall"
	[ -f scripts/preremove ] && echo "i preremove=scripts/preremove"
	[ -f scripts/postremove ] && echo "i postremove=scripts/postremove"
	[ -f space ] && echo "i space=space"
	) >>prototype

	#update the pstamp in the pkginfo file
	cat pkginfo |grep -v "^PSTAMP" >/tmp/pkginfo.$$
	mv /tmp/pkginfo.$$ pkginfo
	echo "PSTAMP=$PSTAMP" >>pkginfo

	PKG=`grep "^PKG" pkginfo |sed -e "s/^PKG=//"`
	DESC=`grep "^NAME" pkginfo |sed -e "s/^NAME=//"`
	VERSION=`grep "^VERSION" pkginfo |sed -e "s/^VERSION=//"`

	# now build the package, overwriting existing in /var/spool/pkg
	pkgmk -r `pwd` -o
done
---------

The new package will be stored in /var/spool/pkg/UPssh

Converting the package to stream format
=======================================
The package can be converted to stream format using the following command:
/var/spool/pkg# pkgtrans -s `pwd` /tmp/UPssh.pkg UPssh

NOTE: On installation, the stream formated package will be converted
to file-system format in /var/spool.... This can be a problem on 
machines without sufficient space in /var. In addition, it adds
additional time to the installation.