跳过导航链接 | |
退出打印视图 | |
应用程序包开发者指南 Oracle Solaris 10 1/13 Information Library (简体中文) |
在此案例研究中,软件包有三种类型的对象。管理员可以选择安装哪一种对象类型,并选择对象在安装计算机上的位置。
此案例研究展示以下技术:
有关参数化路径名的信息,请参见参数化路径名。
使用 request 脚本请求来自管理员的输入
有关 request 脚本的信息,请参见编写 request 脚本。
为安装参数设置条件值。
要在此案例研究中设置选择性安装,您必须完成以下任务:
为每种可安装对象的类型定义一个类。
在此案例研究中,三种对象类型是:软件包可执行文件、手册页和 emacs 可执行文件。每种类型都有其自己的类: 分别是 bin、man 和 emacs。请注意在 prototype 文件中,所有对象文件均属于这三个类之一。
在 pkginfo 文件中将 CLASSES 参数初始化为 null。
通常在定义类时,应该在 pkginfo 文件的 CLASSES 参数中列出该类。否则,不会安装属于该类的任何对象。对于此案例研究,参数最初设置为 null,意味着不会安装任何对象。 CLASSES 参数将由 request 脚本根据管理员的选择进行更改。这样,CLASSES 参数会仅设置为管理员希望安装的那些对象类型。
注 - 通常可取的方法是将参数设置为缺省值。如果此软件包有对所有三种对象类型通用的组件,可以将其指定给 none 类,然后将 CLASSES 参数设置为等于 none。
将参数化路径名插入到 prototype 文件。
request 脚本会将这些环境变量设置为管理员提供的值。然后,pkgadd 命令在安装时解析这些环境变量,从而知道软件包的安装位置。
此示例中使用的三个环境变量在 pkginfo 文件中设置为其缺省值,作用如下:
$NCMPBIN 定义对象可执行文件的位置
$NCMPMAN 定义手册页的位置
$EMACS 定义 emacs 可执行文件的位置
prototype 示例文件显示了如何定义含变量的对象路径名。
创建 request 脚本,用于询问管理员应该安装软件包的哪些部分及其放置位置。
此软件包的 request 脚本会询问管理员两个问题:
是否应该安装软件包的此部分?
当答复为是时,相应的类名被添加到 CLASSES 参数。例如,当管理员选择安装与此软件包关联的手册页时,类 man 将会添加到 CLASSES 参数。
如果是,应该将软件包的此部分放置在什么位置?
此时将设置相应的环境变量来响应此问题。在手册页示例中,变量 $NCMPMAN 设置为响应值。
对于三种对象类型的每种类型都会重复这两个问题。
在 request 脚本的末尾,参数将设置为对 pkgadd 命令和所有其他打包脚本的安装变量可用。request 脚本通过将这些定义写入调用实用程序提供的文件来实现这一点。对于此案例研究,没有提供其他脚本。
在查看此案例研究中的 request 脚本时,请注意,上述问题是通过数据验证工具 ckyorn 和 ckpath 生成的。有关这些工具的更多信息,请参见 ckyorn(1) 和 ckpath(1)。
PKG=ncmp NAME=NCMP Utilities CATEGORY=application, tools BASEDIR=/ ARCH=SPARC VERSION=RELEASE 1.0, Issue 1.0 CLASSES="" NCMPBIN=/bin NCMPMAN=/usr/man EMACS=/usr/emacs
i pkginfo i request x bin $NCMPBIN 0755 root other f bin $NCMPBIN/dired=/usr/ncmp/bin/dired 0755 root other f bin $NCMPBIN/less=/usr/ncmp/bin/less 0755 root other f bin $NCMPBIN/ttype=/usr/ncmp/bin/ttype 0755 root other f emacs $NCMPBIN/emacs=/usr/ncmp/bin/emacs 0755 root other x emacs $EMACS 0755 root other f emacs $EMACS/ansii=/usr/ncmp/lib/emacs/macros/ansii 0644 root other f emacs $EMACS/box=/usr/ncmp/lib/emacs/macros/box 0644 root other f emacs $EMACS/crypt=/usr/ncmp/lib/emacs/macros/crypt 0644 root other f emacs $EMACS/draw=/usr/ncmp/lib/emacs/macros/draw 0644 root other f emacs $EMACS/mail=/usr/ncmp/lib/emacs/macros/mail 0644 root other f emacs $NCMPMAN/man1/emacs.1=/usr/ncmp/man/man1/emacs.1 0644 root other d man $NCMPMAN 0755 root other d man $NCMPMAN/man1 0755 root other f man $NCMPMAN/man1/dired.1=/usr/ncmp/man/man1/dired.1 0644 root other f man $NCMPMAN/man1/ttype.1=/usr/ncmp/man/man1/ttype.1 0644 root other f man $NCMPMAN/man1/less.1=/usr/ncmp/man/man1/less.1 0644 inixmr other
trap 'exit 3' 15 # determine if and where general executables should be placed ans=`ckyorn -d y \ -p "Should executables included in this package be installed" ` || exit $? if [ "$ans" = y ] then CLASSES="$CLASSES bin" NCMPBIN=`ckpath -d /usr/ncmp/bin -aoy \ -p "Where should executables be installed" ` || exit $? fi # determine if emacs editor should be installed, and if it should # where should the associated macros be placed ans=`ckyorn -d y \ -p "Should emacs editor included in this package be installed" ` || exit $? if [ "$ans" = y ] then CLASSES="$CLASSES emacs" EMACS=`ckpath -d /usr/ncmp/lib/emacs -aoy \ -p "Where should emacs macros be installed" ` || exit $? fi
请注意,request 脚本可以在不在文件系统上留下任何文件的情况下退出。对于 2.5 和兼容版本之前的 Oracle Solaris 版本上的安装(其中没有 checkinstall 脚本可用),可以运行 request 脚本来以任何所需的方式对文件系统进行测试以确保安装成功。当 request 脚本以代码 1 退出时,安装将完全退出。
这些示例文件显示了使用参数化路径建立多个基目录。然而,首选的方法涉及使用由 pkgadd 命令管理并验证的 BASEDIR 参数。每当使用多个基目录时,在同一个平台上安装多个版本和体系结构时应格外小心。