Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Application Packaging Developer's Guide
Previous Next

Modifying a File by 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 by Using the sed Class and a postinstall Script and Modifying a File by 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 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.

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
The r.inittab Removal Class Action Script
# PKGINST parameter provided by installation service
while read src dest
do
# remove all entries from the table that
# are associated with this PKGINST
sed -e "/^[^:]*:[^:]*:[^:]*:[^#]*#$PKGINST$/d" $dest >
/tmp/$$itab ||
exit 2
mv /tmp/$$itab $dest ||
exit 2
done
/sbin/init q ||
exit 2
exit 0
The inittab File
rb:023456:wait:/usr/robot/bin/setup
Previous Next

 
 
  Published under the terms fo the Public Documentation License Version 1.01. Design by Interspire