Object classes allow a series of actions to be performed on a group of package objects at installation or removal. You assign objects to a class in the prototype file. All package objects must be given a class, although the class of none is used by default for objects that require no special action.
The installation parameter
CLASSES, defined in the pkginfo file, is a list of classes to be installed (including the none class).
CLASSES list determines the order of installation. Class none is always installed first, if present, and removed last. Since directories are the fundamental support structure for all other file system objects, they should all be assigned to the none class. Exceptions can be made, but as a general rule, the none class is safest. The reason for this is to ensure that the directories are created before the objects they will contain and also to ensure that no attempt is made to delete a directory before it has been emptied.
The pkgadd command creates a list of path names upon which the action script will operate. Each line of this list contains source and destination path names, separated by a space. The source path name indicates where the object to be installed resides on the installation volume and the destination path name indicates the location on the target system where the object should be installed. The contents of the list are restricted by the following criteria:
The list contains only path names belonging to the associated class.
If the attempt to create the package object fails, directories, named pipes, character devices, block devices, and symbolic links are included in the list with the source path name set to /dev/null. Normally they will be automatically created by the pkgadd command (if not already in existence) and given proper attributes (mode, owner, group) as defined in the pkgmap file.
Linked files where the file type is l are not included in the list under any circumstances. Hard links in the given class are created in item 4.
If no class action script is provided for installation of a particular class, the path names in the generated list are copied from the volume to the appropriate target location.
If there is a class action script, the script is executed.
The class action script is invoked with standard input containing the list generated in item 1. If this is the last volume of the package, or there are no more objects in this class, the script is executed with the single argument of ENDOFCLASS.
Even if there are no regular files of this class anywhere in the package, the class action script will be called at least once with an empty list and the ENDOFCLASS argument.
The pkgadd command performs a content and attribute audit and creates hard links.
After successfully executing items 2 or 3, the pkgadd command audits both content and attribute information for the list of path names. The pkgadd command creates the links associated with the class automatically. Detected attribute inconsistencies are corrected for all path names in the generated list.
Objects are removed class by class. Classes that exist for a package but that are not listed in the
CLASSES parameter are removed first (for example, an object installed with the installf command). Classes listed in the
CLASSES parameter are removed in reverse order. The none class is always removed last. The following list describes the system actions that occur when a class is removed:
The pkgrm command creates a path name list.
The pkgrm command creates a list of installed path names that belong to the indicated class. Path names referenced by another package are excluded from the list unless their file type is e (meaning the file should be edited upon installation or removal).
If the package being removed modified any files of type e during installation, it should remove just the lines it added. Do not delete a non-empty editable file; just remove the lines the package added.
If there is no class action script, the path names are deleted.
If your package has no removal class action script for the class, all the path names in the list generated by the pkgrm command are deleted.
Files with a file type of e (editable), which are not assigned to a class and an associated class action script, will be removed at this point, even if the path name is shared with other packages.
If there is a class action script, the script is executed.
The pkgrm command invokes the class action script with standard input for the script containing the list generated in item 1.
The pkgrm command performs an audit.
After successfully executing the class action script, the pkgrm command removes knowledge of the path names from the package database unless a path name is referenced by another package.
The class action script defines a set of actions to be executed during installation or removal of a package. The actions are performed on a group of path names based on their class definition. (See Chapter 5, Package Creation Case Studies for examples of class action scripts.)
The name of a class action script is based on the class on which it should operate and whether those operations should occur during package installation or removal. The two name formats are as follows:
Operates on path names in the indicated class during package installation.
Operates on path names in the indicated class during package removal.
This file name format is not used for files belonging to the sed, awk, or build system classes. For more information on these special classes, see "The Special System Classes".
A script is executed for all files in the given class on the current volume (for example, floppy disk).
The pkgadd and pkgrm commands create a list of all objects listed in the pkgmap file that belong to the class. As a result, a class action script can act only upon path names defined in the pkgmap that belong to a particular class.
When a class action script is executed for the last time (that is, no more files are found belonging to that class), the class action script will be executed once with the keyword argument ENDOFCLASS.
Administrator interaction is not permitted during execution of a class action script.
If a package spans more than one volume, the class action script is executed once for each volume that contains at least one file belonging to a class. Consequently, each script must be able to be executed more than once. This means that executing a script any number of times with the same input must produce the same results as executing the script only once.
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.
A class action script should never add, remove, or modify a path name or system attribute that does not appear in the list generated by the pkgadd command. For more information on this list, see item 1 in "How Classes Are Processed During Installation".
When your script sees the ENDOFCLASS argument, put post-processing actions (like clean up) into your script.
All administrator interaction is restricted to the request script. Do not try to obtain information from the administrator using a class action script.
Provides a method for using sed instructions to edit files upon package installation and removal.
Provides a method for using awk instructions to edit files upon package installation and removal.
Provides a method to dynamically construct or modify a file using Bourne shell commands.
The preserve class
Provides a method to preserve files that should not be overwritten by future package installations.
If there are several files in a package that require special processing that can be fully defined through sed, awk, or sh commands, installation will be faster by using the system classes rather than multiple classes and their corresponding class action scripts.
The sed class provides a method to modify an existing object on the target system. The sed class action script executes automatically at installation if a file belonging to class sed exists. The name of the sed class action script should be the same as the name of the file on which the instructions will be executed.
A sed class action script delivers sed instructions in the format shown in Figure 3-1.
# comment, which may appear on any line in the file !install # sed(1) instructions which will be invoked during # installation of the object [address [,address]] function [arguments] . . . !remove # sed(1) instructions to be invoked during the removal process [address [,address]] function [arguments]
Two commands indicate when instructions should be executed. The sed instructions that follow the !install command are executed during package installation and those that follow the !remove command are executed during package removal. It does not matter which order these commands are used in the file.
The awk class action script is executed automatically at installation if a file belonging to class awk exists. Such a file contains instructions for the awk class script in the format shown in Figure 3-2.
# comment, which may appear on any line in the file !install # awk(1) program to install changes . . . (awk program) !remove # awk1(1) program to remove changes . . . (awk program)
Two commands indicate when instructions should be executed. The awk instructions that follow the !install command are executed during package installation, and those that follow the !remove command are executed during package removal. It does not matter in which order these commands are used in the file.
The name of the awk class action script should be the same as the name of the file on which the instructions will be executed.
The file to be modified is used as input to awk and the output of the script ultimately replaces the original object. Environment variables may not be passed to the awk command with this syntax.
For more information on awk instructions, see the awk(1) man page.
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.
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 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.
#ident "$Header: i.CONFIG.prsv,v 12.1 1997/09/19 $" error=no echo "## checking common configuration files" while read src dest do [ "$src" = /dev/null ] && continue if [ -f "$dest" ] then echo $dest preserved else echo $dest cp $src $dest || error=yes fi done [ "$error" = yes ] && exit 2 exit 0
Modify the script to include the filename or filenames you would like to preserve.