JavaScript is required to for searching.
跳过导航链接
退出打印视图
应用程序包开发者指南     Oracle Solaris 10 1/13 Information Library (简体中文)
search filter icon
search icon

文档信息

前言

1.  设计软件包

2.  生成软件包

3.  增强软件包的功能(任务)

4.  验证和转换软件包

5.  软件包创建案例研究

6.  创建软件包的高级技术

指定基目录

缺省管理文件

适应不确定性

使用 BASEDIR 参数

使用参数化基目录

示例-使用参数化基目录

pkginfo 文件

pkgmap 文件

管理基目录

适应重定位

遍历基目录

使用 BASEDIR 参数

pkginfo 文件

pkgmap 文件

示例-遍历 BASEDIR 的分析脚本

request 脚本

checkinstall 脚本

使用相对参数化路径

pkginfo 文件

pkgmap 文件

示例-遍历相对参数化路径的 request 脚本

在异构环境中支持重定位

传统方法

可重定位软件包

示例-传统的可重定位软件包

pkginfo 文件

pkgmap 文件

绝对软件包

示例-传统绝对软件包

pkgmap 文件

复合软件包

示例-传统解决方案

pkginfo 文件

pkgmap 文件

超越传统

复合软件包另一特性

使绝对路径名看起来像可重定位对象

示例-修改文件

说明

实现

示例

示例-创建新文件

说明

实现

示例

示例 -复合软件包

pkginfo 文件

pkgmap 文件

使软件包可远程安装

示例-安装到客户机系统

示例-安装到服务器或独立系统

示例-挂载共享文件系统

修补软件包

checkinstall 脚本

preinstall 脚本

类操作脚本

postinstall 脚本

patch_checkinstall 脚本

patch_postinstall 脚本

升级软件包

request 脚本

postinstall 脚本

创建类归档软件包

归档软件包目录的结构

支持类归档软件包的关键字

faspac 实用程序

词汇表

索引

适应重定位

尽管您可以为各种软件包选择能够保证对某个体系结构和版本唯一的基目录,但这会导致目录分层结构中存在多余的级别。例如,对于为基于 SPARC 和 x86 的处理器设计的产品,您可能会根据处理器和版本组织基目录,如下所示。

基目录
版本和处理器
/opt/SUNWstuf/sparc/1.0
1.0 版,SPARC
/opt/SUNWstuf/sparc/1.2
1.2 版,SPARC
/opt/SUNWstuf/x86/1.0
1.0 版,x86

这样做完全可以而且有效,但是您处理名称和编号的方式就好像它们对管理员有意义一样。一种更好的方法是在向管理员进行解释并获取权限之后自动完成此工作。

这意味着您可以在软件包中完成全部工作,而无需要求管理员手动完成。您可以在 postinstall 脚本中任意指定基目录,然后透明地建立适当的客户机链接。您还可以在 postinstall 脚本中使用 pkgadd 命令在客户机上安装软件包的全部或一部分。您甚至可以咨询管理员哪些用户或客户机需要了解此软件包,并自动更新 PATH 环境变量和 /etc 文件。只要软件包在安装时执行的所有操作能够在删除时撤消,那么该方法是完全可以接受的。

遍历基目录

您可以利用两种方法在安装时控制基目录。第一种方法最适合于仅能安装在 Solaris 2.5 和兼容发行版上的新软件包;它为管理员提供非常有用的数据,支持多个已安装的版本和体系结构,而只需要完成最少的特殊工作。第二种方法可由任何软件包使用,并且利用 request 脚本所固有的对于生成参数的控制来确保安装成功。

使用 BASEDIR 参数

checkinstall 脚本可以在安装时选择适当的基目录,这意味着可以将基目录放置在目录树中非常低的位置。此示例按顺序递增基目录,从而得到如下形式的目录:/opt/SUNWstuf/opt/SUNWstuf.1/opt/SUNWstuf.2。管理员可以使用 pkginfo 命令确定在每个基目录中所安装的体系结构和版本。

如果 SUNWstuf 软件包(包含一组执行具体工作的实用程序)使用此方法,则它的 pkginfo pkgmap 文件将如下所示。

