The build Class Script
The build class creates or modifies a package object file by executing Bourne shell instructions. These instructions are delivered as the package object, which runs automatically at installation if it belongs to the build class.
The name of the build class action script should be the same as the name of the file on which the instructions will be executed, and must be executable by the sh command. The script's output becomes the new version of the file as it is built or modified. If the script produces no output, the file will not be created or modified. Therefore, the script can modify or create the file itself.
For example, if a package delivers a default file, /etc/randomtable, and if the file does not already exist on the target system, the prototype file entry might be:
e build /etc/randomtable ? ? ? |
and the package object, /etc/randomtable, might look like this:
!install # randomtable builder if [ -f $PKG_INSTALL_ROOT/etc/randomtable ]; then echo "/etc/randomtable is already in place."; else echo "# /etc/randomtable" > $PKG_INSTALL_ROOT/etc/randomtable echo "1121554 # first random number" >> $PKG_INSTALL_ROOT/etc/randomtable fi !remove # randomtable deconstructor if [ -f $PKG_INSTALL_ROOT/etc/randomtable ]; then # the file can be removed if it's unchanged if [ egrep "first random number" $PKG_INSTALL_ROOT/etc/randomtable ]; then rm $PKG_INSTALL_ROOT/etc/randomtable; fi fi |
See Chapter 5, Package Creation Case Studies for another example using the build class.
The preserve Class Script
The preserve class preserves a package object file by determining whether or not an existing file should be overwritten when the package is installed. Two possible scenarios when using a preserve class script are:
If the file to be installed does not already exist in the target directory, the file will be installed normally.
If the file to be installed exists in the target directory, a message describing the file exists is displayed, and the file is not installed.
Both scenario outcomes are considered successful by the preserve script. A failure occurs only, when in the second scenario, the file is unable to be copied to the target directory.
Starting with the Solaris 7 release, the i.preserve script and a copy of this script, i.CONFIG.prsv, can be found in the /usr/sadm/install/scripts directory with the other class action scripts.
Modify the script to include the filename or filenames you would like to preserve.
How to Write Class Action Scripts
Make the directory containing your information files the current working directory.
Assign the package objects in the prototype file the desired class names. For example, assigning objects to an application and manpage class would look like:
f manpage /usr/share/man/manl/myappl.1l f application /usr/bin/myappl
Modify the CLASSES parameter in the pkginfo file to contain the class names you want to use in your package. For example, entries for the application and manpage classes would look like:
CLASSES=manpage application none
Note - The none class is always installed first and removed last, regardless of where it appears in the definition of the CLASSES parameter.
If you are a creating class action script for a file belonging to the sed, awk, or build class, make the directory containing the package object your current working directory.
Create the class action scripts or package objects (for files belonging to the sed, awk, or build class). An installation script for a class named application would be named i.application and a removal script would be named r.application.
Remember, when a file is part of a class that has a class action script, the script must install the file. The pkgadd command does not install files for which a class action script exists, although it does verify the installation. And, if you define a class but do not deliver a class action script, the only action taken for that class is to copy components from the installation medium to the target system (the default pkgadd behavior).
Complete one of the following tasks.
If you have not created your prototype file, complete the procedure "How to Create a prototype File Using the pkgproto Command", and skip to Step 7.
If you have already created your prototype file, edit it and add an entry for each installation script you just created.
Build your package.
See "How to Build a Package", if needed.
Where to Go Next
After you build the package, install it to confirm that it installs correctly and verify its integrity. Chapter 4, Verifying and Transferring a Package explains how to do this and provides step-by-step instructions on how to transfer your verified package to a distribution medium.