Application Packaging Developer's Guide

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.


This case study demonstrates the following techniques:


To modify /etc/inittab at the time of installation, using the sed class, you must complete the following tasks:

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

NAME=Case Study #4
VERSION=Version 1d05

The prototype File

i pkginfo
i postinstall
e sed /etc/inittab ? ? ?

The sed Class Action Script (/etc/inittab)

# remove all entries from the table that are associated
# with this package, though not necessarily just
# with this package instance
# remove any previous entry added to the table
# for this particular change
# 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!
rb:023456:wait:/usr/robot/bin/setup #ROBOT

The postinstall Script

# make init re-read inittab
/sbin/init q ||
exit 2
exit 0