pkginfo 文件
# pkginfo file
PKG=SUNWstuf
NAME=software stuff 
ARCH=sparc
VERSION=1.0.0,REV=1.0.5
CATEGORY=application
DESC=a set of utilities that do stuff
BASEDIR=/opt/SUNWstuf
VENDOR=Sun Microsystems, Inc.
HOTLINE=Please contact your local service provider
EMAIL=
MAXINST=1000
CLASSES=none daemon
PSTAMP=hubert990707141632
pkgmap 文件
: 1 1758
1 d none EZstuf 0775 root bin
1 f none EZstuf/dirdel 0555 bin bin 40 773 751310229
1 f none EZstuf/usrdel 0555 bin bin 40 773 751310229
1 f none EZstuf/filedel 0555 bin bin 40 773 751310229
1 d none HRDstuf 0775 root bin
1 f none HRDstuf/mksmart 0555 bin bin 40 773 751310229
1 f none HRDstuf/mktall 0555 bin bin 40 773 751310229
1 f none HRDstuf/mkcute 0555 bin bin 40 773 751310229
1 f none HRDstuf/mkeasy 0555 bin bin 40 773 751310229
1 d none /etc    ? ? ?
1 d none /etc/rc2.d ? ? ?
1 f daemon /etc/rc2.d/S70dostuf 0744 root sys 450 223443
1 i pkginfo 348 28411 760740163
1 i postinstall 323 26475 751309908
1 i postremove 402 33179 751309945
1 i preinstall 321 26254 751310019
1 i preremove 320 26114 751309865
1 i i.daemon 509 39560 752978103
1 i r.daemon 320 24573 742152591

示例-遍历 BASEDIR 的分析脚本

假定 SUNWstuf 的 x86 版本已经安装在服务器上的 /opt/SUNWstuf 中。当管理员使用 pkgadd 命令安装 SPARC 版本时,request 脚本需要检测是否存在 x86 版本并且与管理员就安装问题进行交互。


注 - 可在 checkinstall 脚本中遍历基目录而无需管理员交互,但是,如果此类任意操作的发生过于频繁,管理员会在此过程中失去信心。


软件包的用于处理此情形的 request 脚本和 checkinstall 脚本可能如下所示。

request 脚本
# request script
for SUNWstuf to walk the BASEDIR parameter.
 
PATH=/usr/sadm/bin:${PATH}    # use admin utilities
 
GENMSG="The base directory $LOCAL_BASE already contains a \
different architecture or version of $PKG."
 
OLDMSG="If the option \"-a none\" was used, press the  \
key and enter an unused base directory when it is requested."
 
OLDPROMPT="Do you want to overwrite this version? "
 
OLDHELP="\"y\" will replace the installed package, \"n\" will \
stop the installation."
 
SUSPEND="Suspending installation at user request using error \
code 1."
 
MSG="This package could be installed at the unused base directory $WRKNG_BASE."
 
PROMPT="Do you want to use to the proposed base directory? "
 
HELP="A response of \"y\" will install to the proposed directory and continue,
\"n\" will request a different directory. If the option \"-a none\" was used,
press the  key and enter an unused base directory when it is requested."
 
DIRPROMPT="Select a preferred base directory ($WRKNG_BASE) "
 
DIRHELP="The package $PKG will be installed at the location entered."
 
NUBD_MSG="The base directory has changed. Be sure to update \
any applicable search paths with the actual location of the \
binaries which are at $WRKNG_BASE/EZstuf and $WRKNG_BASE/HRDstuf."
 
OldSolaris=""
Changed=""
Suffix="0"
 
#
# Determine if this product is actually installed in the working
# base directory.
#
Product_is_present () {
      if [ -d $WRKNG_BASE/EZstuf -o -d $WRKNG_BASE/HRDstuf ]; then
            return 1
      else
            return 0
      fi
}
 
if [ ${BASEDIR} ]; then
      # This may be an old version of Solaris. In the latest Solaris
      # CLIENT_BASEDIR won't be defined yet. In older version it is.
      if [ ${CLIENT_BASEDIR} ]; then
            LOCAL_BASE=$BASEDIR
            OldSolaris="true"
      else    # The base directory hasn't been processed yet
            LOCAL_BASE=${PKG_INSTALL_ROOT}$BASEDIR
fi
 
WRKNG_BASE=$LOCAL_BASE
 
    # See if the base directory is already in place and walk it if
    # possible
