Wednesday, September 19, 2012

Non-relocatable SVr4 package

Packages advantages, such as consistency and standardization are quite obvious.
Of course one can get very complex about it, but it suffices to play it simple.
   
An essential distinction is between relocatable and non-relocatable options.
Relocatable packages comprises a directory hierarchy that can be rooted at will.
Non-relocatable packages merge their contents into the preexistent directory hierarchy.
   
It's very easy to create a simple non-relocatable SVr4 package.
Begin by organizing disjoint directories where to put sources and output.
A ZFS file-system proves useful for handling many versions via snapshots and clones.
   
# zfs create -o mountpoint=/pkg data/pkg
# zfs create data/pkg/src
# zfs create data/pkg/out
   
It's a good practice to give a package name a well defined prefix.
Typically an abbreviation of an organization name or other acronym is used.
    
# mkdir /pkg/src/PHXsvc1
    
All the subsequent work will be done inside the source directory.
Actually this isn't required but will simplify matters.
   
# cd /pkg/src/PHXsvc1
    
Once in the source directory, create or put the package contents (files and directories).
Adjust mode and ownership as it should be on the target system after the installation.
    
# ll
total ...
-r--r--r--   1 root  sys    934 Sep 13 15:36 manifest.xml
-r-xr-xr-x   1 root  sys    582 Sep 12 15:55 script.sh
...
   
Generate the base prototype.
The above and below highlights shows related information.
    
# find . ! -name . -a ! -name prototype | pkgproto > prototype
# cat prototype 
f none manifest.xml 0444 root sys
f none script.sh 0555 root sys
   
Edit the prototype to describe where each item will be placed on the target system.
New directories (d) can be created and existent ones can be referenced within new files (f).
Except for JumpStart, when packaging SMF services set the class to manifest.
Every new class that's used must also be referenced in pkginfo's CLASSES.
The below highlights shows what's been edited in the base prototype.
          
# cat prototype 
f manifest /var/svc/manifest/site/manifest.xml 0444 root sys
d none /opt/site 0755 root sys
f none /opt/site/script.sh 0555 root sys
     
Create the information files copyright, pkginfo and scripts in the source directory.
For SMF manifests the search clause is required to point to supporting scripts.
For JumpStart, the search clause and the supporting scripts shouldn't be used.
Reference them all in the prototype along with the package contents.
   
# cat copyright

  Copyright (c) 2012 ...
  All Rights Reserved.


  This product is protected by copyright and distributed under
  licenses restricting copying, distribution, and decompilation.


  
# cat pkginfo
PKG="PHXsvc1"
NAME="Non-relocatable sample package"
ARCH="i386,sparc"
VERSION="1.0"
CATEGORY="system"
DESC="Non-relocatable package demonstration"
VENDOR="AZ - Learnings on Solaris"
PSTAMP="Sep 19, 2012"
CLASSES="none manifest" 
   
# cat prototype 
! search /usr/sadm/install/scripts/
i copyright
i pkginfo
i i.manifest
i r.manifest

f manifest /var/svc/manifest/site/manifest.xml 0444 root sys
d none /opt/site 0755 root sys
f none /opt/site/script.sh 0555 root sys
   
Finally, create the package.    
   
# pkgmk -o -d /pkg/out
## Building pkgmap from package prototype file.
## Processing pkginfo file.
WARNING: missing directory entry for </opt>
WARNING: missing directory entry for </var>
WARNING: missing directory entry for </var/svc>
WARNING: missing directory entry for </var/svc/manifest>
WARNING: missing directory entry for </var/svc/manifest/site>
## Attempting to volumize 3 entries in pkgmap.
part  1 -- 31 blocks, 17 entries
## Packaging one part.
/pkg/out/PHXsvc1/pkgmap
/pkg/out/PHXsvc1/pkginfo
/pkg/out/PHXsvc1/root/opt/site/script.sh
/pkg/out/PHXsvc1/root/var/svc/manifest/site/manifest.xml
/pkg/out/PHXsvc1/install/copyright
/pkg/out/PHXsvc1/install/i.manifest
/pkg/out/PHXsvc1/install/r.manifest
## Validating control scripts.
## Packaging complete.
       
It may be convenient to convert the package to a streamed format.
Notably because it's easier to deal with a single file instead of a directory hierarchy.
     
# pkgtrans /pkg/out /pkg/out/PHXsvc1.pkg PHXsvc1
 
# ll /pkg/out 
total ...
drwxr-xr-x   3 root  root      5 Sep 19 10:28 PHXsvc1
-rw-r--r--   1 root  root   3.5K Sep 19 10:55
PHXsvc1.pkg
...
   

A few verifications could be:
   
# pkgchk -d /pkg/out/PHXsvc1.pkg all 
Checking uninstalled stream format package <PHXsvc1> from </pkg/out/PHXsvc1.pkg>
## Checking control scripts.
## Checking package objects.
## Checking is complete.
  
  
# pkginfo -l -d /pkg/out/PHXsvc1.pkg
   PKGINST:  PHXsvc1
      NAME:  Non-relocatable sample package
  CATEGORY:  system
      ARCH:  i386,sparc
   VERSION:  1.0
    VENDOR:  AZ - Learnings on Solaris
      DESC:  Non-relocatable package demonstration
    PSTAMP:  Sep 19, 2012
    STATUS:  spooled
     FILES:        8 spooled pathnames
                   1 directories
                   1 executables
                   5 package information files
                   3 blocks used (approx)