Creating Solaris Packages


Tags:
                                  
Creating Solaris Packages
-------------------------

(This is certainly not the ONLY way to do this, so I'll just show you how I did it, and you 
 can investigate the other ways and decide which one works best for you...  Here are a few
 links)

http://www.ibiblio.org/pub/packages/solaris/sparc/html/creating.solaris.packages.html
http://www.sunfreeware.com

My version is basically a composite of the above two methods.

First, create a directory structure to house the build files for your packages:

mkdir /u01/app/build
mkdir /u01/app/build/config             - will house the config files for the package
mkdir /u01/app/build/package            - will house the final package
mkdir /u01/app/build/pkgtmp             - will house the temporary build
mkdir /u01/app/build/source             - will house the source code for the application

download and untar the source code (in /u01/app/build/source) for the app you wish to make a
package of...  In this case, we'll use the Apache webserver.

mkdir /u01/app/build/source/apache
cp /tmp/httpd-2.2.3.tar /u01/app/build/source/apache/
cd /u01/app/build/source/apache/
tar -xvf httpd-2.2.3.tar 
rm httpd-2.2.3.tar
cd httpd-2.2.3/

mkdir -p /u01/app/build/config/apache/httpd-2.2.3

Now, configure the application as you normally would, but change the prefix to /u01/app/build/pkgtmp 
so that we can get a clean list of files that it installs:

./configure --prefix=/u01/app/build/pkgtmp --disable-ipv6 --enable-so --enable-rewrite

Now install to the configured directory:

make
make install

Now create a list of the files that were installed:

find /u01/app/build/pkgtmp -print > /u01/app/build/config/apache/httpd-2.2.3/files

Now change the prefix in the files list to represent what the prefix of the final package should be.

For example,
/u01/app/build/config/apache/httpd-2.2.3/files now looks something like this:

/u01/app/build/pkgtmp
/u01/app/build/pkgtmp/modules
/u01/app/build/pkgtmp/modules/httpd.exp
/u01/app/build/pkgtmp/bin
/u01/app/build/pkgtmp/bin/apxs
/u01/app/build/pkgtmp/bin/htpasswd
/u01/app/build/pkgtmp/bin/htdigest
/u01/app/build/pkgtmp/bin/rotatelogs
/u01/app/build/pkgtmp/bin/logresolve
/u01/app/build/pkgtmp/bin/ab
/u01/app/build/pkgtmp/bin/checkgid
/u01/app/build/pkgtmp/bin/htdbm
/u01/app/build/pkgtmp/bin/htcacheclean
/u01/app/build/pkgtmp/bin/httxt2dbm
/u01/app/build/pkgtmp/bin/apachectl
/u01/app/build/pkgtmp/bin/dbmmanage
/u01/app/build/pkgtmp/bin/envvars-std
/u01/app/build/pkgtmp/bin/envvars
/u01/app/build/pkgtmp/bin/httpd
/u01/app/build/pkgtmp/conf
/u01/app/build/pkgtmp/conf/extra
/u01/app/build/pkgtmp/conf/extra/httpd-autoindex.conf
/u01/app/build/pkgtmp/conf/extra/httpd-dav.conf
...and so on...


so we need to change that... so:

vi /u01/app/build/config/apache/httpd-2.2.3/files
:1,$s/build\/pkgtmp/apache/g

...will change the files list to look something like this:

/u01/app/apache
/u01/app/apache/modules
/u01/app/apache/modules/httpd.exp
/u01/app/apache/bin
/u01/app/apache/bin/apxs
/u01/app/apache/bin/htpasswd
/u01/app/apache/bin/htdigest
/u01/app/apache/bin/rotatelogs
/u01/app/apache/bin/logresolve
/u01/app/apache/bin/ab
/u01/app/apache/bin/checkgid
/u01/app/apache/bin/htdbm
/u01/app/apache/bin/htcacheclean
/u01/app/apache/bin/httxt2dbm
/u01/app/apache/bin/apachectl
/u01/app/apache/bin/dbmmanage
/u01/app/apache/bin/envvars-std
/u01/app/apache/bin/envvars
/u01/app/apache/bin/httpd
/u01/app/apache/conf
/u01/app/apache/conf/extra
/u01/app/apache/conf/extra/httpd-autoindex.conf
/u01/app/apache/conf/extra/httpd-dav.conf
...and so on...