while [ -d ${WRKNG_BASE} -a Product_is_present ]; do
         # There is a conflict
         # Is this an update of the same arch & version?
         if [ ${UPDATE} ]; then
               exit 0    # It's out of our hands.
         else
               # So this is a different architecture or
               # version than what is already there.
               # Walk the base directory
               Suffix=`expr $Suffix + 1`
               WRKNG_BASE=$LOCAL_BASE.$Suffix
               Changed="true"
         fi
done
 
    # So now we can propose a base directory that isn't claimed by
    # any of our other versions.
if [ $Changed ]; then
         puttext "$GENMSG"
         if [ $OldSolaris ]; then
               puttext "$OLDMSG"
               result=`ckyorn -Q -d "a" -h "$OLDHELP" -p "$OLDPROMPT"`
               if [ $result="n" ]; then
                     puttext "$SUSPEND"
                     exit 1    # suspend installation
               else
                     exit 0
               fi
         else    # The latest functionality is available
               puttext "$MSG"
               result=`ckyorn -Q -d "a" -h "$HELP" -p "$PROMPT"`
               if [ $? -eq 3]; then
                     echo quitinstall >> $1
                     exit 0
               fi
 
               if [ $result="n" ]; then
                     WRKNG_BASE=`ckpath -ayw -d "$WRKNG_BASE" \
                     -h "$DIRHELP" -p "$DIRPROMPT"`
               else if [ $result="a" ]
                     exit 0
               fi
            fi
            echo "BASEDIR=$WRKNG_BASE" >> $1
            puttext "$NUBD_MSG"
      fi
fi
exit 0
checkinstall 脚本
# checkinstall
script for SUNWstuf to politely suspend
 
grep quitinstall $1
if [ $? -eq 0 ]; then
    exit 3        # politely suspend installation
fi
 
exit 0

如果基目录仅仅是 /opt,则此方法不会非常有效。因为 /opt 难以遍历,所以此软件包必须更加准确地调用 BASEDIR。实际上,根据挂载方案的不同,可能无法实现这一点。此示例通过在 /opt 下创建一个新目录来遍历基目录,这种方法不会导致任何问题。

此示例使用了 request 脚本和 checkinstall 脚本,虽然 2.5 发行版以前的 Oracle Solaris 版本无法运行 checkinstall 脚本。此示例中的 checkinstall 脚本用于正常停止安装,以响应一个采用 quitinstall 字符串形式的专用消息。如果此脚本在 Solaris 2.3 发行版中执行,checkinstall 脚本将被忽略,而 request 脚本将停止安装并显示错误消息。

请记住,在 Solaris 2.5 和兼容发行版之前,BASEDIR 参数是一个只读参数,不能通过 request 脚本更改。因此,如果检测到 SunOS 操作系统的早期版本(通过测试 CLIENT_BASEDIR 条件环境变量),request 脚本只有两种选择-继续或退出。

使用相对参数化路径

如果您的软件产品可能安装在 SunOS 操作系统的早期版本上,则 request 脚本需要完成所有必要的工作。还可以使用此方法处理多个目录。如果需要使用额外的目录,仍然需要将这些包括在单个基目录下,以便提供易于管理的产品。尽管 BASEDIR 参数没有提供最新 Oracle Solaris 发行版中的粒度级别,您的软件包仍然可以使用 request 脚本来处理参数化路径,从而遍历基目录。pkginfopkgmap 文件可能如下所示。

pkginfo 文件
# pkginfo file
PKG=SUNWstuf
NAME=software stuff 
ARCH=sparc
VERSION=1.0.0,REV=1.0.5
CATEGORY=application
DESC=a set of utilities that do stuff
BASEDIR=/opt
SUBBASE=SUNWstuf
VENDOR=Sun Microsystems, Inc.
HOTLINE=Please contact your local service provider
EMAIL=
MAXINST=1000
CLASSES=none daemon
PSTAMP=hubert990707141632
pkgmap 文件
: 1 1758
1 d none $SUBBASE/EZstuf 0775 root bin
1 f none $SUBBASE/EZstuf/dirdel 0555 bin bin 40 773 751310229
1 f none $SUBBASE/EZstuf/usrdel 0555 bin bin 40 773 751310229
1 f none $SUBBASE/EZstuf/filedel 0555 bin bin 40 773 751310229
1 d none $SUBBASE/HRDstuf 0775 root bin
1 f none $SUBBASE/HRDstuf/mksmart 0555 bin bin 40 773 751310229
1 f none $SUBBASE/HRDstuf/mktall 0555 bin bin 40 773 751310229
1 f none $SUBBASE/HRDstuf/mkcute 0555 bin bin 40 773 751310229
1 f none $SUBBASE/HRDstuf/mkeasy 0555 bin bin 40 773 751310229
1 d none /etc    ? ? ?
1 d none /etc/rc2.d ? ? ?
1 f daemon /etc/rc2.d/S70dostuf 0744 root sys 450 223443
1 i pkginfo 348 28411 760740163
1 i postinstall 323 26475 751309908
1 i postremove 402 33179 751309945
1 i preinstall 321 26254 751310019
1 i preremove 320 26114 751309865
1 i i.daemon 509 39560 752978103
1 i r.daemon 320 24573 742152591

