The r.inittab Removal Class Action Script
# PKGINST parameter provided by installation service while read src dest do # remove all entries from the table that # are associated with this PKGINST sed -e "/^[^:]*:[^:]*:[^:]*:[^#]*#$PKGINST$/d" $dest > /tmp/$$itab || exit 2 mv /tmp/$$itab $dest || exit 2 done /sbin/init q || exit 2 exit 0 |
The inittab File
rb:023456:wait:/usr/robot/bin/setup |
Modifying a File Using the sed Class and a postinstall Script
This case study modifies a file which exists on the installation machine during package installation. It uses one of three modification methods. The other two methods are described in "Modifying a File Using Standard Classes and Class Action Scripts" and "Modifying a File Using The build Class". The file modified is /etc/inittab.
Techniques
This case study demonstrates the following techniques:
Using the sed class
For more information on the sed class, see "The sed Class Script ".
Using a postinstall script
For more information on this script, see "Writing Procedure Scripts".
Approach
To modify /etc/inittab at the time of installation, using the sed class, you must complete the following tasks:
Add the sed class script to the prototype file.
The name of a script must be the name of the file that will be edited. In this case, the file to be edited is /etc/inittab and so the sed script is named /etc/inittab. There are no requirements for the mode, owner, and group of a sed script (represented in the sample prototype by question marks). The file type of the sed script must be e (indicating that it is editable).
Set the CLASSES parameter to include the sed class.
As shown in the example file, sed is the only class being installed. However, it could be one of any number of classes.
Create a sed class action script.
Your package cannot deliver a copy of /etc/inittab that looks the way you need it to, since /etc/inittab is a dynamic file and you have no way of knowing how it will look at the time of package installation. However, using a sed script allows you to modify the /etc/inittab file during package installation.
Create a postinstall script.
You need to execute the init q command to inform the system that /etc/inittab has been modified. The only place you can perform that action in this example is in a postinstall script. Looking at the example postinstall script, you will see that its only purpose is to execute the init q command.
This approach to editing /etc/inittab during installation has one drawback; you have to deliver a full script (the postinstall script) simply to perform the init q command.
Case Study Files
The pkginfo File
PKG=case4 NAME=Case Study #4 CATEGORY=applications BASEDIR=/opt ARCH=SPARC VERSION=Version 1d05 CLASSES=sed |
The prototype File
i pkginfo i postinstall e sed /etc/inittab ? ? ? |
The sed Class Action Script (/etc/inittab)
!remove # remove all entries from the table that are associated # with this package, though not necessarily just # with this package instance /^[^:]*:[^:]*:[^:]*:[^#]*#ROBOT$/d !install # remove any previous entry added to the table # for this particular change /^[^:]*:[^:]*:[^:]*:[^#]*#ROBOT$/d # add the needed entry at the end of the table; # sed(1) does not properly interpret the '$a' # construct if you previously deleted the last # line, so the command # $a\ # rb:023456:wait:/usr/robot/bin/setup #ROBOT # will not work here if the file already contained # the modification. Instead, you will settle for # inserting the entry before the last line! $i\ rb:023456:wait:/usr/robot/bin/setup #ROBOT |
The postinstall Script
# make init re-read inittab /sbin/init q || exit 2 exit 0 |
Modifying a File Using The build Class
This case study modifies a file which exists on the installation machine during package installation. It uses one of three modification methods. The other two methods are described in "Modifying a File Using Standard Classes and Class Action Scripts" and "Modifying a File Using the sed Class and a postinstall Script". The file modified is /etc/inittab.
Techniques
This case study demonstrates how to use the build class. For more information on the build class, see "The build Class Script ".
Approach
This approach to modifying /etc/inittab uses the build class. A build class script is executed as a shell script and its output becomes the new version of the file being executed. In other words, the data file /etc/inittab that is delivered with this package will be executed and the output of that execution will become /etc/inittab.
The build class script is executed during package installation and package removal. The argument install is passed to the file if it is being executed at installation time. Notice in the sample build class script that installation actions are defined by testing for this argument.
To edit /etc/inittab using the build class, you must complete the following tasks:
Define the build file in the prototype file.
The entry for the build file in the prototype file should place it in the build class and define its file type as e. Be certain that the CLASSES parameter in the pkginfo file is defined as build.
Create the build class script.
The sample build class script performs the following procedures:
Edits the /etc/inittab file to remove any existing changes for this package. Notice that the file name /etc/inittab is hardcoded into the sed command.
If the package is being installed, adds the new line to the end of /etc/inittab. A comment tag is included in this new entry to describe where that entry came from.
Executes the init q command.