Packaging your software applications

5c. Modify an existing file using the build class

This 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 shown in case study 5a and case study 5b. The file modified is /etc/inittab.


This case study shows an example of using the build class.


This approach to modifying /etc/inittab uses the build class. A build class file is executed as a shell script and its output becomes the new version of the file for which it is named. In other words, the file inittab(F) that is delivered with this package is executed and the output of that execution becomes /etc/inittab.

The build class file 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 file that installation actions are defined by testing for this argument.

To edit /etc/inittab using the build class, you must:

  1. Define the build file in the prototype(F) file.

    The prototype file entry for the build class file should be of class build and file type e. Be certain that the CLASSES parameter in the pkginfo file includes build. See the sample pkginfo file and sample prototype file for this example.

  2. Create the build file.

    The sample build file performs the following procedures:

    Edits /etc/inittab to remove any changes already existing for this package. Notice that the filename /etc/inittab is hard-coded 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 remind us from where that entry came.

    Executes init q.
This solution addresses the drawbacks in case study 5a and case study 5b. Only one file is needed (beyond the pkginfo and prototype files), that file is short and simple, it works with multiple instances of a package because the $PKGINST parameter is used, and no postinstall script is required because init q can be executed from the build file.

pkginfo file

   NAME='Case Study 5c'
   VERSION='Version 1d05'

prototype file

   i pkginfo
   e build /etc/inittab=/home/case5c/ ? ? ?

build script (/home/case5c/

   # PKGINST parameter provided by installation service

# remove all entries from the existing table that # are associated with this PKGINST sed -e "/^[^:]*:[^:]*:[^:]*:[^#]*#$PKGINST$/d" /etc/inittab || exit 2

if [ "$1" = install ] then # add the following entry to the table echo "rb:023456:wait:/usr/robot/bin/setup #$PKGINST" || exit 2 fi /sbin/init q || exit 2 exit 0

Next topic: 6. Modify crontab files during installation
Previous topic: inittab file

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005