此示例并不完善。pkginfo -r 命令为安装基本位置返回 /opt,其含义相当模糊。许多软件包位于 /opt 中,但起码它是一个有意义的目录。就像上一个示例一样,接下来的这个示例完全支持多个体系结构和版本。request 脚本可根据特定软件包的需要进行调整,并可解析任何适用的相关性。

示例-遍历相对参数化路径的 request 脚本

# request script
for SUNWstuf to walk a parametric path
 
PATH=/usr/sadm/bin:${PATH}    # use admin utilities
 
MSG="The target directory $LOCAL_BASE already contains \
different architecture or version of $PKG. This package \
could be installed at the unused target directory $WRKNG_BASE."
 
PROMPT="Do you want to use to the proposed directory? "
 
HELP="A response of \"y\" will install to the proposed directory \
and continue, \"n\" will request a different directory. If \
the option \"-a none\" was used, press the <RETURN> key and \
enter an unused base directory when it is requested."
 
DIRPROMPT="Select a relative target directory under $BASEDIR/"
 
DIRHELP="The package $PKG will be installed at the location entered."
 
SUSPEND="Suspending installation at user request using error \
code 1."
 
NUBD_MSG="The location of this package is not the default. Be \
sure to update any applicable search paths with the actual \
location of the binaries which are at $WRKNG_BASE/EZstuf \
and $WRKNG_BASE/HRDstuf."
 
Changed=""
Suffix="0"
 
#
# Determine if this product is actually installed in the working
# base directory.
#
Product_is_present () {
      if [ -d $WRKNG_BASE/EZstuf -o -d $WRKNG_BASE/HRDstuf ]; then
            return 1
      else
            return 0
 
      fi
}
 
if [ ${BASEDIR} ]; then
      # This may be an old version of Solaris. In the latest Solaris
      # CLIENT_BASEDIR won't be defined yet. In older versions it is.
      if [ ${CLIENT_BASEDIR} ]; then
            LOCAL_BASE=$BASEDIR/$SUBBASE
      else    # The base directory hasn't been processed yet
            LOCAL_BASE=${PKG_INSTALL_ROOT}$BASEDIR/$SUBBASE
      fi
 
WRKNG_BASE=$LOCAL_BASE
 
# See if the base directory is already in place and walk it if
# possible
while [ -d ${WRKNG_BASE} -a Product_is_present ]; do
         # There is a conflict
         # Is this an update of the same arch & version?
         if [ ${UPDATE} ]; then
               exit 0    # It's out of our hands.
         else
               # So this is a different architecture or
               # version than what is already there.
               # Walk the base directory
               Suffix=`expr $Suffix + 1`
               WRKNG_BASE=$LOCAL_BASE.$Suffix
               Changed="true"
         fi
done
 
# So now we can propose a base directory that isn't claimed by
# any of our other versions.
if [ $Changed ]; then
         puttext "$MSG"
         result=`ckyorn -Q -d "a" -h "$HELP" -p "$PROMPT"`
         if [ $? -eq 3 ]; then
               puttext "$SUSPEND"
               exit 1
         fi
 
         if [ $result="n" ]; then
               WRKNG_BASE=`ckpath -lyw -d "$WRKNG_BASE" -h "$DIRHELP" \
               -p "$DIRPROMPT"`
 
            elif [ $result="a" ]; then
                   exit 0
            else
                   exit 1
            fi
            echo SUBBASE=$SUBBASE.$Suffix >> $1
            puttext "$NUBD_MSG"
      fi
fi
exit 0