Solaris Package creation with relocation support
Creating a Solaris package to ship your application to your customer or user. Making it relocatable so the user can choose to install at any location.
Background
I was working on a application which was ready to be shipped to the customer. We wanted to ship the application in such a way that its easier for the user to install. We started evaluating different ways to ship the application. After experiencing the Portable applications on Windows and the zip/dmg way of App delievery in macOS (formally OS X), the first option which came to everybody’s mind was to create a zip of our application.
The advantage of zip was that the user was able to download the zip from our website and extract it on their machine to install the application.
As our application development progressed we realized that zipping the application with a README file is not enough. Testers were frequently missing some or the other step and running into installation failures. We decided to add a small script which would automate the process of installing the application. It worked great till we had to work with Testers who were not familiar with installation process.
Finally we decided to create a Solaris Package so the Testers and eventually our Customer/User could easily install the application and find help onliine. Solaris Packages were meeting all our requirements like it has a dependency management, it can be easily installed/uninstalled and it has a help system. Apart from this it gave us the freedom of adding various scripts to handle the installation process at different stages.
Creating Solaris Package
Solaris Packages can be created in 4 simple steps listed below:
- Create working space where we will be creating our package.
1 2
mkdir /tmp/myapp && cd /tmp/myapp export MYAPP_PACKAGE_DIR=/tmp/myapp
- Create a
pkginfo
file for information about your package. Check here for more info onpkginfo
file.1 2 3 4 5 6 7 8 9 10
PKG=<pkg> NAME=<pkg> VERSION=<ver> ARCH=<arch> CLASSES=none CATEGORY=application VENDOR=<vendor> PSTAMP=`date` EMAIL=noreply@bikramjs.in BASEDIR=<path>
- Now lets create all the scripts which we will help us automate various steps during installation.
1 2 3 4 5 6 7 8 9
# Copy all your scripts to some temp dir cat /path/src/request > ${MYAPP_PACKAGE_DIR}/request cat /path/src/preinstall > ${MYAPP_PACKAGE_DIR}/preinstall cat /path/src/postinstall > ${MYAPP_PACKAGE_DIR}/postinstall cat /path/src/checkinstall > ${MYAPP_PACKAGE_DIR}/checkinstall cat /path/src/preremove > ${MYAPP_PACKAGE_DIR}/preremove cat /path/src/postremove > ${MYAPP_PACKAGE_DIR}/postremove cat /path/src/copyright > ${MYAPP_PACKAGE_DIR}/copyright #for copyright message cat /path/src/depend > ${MYAPP_PACKAGE_DIR}/depend #for adding package names which are required for your package in format of <type> <pkg.abbr> <name>
There are mainly 6 scripts that you can add to your package. There are some other scripts also which are used for patching. Following is brief explaination about those scripts:
request
: To prompt user for input. This script will not be executed if the package is already installed withinstance=overwrite
in/var/sadm/install/admin/default
filecheckinstall
: 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.preinstall
: Used to configure installation according to the environment set in checkinstall script.postinstall
: Used to configure installation after the installation has happened.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.postremove
: Used to execute full cleanup and other system commands likeldconfig
to remove the broken links left by the package removal.
- Create a
Prototype
file for your package to include the files which you want to ship.1 2 3 4 5 6 7 8 9
i pkginfo i preinstall i postinstall i checkinstall i request i preremove i postremove i copyright i depend
i
in front of all the scripts indicate that its a installation script. Please check documentation here for more info. Now we have a basicPrototype
file with our scripts, copyright message and dependencies. Next we will add our application to thePrototype
file:1 2
# myapp in the command below is the name of the sub folder which will contain all my files. pkgproto /path/src/dist=/myapp >> ${MYAPP_PACKAGE_DIR}/Prototype
- Create the installable package using
pkgmk
. Check here for more information.1
pkgmk -o -r / -d ${MYAPP_PACKAGE_DIR} -f ${MYAPP_PACKAGE_DIR}/Prototype
- Previous step creates the package in a directory which is not suitable for shiping or downloading from a website. Now we need to translate the package from directory to a data stream file. Check here for more info on
pkgtrans
.1
pkgtrans -s `pwd` ${MYAPP_PACKAGE_DIR}/myapp.pkg myapp
- You can use any temporary directory just replace /tmp with your choice.
- You can set the file permissions before creating a prototype file.
- 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
.- You can use your own custom prototype file to define the file permissions also.
- You can use
-g
flag inpkgtrans
command to sign the packages to build trust among your users.
Making package relocatable
So far we have see how to create a package on Solaris. Now in order to make it relocatable we need to run few extra steps during the packing process.
Steps would remain same till Prototype
file generation. After the Prototype
file is generated we need to update our Prototype
to tell it that its a relocatable package and user should be able to install the package at any location they want.
- Lets make the package relocateable
1
sed -i "s:/myapp:\$BASEDIR/:g" ${MYAPP_PACKAGE_DIR}/Prototype # $BASEDIR variable will make sure that package becomes relocateable
- Now lets create the pkg using
pkgmk
command with a value pointing to our package locally.1
pkgmk -o -r / -d ${MYAPP_PACKAGE_DIR} -f ${MYAPP_PACKAGE_DIR}/Prototype BASEDIR=/path/src/dist # BASEDIR here is a varaible
- Now we can use the
pkgtrans
command to convert it to a single file for easy distribution.1
pkgtrans -s `pwd` ${MYAPP_PACKAGE_DIR}/myapp.pkg myapp
Testing
To test the package, you can install it on a Solaris machine and use following command to verify if the relocation support we added is working or not. Check here for all supported options in pkgadd
.
1
2
pkgadd –R /opt/installed_myapp myapp.pkg
ls -l /opt/installed_myapp/bin/myapp