应用程序包开发者指南

使用 build 类修改文件

此案例研究在软件包安装期间修改安装计算机上存在的一个文件。它使用三种修改方法之一。另外两种方法将在使用标准类和类操作脚本修改文件使用 sed 类和 postinstall 脚本修改文件中进行介绍。修改的文件是 /etc/inittab

技术

此案例研究展示如何使用 build 类。有关 build 类的更多信息,请参见build 类脚本

方法

这种修改 /etc/inittab 的方法使用 build 类。build 类脚本作为 shell 脚本执行,其输出成为正在执行的文件的新版本。换句话说,与该软件包一起提供的 /etc/inittab 数据文件将会执行,执行后的输出将成为 /etc/inittab

build 类脚本在软件包安装和删除期间执行。如果该文件在安装时执行,参数 install 会传递给该文件。请注意在 build 样例类脚本中,安装操作通过测试此参数来定义。

要使用 build 类编辑 /etc/inittab,您必须完成以下任务:

该解决方案解决了在使用标准类和类操作脚本修改文件使用 sed 类和 postinstall 脚本修改文件的案例研究中描述的缺点。只需要一个很短的文件(除 pkginfo prototype 文件之外)。因为使用了 PKGINST 参数,所以该文件适用于软件包的多个实例,而且由于 init q 命令可从 build 类脚本中执行,因此不需要 postinstall 脚本。

案例研究文件

pkginfo 文件

PKG=case6
NAME=Case Study #6
CATEGORY=applications
BASEDIR=/opt
ARCH=SPARC
VERSION=Version 1d05
CLASSES=build

prototype 文件

i pkginfo
e build /etc/inittab ? ? ?

生成文件

# 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