Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
3.  Enhancing the Functionality of a Package Creating Installation Scripts Writing Class Action Scripts How Classes Are Processed During Removal  Previous   Contents   Next 
   
 

The Class Action Script

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:

Name Format

Description

i.class

Operates on path names in the indicated class during package installation.

r.class

Operates on path names in the indicated class during package removal.

For example, the name of the installation script for a class named manpage would be i.manpage and the removal script would be named r.manpage.


Note - 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".


Class Action Script Behaviors

  • Class action scripts are executed as uid=root and gid=other.

  • 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.

Design Rules for Class Action Scripts

  • 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.

The Special System Classes

The system provides four special classes. They are:

  • The sed class

    Provides a method for using sed instructions to edit files upon package installation and removal.

  • The awk class

    Provides a method for using awk instructions to edit files upon package installation and removal.

  • The build class

    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 Script

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 the figure below.

Figure 3-1 Format of a sed Class Action Script

# 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.

For more information on sed instructions, see sed(1). For examples of sed class action scripts, see Chapter 5, Package Creation Case Studies.

The awk Class Script

The awk class provides a method to modify an existing object on the target system. Modifications are delivered as awk instructions in an awk class action script.

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 the figure below.

Figure 3-2 Format of an awk Class Action Script

# 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 awk(1).

 
 
 
  Previous   Contents   Next