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 by 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 by 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 by Using The build Class shows a more streamlined approach to editing /etc/inittab during installation.