so now we just need to remove any files from this list that we don't need in the package.
For example, I'll remove the Apache online html manual...

vi /u01/app/build/config/apache/httpd-2.2.3/files

and delete the following lines:

/u01/app/apache/manual*

I would probably also remove the test cgi files:

/u01/app/apache/cgi-bin/printenv
/u01/app/apache/cgi-bin/test-cgi

it's really up to you and what you need...  but this file list is the final list of files
that will be included in your package, so thin out wisely...

once the list is down to what you need, you need to create a package prototype:

cat /u01/app/build/config/apache/httpd-2.2.3/files \
    | pkgproto > /u01/app/build/config/apache/httpd-2.2.3/Prototype

...which will look something like this:

d none /u01/app/apache 0755 root root
d none /u01/app/apache/modules 0755 root root
f none /u01/app/apache/modules/httpd.exp 0644 root root
d none /u01/app/apache/bin 0755 root root
f none /u01/app/apache/bin/apxs 0755 root root
f none /u01/app/apache/bin/htpasswd 0755 root root
f none /u01/app/apache/bin/htdigest 0755 root root
f none /u01/app/apache/bin/rotatelogs 0755 root root
f none /u01/app/apache/bin/logresolve 0755 root root
f none /u01/app/apache/bin/ab 0755 root root
f none /u01/app/apache/bin/checkgid 0755 root root
f none /u01/app/apache/bin/htdbm 0755 root root
f none /u01/app/apache/bin/htcacheclean 0755 root root
f none /u01/app/apache/bin/httxt2dbm 0755 root root
f none /u01/app/apache/bin/apachectl 0755 root root
f none /u01/app/apache/bin/dbmmanage 0755 root root
f none /u01/app/apache/bin/envvars-std 0644 root root
f none /u01/app/apache/bin/envvars 0644 root root
f none /u01/app/apache/bin/httpd 0755 root root
d none /u01/app/apache/conf 0755 root root
d none /u01/app/apache/conf/extra 0755 root root
f none /u01/app/apache/conf/extra/httpd-autoindex.conf 0644 root root
f none /u01/app/apache/conf/extra/httpd-dav.conf 0644 root root
...and so on...

edit the Prototype file to change the file permissions or owner to meet your needs 

you can now remove the temporary build:

