Saturday 6 December 2014

How to Create a Solaris Package

Hello,

          I've been working on Solaris for the past 3 years and the commands i used most on this servers are pkgadd and pkgrm. So if you are developing a application and planning to have it deployed/installed on a solaris machine, it's better to create a solaris package to do the installation rather than copying the files manually over to the server, because the UN-installation becomes a night mare if you do the copy manually, you will definitely not remember where you copied those files and more over you have better things to remember than this. If you use solaris packages to do the installation , the pkg utility in solaris server remembers where those files are installed and you can use the pkg utility to do the UN-installation or query the contents of the package, for more information on the pkg utility commands refer http://docs.oracle.com/cd/E26505_01/html/E29492/ewbej.html . In this post i will be creating a simple solaris package for the GNUscreen utility, i 've already downloaded the GNU screen 3.9.4 and compiled them and available in my solaris server. Now i need to create a package for it so that i don't have to do the compilation every time i need to install the screen utility in other solaris server. I am going  to use Solaris 10 10/08 s10x_u6wos_07b X86 for creating the package.


Let's get to work, i am inside the directory where the files/directory to be packaged are available.

[madhu@pkgserver] $ pwd
/tmp/GNUscreen-pkg


List the contents inside the directory to see what GNU-screen-3.9.4 has,

[madhu@pkgserver] $ ls -l
drwxr-xr-x   2 madhu admin        186 Sep  7 09:47 bin
drwxr-xr-x   2 madhu admin        182 Sep  7 09:47 etc
drwxr-xr-x   2 madhu admin        535 Sep  7 09:47 info
drwxr-xr-x   3 madhu admin       178 Sep  7 09:47 man
drwxr-xr-x   3 madhu admin        180 Sep  7 09:47 share


Next step is to create the pkginfo file, this file is mandatory for package creation. After installing the package , when you do a pkginfo <<packag name>> , the information is read from this file and displayed to the user.  Below is the pkginfo file for this package

[madhu@pkgserver] $ cat pkginfo
PKG=GNUscreen
NAME=GNU screen 3.9.4 SPARC 32bit Solaris 8
VERSION=3.9.4
ARCH=sparc
CLASSES=none
CATEGORY=utility
VENDOR=tester
PSTAMP=1st April 2000
EMAIL=test@email.com
BASEDIR=/


Next step is to Create the Prototype file, this file is the input file for the package creation. This file contains the directories/files/pre-install/post-install scripts to be included in the package,

The Prototype file should be in a specific format, in the below steps we will generate this file.

[madhu@pkgserver] $ pkgproto /tmp/GNUscreen-pkg=/opt/GNUscreen-pkg > prototype
pkgproto is the command to generate the prototype file and the arguments are source directory and target directory.  Ref : http://www.lehman.cuny.edu/cgi-bin/man-cgi?pkgproto+1

Let's list the contents of prototype file. I've truncated the contents to keep the blog post short,

[madhu@pkgserver]$ cat prototype
d none /opt/GNUscreen-pkg 0755 madhu admin
d none /opt/GNUscreen-pkg/bin 0755 madhu admin
f none /opt/GNUscreen-pkg/bin/screen-3.9.4=/tmp/GNUscreen-pkg/bin/screen-3.9.4 0755 madhu admin
d none /opt/GNUscreen-pkg/etc 0755 madhu admin
f none /opt/GNUscreen-pkg/etc/screenrc=/tmp/GNUscreen-pkg/etc/screenrc 0644 madhu admin
d none /opt/GNUscreen-pkg/info 0755 madhu admin
f none /opt/GNUscreen-pkg/info/screen.info-1=/tmp/GNUscreen-pkg/info/screen.info-1 0644 madhu admin
f none /opt/GNUscreen-pkg/info/screen.info-2=/tmp/GNUscreen-pkg/info/screen.info-2 0644 madhu admin
f none /opt/GNUscreen-pkg/info/screen.info=/tmp/GNUscreen-pkg/info/screen.info 0644 madhu admin
f none /opt/GNUscreen-pkg/info/screen.info-3=/tmp/GNUscreen-pkg/info/screen.info-3 0644 madhu admin
f none /opt/GNUscreen-pkg/info/screen.info-4=/tmp/GNUscreen-pkg/info/screen.info-4 0644 madhu admin
f none /opt/GNUscreen-pkg/info/screen.info-5=/tmp/GNUscreen-pkg/info/screen.info-5 0644 madhu admin
d none /opt/GNUscreen-pkg/man 0755 madhu admin
d none /opt/GNUscreen-pkg/man/man1 0755 madhu admin
f none /opt/GNUscreen-pkg/man/man1/screen.1=/tmp/GNUscreen-pkg/man/man1/screen.1 0644 madhu admin
d none /opt/GNUscreen-pkg/share 0755 madhu admin


