DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Packaging your software applications

5a. Modify an existing file using the sed 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 5b and case study 5c. The file modified is /etc/inittab.

Techniques

This case study shows examples of the following techniques:

Approach

To modify /etc/inittab at the time of installation, you must:

  1. Add the sed class script to the prototype(4) 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(1) script is named /etc/inittab. There are no requirements for the mode owner 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). For an example, see the "sample prototype file" .


    NOTE: Because the pathname of the sed class action script is exactly the same as the file it is intended to edit, these two cannot coexist in the same package.

  2. Set the CLASSES parameter to include sed.

    In the case of the sample pkginfo file, sed is the only class being installed. However, it could be one of any number of classes.

  3. Create a sed class action script.

    You cannot deliver a copy of /etc/inittab that looks the way you need for it to, because /etc/inittab has already been installed and is a dynamic file. Because of this, you have no way of knowing how it will look at the time of package installation. Using a sed script allows you to modify the /etc/inittab file during package installation.

    As already mentioned, the name of a sed script should be the same as the name of the file it will edit. A sed script, including the example, contains sed commands to remove and add information to the file.

  4. Create a postinstall script.

    You need to inform the system that /etc/inittab has been modified by executing init q. The only place you can perform that action in this example is in a postinstall script. Looking at the example postinstall script, you see that its only purpose is to execute init q.

This approach to editing /etc/inittab during installation has two drawbacks. First, you have to deliver a full script (the postinstall script) simply to perform init q. In addition, the package name at the end of each comment line is hard-coded. It would be nice if this value could be based on the package instance so that you could distinguish between the entries you add for each package.

pkginfo file

   PKG='case5a'
   NAME='Case Study 5a'
   CATEGORY='applications'
   ARCH='3b2'
   VERSION='Version 1d05'
   CLASSES='sed'

prototype file

   i pkginfo
   i postinstall
   e sed /etc/inittab=/home/mypkg/inittab.sed ? ? ?

sed script (/home/mypkg/inittab.sed)

   !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

postinstall script

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

Next topic: 5b. Modify an existing file using a class action script
Previous topic: depend file

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004