The copyright File
Copyright (c) 1999 company_name All Rights Reserved. THIS PACKAGE CONTAINS UNPUBLISHED PROPRIETARY SOURCE CODE OF company_name. The copyright notice above does not evidence any actual or intended publication of such source code |
The compver File
Version 3.0 Version 2.3 Version 2.2 Version 2.1 Version 2.1.1 Version 2.1.3 Version 1.7 |
The depend File
P acu Advanced C Utilities Issue 4 Version 1 P cc C Programming Language Issue 4 Version 1 P dfm Directory and File Management Utilities P ed Editing Utilities P esg Extended Software Generation Utilities Issue 4 Version 1 P graph Graphics Utilities P rfs Remote File Sharing Utilities Issue 1 Version 1 P rx Remote Execution Utilities P sgs Software Generation Utilities Issue 4 Version 1 P shell Shell Programming Utilities P sys System Header Files Release 3.1 |
Modifying a File Using Standard Classes and Class Action Scripts
This case study modifies an existing file during package installation using standard classes and class action scripts. It uses one of three modification methods. The other two methods are described in "Modifying a File Using the sed Class and a postinstall Script" and "Modifying a File Using The build Class". The file modified is /etc/inittab.
Techniques
This case study demonstrates how to use installation and removal class action scripts. For more information, see "Writing Class Action Scripts".
Approach
To modify /etc/inittab during installation, using classes and class action scripts, you must complete the following tasks:
Create a class.
Create a class called inittab. You must provide an installation and a removal class action script for this class. Define the inittab class in the CLASSES parameter in the pkginfo file.
Create an inittab file.
This file contains the information for the entry that you will add to /etc/inittab. Notice in the prototype file figure that inittab is a member of the inittab class and has a file type of e for editable.
Create an installation class action script (i.inittab).
Remember that class action scripts must produce the same results each time they are executed. The class action script performs the following procedures:
Checks if this entry has been added before
If it has, removes any previous versions of the entry
Edits the inittab file and adds the comment lines so you know where the entry is from
Moves the temporary file back into /etc/inittab
Executes the init q command when it receives the ENDOFCLASS indicator
Note that the init q command can be performed by this installation script. A one-line postinstall script is not needed by this approach.
Create a removal class action script (r.inittab).
The removal script is very similar to the installation script. The information added by the installation script is removed and the init q command is executed.
This case study is more complicated than the next one; see "Modifying a File Using the sed Class and a postinstall Script". Instead of providing two files, three are needed and the delivered /etc/inittab file is actually just a place holder containing a fragment of the entry to be inserted. This could have been placed into the i.inittab file except that the pkgadd command must have a file to pass to the i.inittab file. Also, the removal procedure must be placed into a separate file (r.inittab). While this method works fine, it is best reserved for cases involving very complicated installations of multiple files. See "Modifying crontab Files During Installation".
The sed program used in "Modifying a File Using the sed Class and a postinstall Script" supports multiple package instances since the comment at the end of the inittab entry is based on package instance. The case study in "Modifying a File Using The build Class" shows a more streamlined approach to editing /etc/inittab during installation.
Case Study Files
The pkginfo File
PKG=case5 NAME=Case Study #5 CATEGORY=applications BASEDIR=/opt ARCH=SPARC VERSION=Version 1d05 CLASSES=inittab |
The prototype File
i pkginfo i i.inittab i r.inittab e inittab /etc/inittab ? ? ? |
The i.inittab Installation Class Action Script
# PKGINST parameter provided by installation service while read src dest do # remove all entries from the table that # associated with this PKGINST sed -e "/^[^:]*:[^:]*:[^:]*:[^#]*#$PKGINST$/d" $dest > /tmp/$$itab || exit 2 sed -e "s/$/#$PKGINST" $src >> /tmp/$$itab || exit 2 mv /tmp/$$itab $dest || exit 2 done if [ "$1" = ENDOFCLASS ] then /sbin/init q || exit 2 fi exit 0 |