The syntax of this file is of format <type> <class> <name of file> <permissions> <user> <group> , all the fields are self explanatory, except the second one called class, more information about the class can be found here http://docs.oracle.com/cd/E19683-01/806-7008/6jftmsc38/index.html . If needed you can change the values in the Prototype file except the <name of file> , i am changing the <user> <group> . 
Also the pkginfo file is missing in the protoype file, so that needs to included as well else the package creation will fail. After the change it looks like below.

[madhu@pkgserver]$ cat prototype
i pkginfo
d none /opt/GNUscreen-pkg 0755 root root
d none /opt/GNUscreen-pkg/bin 0755 root root
f none /opt/GNUscreen-pkg/bin/screen-3.9.4=/tmp/GNUscreen-pkg/bin/screen-3.9.4 0755 root root
d none /opt/GNUscreen-pkg/etc 0755 root root
f none /opt/GNUscreen-pkg/etc/screenrc=/tmp/GNUscreen-pkg/etc/screenrc 0644 root root
d none /opt/GNUscreen-pkg/info 0755 root root
f none /opt/GNUscreen-pkg/info/screen.info-1=/tmp/GNUscreen-pkg/info/screen.info-1 0644 root root
f none /opt/GNUscreen-pkg/info/screen.info-2=/tmp/GNUscreen-pkg/info/screen.info-2 0644 root root
f none /opt/GNUscreen-pkg/info/screen.info=/tmp/GNUscreen-pkg/info/screen.info 0644 root root
f none /opt/GNUscreen-pkg/info/screen.info-3=/tmp/GNUscreen-pkg/info/screen.info-3 0644 root root
f none /opt/GNUscreen-pkg/info/screen.info-4=/tmp/GNUscreen-pkg/info/screen.info-4 0644 root root
f none /opt/GNUscreen-pkg/info/screen.info-5=/tmp/GNUscreen-pkg/info/screen.info-5 0644 root root
d none /opt/GNUscreen-pkg/man 0755 root root
d none /opt/GNUscreen-pkg/man/man1 0755 root root
f none /opt/GNUscreen-pkg/man/man1/screen.1=/tmp/GNUscreen-pkg/man/man1/screen.1 0644 root root
d none /opt/GNUscreen-pkg/share 0755 root root


Ok, now everything is set, it's time to create the package .

[madhu@pkgserver]$ pkgmk -o -d /tmp/GNUscreen-pkg/ -f prototype
## Building pkgmap from package prototype file.
## Processing pkginfo file.
WARNING: missing directory entry for </opt>
## Attempting to volumize 28 entries in pkgmap.
part  1 -- 2244 blocks, 121 entries
## Packaging one part.
/tmp/GNUscreen-pkg/GNUscreen/pkgmap
/tmp/GNUscreen-pkg/GNUscreen/pkginfo
/tmp/GNUscreen-pkg/GNUscreen/root/opt/GNUscreen-pkg/bin/screen-3.9.4
/tmp/GNUscreen-pkg/GNUscreen/root/opt/GNUscreen-pkg/etc/screenrc
/tmp/GNUscreen-pkg/GNUscreen/root/opt/GNUscreen-pkg/info/screen.info
/tmp/GNUscreen-pkg/GNUscreen/root/opt/GNUscreen-pkg/info/screen.info-1
/tmp/GNUscreen-pkg/GNUscreen/root/opt/GNUscreen-pkg/info/screen.info-2
/tmp/GNUscreen-pkg/GNUscreen/root/opt/GNUscreen-pkg/share/screen/screeninfo.src
/tmp/GNUscreen-pkg/GNUscreen/root/opt/GNUscreen-pkg/share/screen/screenrc
/tmp/GNUscreen-pkg/GNUscreen/root/opt/GNUscreen-pkg/share/screen/us-braille.tbl
## Validating control scripts.
## Packaging complete.


pkgmk command is used to create the package, let's check the content of the package to ensure the integrity of the package.  Ref : http://heirloom.sourceforge.net/pkgtools/pkgmk.1.html

