Search This Blog

Wednesday 13 March 2013

Solaris Package creation with relocation support

Solaris Packages can be created in 4 simple steps listed below:
  1. Create a pkginfo for information about your package.
  2. Create a prototype of your package to include the files which you want to ship.
  3. Make the package to make it ready to ship.
  4. Transfer the package from directory to a data stream file.
Explanation:
There are mainly 6 scripts that you can add to your package. There are some other scripts also which are used for patching. They are:
  1. request: To prompt user for input. This script will not be executed if an instance of package is already installed with instance=overwrite in /var/sadm/install/admin/default file
  2. checkinstall: Used to check whether the package is already installed or the system meets the requirements of package or to configure the installation of your package by setting environment for other scripts.
  3. preinstall: Used to configure installation according to the environment set in checkinstall script.
  4. postinstall: Used to configure installation after the installation has happened.
  5. preremove: Used to execute some pre un-installation commands like removing the new files created by the package which were not part of the package supplied.
  6. postremove: Used to execute full cleanup and other system commands like ldconfig to remove the broken links left by the package removal.
Here is an example for above steps:
# Copy all your scripts to some temp dir
cat $request > /tmp/request
cat $preinstall > /tmp/preinstall
cat $postinstall > /tmp/postinstall
cat $checkinstall > /tmp/checkinstall
cat $preremove > /tmp/preremove
cat $postremove > /tmp/postremove
cat $copyright > /tmp/copyright #for copyright message
cat $depend > /tmp/depend #for adding package names which are required for your package in format of <type> <pkg.abbr> <name>

# Create pkginfo
echo "PKG=$pkg\nNAME=$pkg\nVERSION=$ver\nARCH=$arch\nCLASSES=none\nCATEGORY=application\nVENDOR=$vendor\nPSTAMP=`date`\nEMAIL=mymail@mydomain.com\nBASEDIR=$path" > /tmp/pkginfo

# Create prototype
echo "i pkginfo\ni preinstall\ni postinstall\ni checkinstall\ni request\ni preremove\ni postremove\ni copyright\ni depend" > /tmp/Prototype
pkgproto $path/$pkg=$pkg >> /tmp/Prototype

# For creating relocatable packages
sed -i "s:$path:\$BASEDIR/:g" /tmp/Prototype # Only path represents a variable in this command.

# Make package
#if the package is relocatable then supply "BASEDIR=$path" in below command
pkgmk -o -r / -d /tmp -f /tmp/Prototype


# Transfer the package
cd /tmp
pkgtrans -s `pwd` /tmp/$pkgfile $pkg

Tips:
  1. You can use any temporary directory just replace /tmp with your choice.
  2. You can set the file permissions  before creating a prototype file.
  3. You can use your custom prototype file for file mappings pointing to files in specific directory. for e.g. : i pkginfo=/home/user/mysrc/pkginfo.
  4. You can use your own custom prototype file to define the file permissions also.
Note: All word starting with $ are variables use them as per you choice.

No comments:

Post a Comment