rm -r /u01/app/build/pkgtmp/*

Now, reconfigure the app and install it to it's actual location

cd /u01/app/build/source/apache/httpd-2.2.3
make clean
./configure --prefix=/u01/app/apache --disable-ipv6 --enable-so --enable-rewrite
make
make install

Now, create the pkginfo file.  Here is an example:

vi /u01/app/build/config/apache/httpd-2.2.3/pkginfo

-----------------------------------------------------
PKG="CMRapache"
NAME="Apache 2.2.3"
VERSION="2.2.3"
ARCH="sparc"
SUNW_PKG_THISZONE="true"
CLASSES="none"
CATEGORY="application"
PSTAMP="Kyle Reynolds"
EMAIL="kyle.reynold@@camelrichard.org"
BASEDIR="/"
DESC="Apache 2.2.3 compiled with: --prefix=/u01/app/apache --disable-ipv6 --enable-so --enable-rewrite"
------------------------------------------------------

I won't go into the details of this file, so to understand all of the options available here, do a
man on pkginfo(4)

now add an entry to the Prototype file to include this pkginfo file in the package:

vi /u01/app/build/config/apache/httpd-2.2.3/Prototype

add the following line to the top of the file

i pkginfo

You may also add a checkinstall script to verify the platform and version before the package is installed:

(I simply use the example provided on 
 http://www.ibiblio.org/pub/packages/solaris/sparc/html/creating.solaris.packages.html)

This script will check to make sure the platform is solaris 10, sparc version

vi /u01/app/build/config/apache/httpd-2.2.3/checkinstall

--------------------------------------------------------------
#!/bin/sh
 
expected_release="5.10"
expected_platform="sparc"
 
release=`uname -r`
platform=`uname -p`
 
if [ ${platform} != ${expected_platform} ]; then
    echo "\n\n\n\tThis package must be installed on a ${expected_platform} architecture\n"
    echo "\tAborting installation.\n\n\n"
    exit 1
fi
if [ ${release} != ${expected_release} ]; then
    echo "\n\n\n\tThis package must be installed on a ${expected_release} machine\n"
    echo "\tAborting installation.\n\n\n"
    exit 1
fi

exit 0
----------------------------------------------------------------

now add an entry to the Prototype file to include this checkinstall script in the package:

vi /u01/app/build/config/apache/httpd-2.2.3/Prototype

add the following line to the top of the file

i checkinstall

Now create the following script: /u01/app/build/config/apache/httpd-2.2.3/makePackage.sh 
Obviously, edit it to meet your needs...

(Once again, this is just slightly different from the one found here:  
 http://www.ibiblio.org/pub/packages/solaris/sparc/html/creating.solaris.packages.html)

makePackage.sh

#!/bin/sh

pkg=CMRapache
pkgfile=Apache.2.2.3.SPARC.Solaris.2.10.pkg
pkgdir=/u01/app/build/package
pkgmk -o -r / -d ${pkgdir} -f Prototype
echo "Setting file permissions in ${pkgdir}/${pkg} tree to 644."
find ${pkgdir}/${pkg} -type f -print | xargs chmod a+r
find ${pkgdir}/${pkg} -type f -print | xargs chmod u+w
echo "Setting directory permissions in ${pkgdir}/${pkg} tree to 755."
find ${pkgdir}/${pkg} -type d -print | xargs chmod 755
if [ -f ${pkgdir}/${pkg}/install/preinstall ]; then
    chmod 755 ${pkgdir}/${pkg}/install/preinstall
fi
if [ -f ${pkgdir}/${pkg}/install/postinstall ]; then
    chmod 755 ${pkgdir}/${pkg}/install/postinstall
fi
if [ -f ${pkgdir}/${pkg}/install/preremove ]; then
    chmod 755 ${pkgdir}/${pkg}/install/preremove
fi
if [ -f ${pkgdir}/${pkg}/install/postremove ]; then
    chmod 755 ${pkgdir}/${pkg}/install/postremove
fi
if [ -f ${pkgdir}/${pkg}/install/request ]; then
    chmod 755 ${pkgdir}/${pkg}/install/request
fi
if [ -f ${pkgdir}/${pkg}/install/checkinstall ]; then
    chmod 755 ${pkgdir}/${pkg}/install/checkinstall
fi
cd ${pkgdir}
echo "Translating package"
pkgtrans ${pkgdir}/ ${pkgdir}/${pkgfile}
echo "Gzipping ${pkgdir}/${pkg} into ${pkgdir}/${pkgfile}..."
gzip ${pkgdir}/${pkgfile}
rm -rf ${pkgdir}/${pkg}

...and run the script

Your finished package will be waiting for you in /u01/app/build/package
Just gunzip it and use pkgadd to install it

I'll add a few more steps here in a few more days... but these are the basics.


If you have the luxury of dedicating a server to building packages, then good for you, but if 
you don't, then I would suggest checking your build directories (at LEAST the config dir) into SVN
or CVS to allow for some quick fine-tuning and/or upgrades.  It may be overkill, but I have my entire
/u01/app/build/* dirs checked into SVN (source code and all...) and I can make changes and have a new 
package built in minutes.