[madhu@pkgserver]$ pwd
/tmp/GNUscreen-pkg/GNUscreen
[madhu@pkgserver]$ ls -lt root/opt/GNUscreen-pkg/
total 40
drwxr-xr-x   3 melango  httpd        180 Dec  6 15:57 share
drwxr-xr-x   3 melango  httpd        178 Dec  6 15:57 man
drwxr-xr-x   2 melango  httpd        535 Dec  6 15:57 info
drwxr-xr-x   2 melango  httpd        182 Dec  6 15:57 etc
drwxr-xr-x   2 melango  httpd        186 Dec  6 15:57 bin


Though we created the package ,it's in the directory format. We need to transform it in to the pkg format for ease of use.

[madhu@pkgserver]$ pkgtrans -o . /tmp/GNUscreen.pkg GNUscreen
Transferring <GNUscreen> package instance


Ref : http://heirloom.sourceforge.net/pkgtools/pkgtrans.1.html

Let's check the installation.

 [madhu@pkgserver]$ /usr/sbin/pkgadd -d /tmp/GNUscreen.pkg

The following packages are available:
  1  GNUscreen     GNU screen 3.9.4 SPARC 32bit Solaris 8
                   (sparc) 3.9.4

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

Processing package instance <GNUscreen> from </tmp/GNUscreen.pkg>

GNU screen 3.9.4 SPARC 32bit Solaris 8(sparc) 3.9.4
tester
## Processing package information.
## Processing system information.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.

Installing GNU screen 3.9.4 SPARC 32bit Solaris 8 as <GNUscreen>

## Installing part 1 of 1.
/opt/GNUscreen-pkg/bin/screen-3.9.4
/opt/GNUscreen-pkg/etc/screenrc
/opt/GNUscreen-pkg/info/screen.info
/opt/GNUscreen-pkg/info/screen.info-1
/opt/GNUscreen-pkg/info/screen.info-2
/opt/GNUscreen-pkg/info/screen.info-3
/opt/GNUscreen-pkg/info/screen.info-4
/opt/GNUscreen-pkg/info/screen.info-5
/opt/GNUscreen-pkg/man/man1/screen.1

[ verifying class <none> ]

Installation of <GNUscreen> was successful.



[madhu@pkgserver]$ ls -ltr /opt/GNUscreen-pkg/
total 10
drwxr-xr-x   2 root     root         512 Dec  6 17:26 bin
drwxr-xr-x   2 root     root         512 Dec  6 17:26 etc
drwxr-xr-x   2 root     root         512 Dec  6 17:26 info
drwxr-xr-x   3 root     root         512 Dec  6 17:26 man
drwxr-xr-x   3 root     root         512 Dec  6 17:26 share



Nice, the files are available in the desired location with the right permission and ownership.

Let's get some information about the package.

[madhu@pkgserver]$ pkginfo -l GNUscreen
   PKGINST:  GNUscreen
      NAME:  GNU screen 3.9.4 SPARC 32bit Solaris 8
  CATEGORY:  utility
      ARCH:  sparc
   VERSION:  3.9.4
   BASEDIR:  /
    VENDOR:  tester
    PSTAMP:  1st April 2000
  INSTDATE:  Dec 06 2014 17:26
     EMAIL:  test@email.com
    STATUS:  completely installed
     FILES:       28 installed pathnames
                   8 directories
                   1 executables
                1396 blocks used (approx)


Let's remove the package


[madhu@pkgserver]$ /usr/sbin/pkgrm GNUscreen

The following package is currently installed:
   GNUscreen  GNU screen 3.9.4 SPARC 32bit Solaris 8
              (sparc) 3.9.4

Do you want to remove this package? [y,n,?,q] y

## Removing installed package instance <GNUscreen>
## Verifying package <GNUscreen> dependencies in global zone
## Processing package information.
## Removing pathnames in class <none>
/opt/GNUscreen-pkg/share/screen/us-braille.tbl
/opt/GNUscreen-pkg/share/screen/screenrc
/opt/GNUscreen-pkg/share/screen/screeninfo.src
/opt/GNUscreen-pkg/share/screen/screencap
/opt/GNUscreen-pkg/share/screen/newsyntax38
/opt/GNUscreen-pkg/share/screen/newsyntax
/opt/GNUscreen-pkg/share/screen/gs-braille.tbl
/opt/GNUscreen-pkg/share/screen/gr-braille.tbl
## Updating system information.

Removal of <GNUscreen> was successful.

[madhu@pkgserver]$ ls -ltr /opt/GNUscreen-pkg/
/opt/GNUscreen-pkg/: No such file or directory



That's it the solaris package is created. Hope this will be helpful for someone. Please note am not an expert in solaris administration, just sharing what i know. If i am wrong , correct me by commenting. Have a Nice Day :)








No comments:

Post a Comment