Monday, September 24, 2012

SVr4 relocatable package

A relocatable package can be more easily developed then a non-relocatable package.
This is probably because it tends to be more self-contained.
The very first steps are common task.
  
# zfs create -o mountpoint=/pkg data/pkg
# zfs create data/pkg/src
# zfs create data/pkg/out
# mkdir /pkg/src/PHXapp1
# cd /pkg/src/PHXapp1
 
The main idea of a relocatable package is that of a base directory.
It's the root of a directory hierarchy comprising all of the package contents.
It's highly recommended to choose somewhere under /opt and not /usr/local.
Also organize the directory hierarchy, contents, ownership and permissions.
(metafiles are highlighted below just to make them better distinguishable)
 
# cp -pr /project/PHXapp1/* .
# ll
total ...
drwxr-xr-x   2 root  bin         4 Sep 24 11:38 bin
drwxr-xr-x   2 root  bin         3 Sep 24 11:38 include
drwxr-xr-x   2 root  bin         3 Sep 24 11:39 lib
drwxr-xr-x   2 root  bin         3 Sep 24 11:38 man

-rw-r--r--   1 root  root      186 Sep 25 14:40 copyright
-rw-r--r--   1 root  root      236 Sep 28 07:52 pkginfo
-rw-r--r--   1 root  root      381 Sep 28 10:19 request

-rw-r--r--   1 root  root       69 Sep 28 08:01 postremove
-rw-r--r--   1 root  root      333 Sep 28 08:26 prototype

  
Most of what's left to do is quite similar to the non-relocatable package's creation.
The first noticeable exception is the pkginfo's BASEDIR variable.
  
Note that by omitting BASEDIR will make pkgkadd emit an empty prompt for it.
Don't omit BASEDIR to make it a default to a request script base directory prompt.

Interestingly the BASEDIR is not automatically removed by pkgrm.
As the package is relocatable, the base directory may vary among installations.
Thus it isn't a good idea to hard code the base directory in the prototype either.
There comes in the postremove script together with the CLIENT_BASEDIR variable.
  
# cat pkginfo
PKG="PHXapp1"
NAME="Relocatable sample package"
ARCH="i386,sparc"
VERSION="1.0"
CATEGORY="system"
DESC="Relocatable package demonstration"
VENDOR="AZ - Learnings on Solaris"
PSTAMP="Sep 24, 2012"
CLASSES="none"  
BASEDIR=/opt/PHXapp1
  
# cat prototype
! search bin include lib man
i copyright
i pkginfo
i request
i postremove
d none bin 0755 root sys
f none bin/script 0750 root root
f none bin/app1 0550 root sys
d none lib 0755 root sys
f none lib/libapp1 0444 root root
d none include 0755 root sys
f none include/app1.h 0444 root root
d none man 0755 root sys
f none man/man1 0644 root root

# cat request
#!/bin/sh
   
while [ 1 ]
do
    printf "\nPath to base directory (q to quit) [$BASEDIR] "
    read DIRECTORY
   
    case "$DIRECTORY" in
 
        "") break;
            ;;
   
        /*) BASEDIR="$DIRECTORY"
            break;
            ;;
   
         q) exit 1
            ;;
  
         *) printf "\tERROR: Path must begin with a slash (/).\n"
            ;;
    esac
done
 
cat >$1 <EOF
BASEDIR=$BASEDIR
EOF
 
exit 0

   
# cat postremove
#!/bin/sh
echo Removing package base directory.
# Let the system complain if directory not empty (as expected).
rmdir $CLIENT_BASEDIR
exit 0
  
# pkgmk -o -d /pkg/out
## Building pkgmap from package prototype file.
## Processing pkginfo file.
## Attempting to volumize 9 entries in pkgmap.
part  1 -- 22 blocks, 21 entries
## Packaging one part.
/pkg/out/PHXapp1/pkgmap
/pkg/out/PHXapp1/pkginfo
/pkg/out/PHXapp1/reloc/bin/app1
/pkg/out/PHXapp1/reloc/bin/script
/pkg/out/PHXapp1/install/copyright
/pkg/out/PHXapp1/reloc/include/app1.h
/pkg/out/PHXapp1/reloc/lib/libapp1
/pkg/out/PHXapp1/reloc/man/man1
/pkg/out/PHXapp1/install/postremove
/pkg/out/PHXapp1/install/request
## Validating control scripts.
## Packaging complete.
 
  
# pkgtrans /pkg/out /pkg/out/PHXapp1.pkg PHXapp1
 
# ll /pkg/out 
total ...
drwxr-xr-x   3 root root       5 Sep 24 11:39 PHXapp1
-rw-r--r--   1 root root    4.0K Sep 24 12:25 PHXapp1.pkg

...

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