Wednesday, June 29, 2005

How to Make A Solaris Package

How to Make A Solaris Package

1. Make a Prototype File.

A Prototype file contains an exhaustive listing of the files you
want to package up. This file also defines file permissions, group
ownership, user ownership, and file type (file, directory, symbolic
link, etc).

The very beginning of the prototype file is the search path, you
have to tell the pkgmk program where to find all these source files
(otherwise called object files). Having the files listed in the
prototype file is just not enough, you have to implicitly declare each
and every subdirectory to the files you are bundling. You must include
every single directory in the search path!!! This will be quite
tedious if you have a very nested application.

To make this a bit easier, you are allowed to declare variables,
eg: !UL=/usr/local. The !UL is the variable declaration, or the
shortcut for /usr/local. In order to use this variable, you have to
preface the abbreviation with the $ sign, eg: $UL/bin. This is the
same as /usr/local/bin. This saves you 7 characters if you have to
type this over and over again. Here is an example of the prototype
header:


!TEB=/tmp/ebs/bin
!search /tmp /tmp/ebs $TEB $TEB/docs
i pkginfo=/tmp/ebs/pkginfo
d none /tmp 1777 root root
f none /tmp/ebs.txt 0755 user user
f none /tmp/ebs/bin/myprogram.sh 0755 user user
f none /tmp/ebs/bin/docs/mydoc.txt 0755 user staff

2. Now you are ready to build your prototype file.
3. Figure out which software you want to package up.
4. Change directory to the main directory, eg: cd /apps/some_software
5. Find all files and pipe output to pkgproto command: find .
-print | pkgproto > prototype
6. Edit the prototype file and put in the absolute path to the file, eg:

before: f none /bin/myprogram.sh
after: f none /tmp/ebs/bin/myprogram.sh

7. Go over the prototype file with a fine tooth comb and check
permissions and ownership.
8. Pay special attention to dot files, eg: .todayrc, .kshrc. They
won't be captured for some reason. In order to get them to be included
in the package build, you have to manually add them like:

f none /apps/some_software/.adotfile=/apps/some_software/.adotfile
0660 user group

9. Pay special attention to sybmolically linked directories, as
they won't be captured.
10. Once you are confident you have a complete prototype file, you
can now make a description file.
11. Make a pkginfo file. This is the standard file to describe your
package. Here is an example.

PKG="MyPackage" * Note, no funny characters like _ or, -, or !.
NAME="Name"
VERSION="Version 1a"
ARCH="SPARC"
CLASSES="none"
CATEGORY="Application"
VENDOR="My Company"
PSTAMP="27thMay1999"
EMAIL="support@company.com"
ISTATES=" S s 1 2 3"
RSTATES=" S s 1 2 3"
BASEDIR="/"

12. Make a preinstall script (optional). This can be an actual shell
script that checks certain conditions, or in my case, just a few echo
commands reminding the installer what the prerequisites for the
install are, etc.
13. Make a copyright file, eg:

- Include your special files in the prototype file, eg:
i pkginfo=/tmp/pkginfo
i copyright=/tmp/copyright
i preinstall=/tmp/preinstall
i postinstall=/tmp/postinstall

14. Build your package by running: sudo pkgmk -o -d $PWD -f
./prototype 2>err.txt
15. Note, if you do not run this as root, you may not have
permission to access all files, and you will not preserve file
ownership.
16. No doubt you will get a few errors, so might as well redirect
output to a log (err.txt) file.
17. Inspect error log for any problems, if you have success you will
have messages like:

$ more err.txt

## Building pkgmap from package prototype file.
## Processing pkginfo file.
## Attempting to volumize 130 entries in pkgmap.
part 1 -- 94855 blocks, 133 entries
## Packaging one part.
/tmp/MyPackage/pkgmap
/tmp/MyPackage/pkginfo
/tmp/MyPackage/root/apps/my_software/DEVT/bin/16
/tmp/MyPackage/root/apps/my_software/DEVT/bin/AddDev.sh
/tmp/MyPackage/root/apps/my_software/DEVT/bin/AddUser.sh
/tmp/MyPackage/root/apps/my_software/DEVT/s01.i
/tmp/MyPackage/root/apps/my_software/DEVT/s02.d
/tmp/MyPackage/root/apps/my_software/DEVT/s02.i
/tmp/MyPackage/root/apps/my_software/DEVT/s13.i
/tmp/MyPackage/root/apps/my_software/env
/tmp/MyPackage/root/apps/my_software/tab
## Validating control scripts.
## Packaging complete.

18. If you have reached this step, you may now congratulate yourself
for making your First Solaris Package!
19. Verify the package is present: $ ls -alrt drwxr-x--- 3 user
staff 185 May 27 10:53 MyPackage/ Yep, it is there. $ du -sk
MyPackage/ 47144 MyPackage Yep, it is quite big.
20. This matches up with the size of the original
/apps/some_software, with the exception of a few files I chose not to
include.
21. Check out what is in the package directory:

drwxr-x--- 3 user staff 106 May 27 10:53 root/
-rw-rw---- 1 user staff 10429 May 27 10:53 pkgmap
-rw-rw---- 1 user staff 240 May 27 10:53 pkginfo

$ ls root/
apps/

$ more pkginfo
PKG=MyPackage
NAME=My Software 1999
VERSION=Version 1a
ARCH=sun4u
CLASSES=none
CATEGORY=Application
VENDOR=My Company
PSTAMP=27thMay1999
EMAIL=support@company.com
ISTATES= S s 1 2 3
RSTATES= S s 1 2 3
BASEDIR=/

$ more pkgmap
more pkgmap
: 1 94855
1 d none /apps 0755 root root
1 d none /apps/some_software 0755 user staff
1 d none /apps/my_software/DEVT 0770 user staff
1 d none /apps/my_software/DEVT/bin 2770 user staff
1 f none /apps/my_software/DEVT/bin/16 0660 user staff 0 0 925521753
1 f none /apps/my_software/DEVT/bin/lasmacro.quiet 0640 user staff
45091 47500 925362634
1 f none /apps/my_software/DEVT/bin/move_files.orig 0550 user staff
1382 35166 916612436

22. At this point in time, you are technically done. You have three options:
1. keep the directory package as such.
2. tar and compress the directory package.
3. run pkgtrans to make package into 1 single file
(DataStream Package). This is my personal preference.
4. Tar your package (so that you can compress or gzip it):
tar cvf MyPackage.tar MyPackage
5. Compress or GZIP your package. Use compress if you are not
sure if the recipient of the package does not have gzip (since it is
not native to Solaris):$ compress -v MyPackage.tar

It is probably a wise choice not to use gzip, since other
locations (where you are sending the package), may NOT have gzip,
since it is not native to Solaris. Compress is native.
6. Or Skip the tar and compress stuff, and just translate
your package into 1 file ( this simply makes the directory into a cpio
archive file):sudo pkgtrans . PackageName.pkg
7. pkgtrans will look for suitable packages and rename it to
PackageName.pkg
8. Now you can investigate, install or remove packages:
* sudo pkginfo -l PackageName.pkg
* sudo pkgadd -d .
* sudo pkgrm

eg:

$ sudo pkgadd -d .

The following packages are available:
1 MyPackage Direct Lending System 1999
(sun4,sun4c,sun4m,sun4e) Today 511

Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]: 1

Processing package instance from

Direct Lending System 1999
(sun4,sun4c,sun4m,sun4e) Today 511
RabobankGroup Sydney
## Processing package information.
## Processing system information.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.

0 Comments:

Post a Comment

<< Home