跳过导航链接 | |
退出打印视图 | |
应用程序包开发者指南 Oracle Solaris 10 1/13 Information Library (简体中文) |
此案例研究在软件包安装期间修改安装计算机上存在的一个文件。它使用三种修改方法之一。另外两种方法将在使用标准类和类操作脚本修改文件和使用 build 类修改文件中进行介绍。修改的文件是 /etc/inittab。
此案例研究展示以下技术:
要使用 sed 类在安装时修改 /etc/inittab,您必须完成以下任务:
将 sed 类脚本添加到 prototype 文件。
脚本的名称必须是将编辑文件的名称。在本例中,将编辑的文件是 /etc/inittab,因此 sed 脚本被命名为 /etc/inittab。对于 sed 脚本的模式、所有者和组没有要求(在样例 prototype 中由问号表示)。sed 脚本的文件类型必须是 e(表示可编辑)。
设置 CLASSES 参数以包括 sed 类。
如示例文件所示,sed 是待安装的唯一类。不过,类的数目可以是任意的。
创建 sed 类操作脚本。
您的软件包不能提供您希望的形式的 /etc/inittab 副本,因为 /etc/inittab 是一个动态文件,您无法知道它在软件包安装时的外观形式。不过,可使用 sed 脚本在软件包安装期间修改 /etc/inittab 文件。
创建 postinstall 脚本。
您需要执行 init q 命令通知系统 /etc/inittab 已被修改。在此示例中,您可以执行该操作的唯一位置是在 postinstall 脚本中。查看 postinstall 示例脚本,您会发现它的唯一作用是执行 init q 命令。
这种在安装期间编辑 /etc/inittab 的方法有一个缺点:虽然只是为了执行 init q 命令也必须提供一个完整的脚本(postinstall 脚本)。
PKG=case4 NAME=Case Study #4 CATEGORY=applications BASEDIR=/opt ARCH=SPARC VERSION=Version 1d05 CLASSES=sed
i pkginfo i postinstall e sed /etc/inittab ? ? ?
!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
# make init re-read inittab /sbin/init q || exit 2 exit 0