创建solaris package step by step

原文地址:http://www.ibiblio.org/pub/packages/solaris/sparc/html/creating.solaris.packages.html

介绍:
solaris 软件包可以使软件很容易的安装到solaris系统中。软件的所有部分都被一个目录文件描述。借助包管理工具您可以在solaris系统中很方便得安装,更新,删除软件,而不用担心“恶意文件”存留,或者错误的配置,或者软件的未完全安装。
软件包的创建过程大体上是安装一次软件,然后把软件组织成一个软件安装包,这个软件安装包可以被快速的安装到其他solaris系统,同时可以很容易的在本机卸载。
本文档将使用GNU bison 1.24 作为示例程序。

软件包的创建:
创建软件包,首先要知道软件包包含那些文件。如果您是软件作者,通常这个很简单,否这您就需要先把软件安装到一个独立的目录中,来查看到底那些文件将被包含到软件包中。GNU 软件很容易做到这一点,只需要通过命令`configure --prefix=/dir`,这个dir就是我们临时安装软件的目录,例如我们可以制定软件目录为/usr/local/pkg.
编译后使用`make install`命令来把软件安装到我们指定的目录中(/usr/local/pkg)。通过命令`find /usr/local/pkg -print > /tmp/files`来得到该软件包需要哪些文件,现在我们已经知道我们都需要哪些文件了。

创建软件包配置文件
软件安装完成后,你需要创建一个目录文件提供给软件包创建工具使用。首先需要清理/tmp/files里的文件路径(/usr/local/pkg还在那),编辑文件,并修复文件路径错误,在运行:
%cat /tmp/files | pkgproto > /tmp/Prototype
这将创建文件/tmp/Prototype,内容如下
[code]
d none /usr/local 0755 root root
d none /usr/local/bin 0755 root root
d none /usr/local/man 0755 root root
d none /usr/local/man/man1 0755 root root
d none /usr/local/lib 0755 root root
d none /usr/local/etc 0755 root root
d none /usr/local/info 0755 root root
d none /usr/local/share 0755 root root
f none /usr/local/bin/bison 0755 root root
f none /usr/local/man/man1/bison.1 0644 root root
f none /usr/local/info/bison.info 0644 root root
f none /usr/local/info/bison.info-1 0644 root root
f none /usr/local/info/bison.info-2 0644 root root
f none /usr/local/info/bison.info-3 0644 root root
f none /usr/local/info/bison.info-4 0644 root root
f none /usr/local/info/bison.info-5 0644 root root
f none /usr/local/share/bison.simple 0644 root root
f none /usr/local/share/bison.hairy 0644 root root
[/code]
检查文件/tmp/Prototype你可能会发现某些权限不是我想要的,我们可以手工编辑每一个文件的权限。
现在你必须在/tmp/Prototype文件中添加指向pkginfo的语句,pkginfo文件将描述pkgmk命令我们要创建的软件包的细节。
在Prototype文件的前端添加一行
i pkginfo
如果你向包含checkinstall, preinstall和postinstall脚本,仅仅需要在Prototype文件头加上就可以。
checkinstall是一个在安装是被运行的的文件,运行的用户是"nobody",通过这个脚本,你可以检查依赖,处理问题,很自然得退出pkgadd程序,唯一需要注意的是当构建软件包时,要保证用户"nobody"有权限读取这个脚本。pkgadd程序不会询问你是否执行checkinstall脚本。
preinstall是在软包正真安装时执行的脚本,运行的用户是"root",在这里产生中断会要求用户使用pkgrm来删除半安装的软件包,pkgadd程序会询问你是否执行preinstall脚本
postinstall是一个软件包安装完成后执行的脚本,运行的用户是"root",通过这个脚本,你可以为刚刚安装的软件做一些额外的事情,例如安装内核驱动,创建设备或者其他后安装过程,pkgadd程序会询问你是否执行preinstall脚本。
添加一下文字到Prototype
[code]
i preinstall
i postinstall
i checkinstall
[/code]
这些脚本会在软件安装开始后执行,如果出错,这些脚本要以非0退出,会要求pkgrm来清理这些半安装的软件。
最后,我们的Prototype文件如下所示:
[code]
i pkginfo
d none /usr/local/bin 0755 root root
d none /usr/local/man 0755 root root
d none /usr/local/man/man1 0755 root root
d none /usr/local/lib 0755 root root
d none /usr/local/etc 0755 root root
d none /usr/local/info 0755 root root
d none /usr/local/share 0755 root root
f none /usr/local/bin/bison 0755 root root
f none /usr/local/man/man1/bison.1 0644 root root
f none /usr/local/info/bison.info 0644 root root
f none /usr/local/info/bison.info-1 0644 root root
f none /usr/local/info/bison.info-2 0644 root root
f none /usr/local/info/bison.info-3 0644 root root
f none /usr/local/info/bison.info-4 0644 root root
f none /usr/local/info/bison.info-5 0644 root root
f none /usr/local/share/bison.simple 0644 root root
f none /usr/local/share/bison.hairy 0644 root root
[/code]
可以查看prototype的帮助文件来获取更多的信息
下一步,我们需要创建pkginfo文件,来告诉pkgmk命令需要调用哪些文件。下边是我们创建的pkginfo文件内容
[code]
PKG="GNUbison"
NAME="GNU bison 1.24"
VERSION="1.24"
ARCH="sparc"
CLASSES="none"
CATEGORY="utility"
VENDOR="GNU"
PSTAMP="4thSep95"
EMAIL="request@gnu.ai.mit.edu"
ISTATES="S s 1 2 3"
RSTATES="S s 1 2 3"
BASEDIR="/"
[/code]
创建软件包
软件包配置文件创建后,你就可以在包含软件配置文件的目录(/tmp)来运行软件包创建命令来创建软件包了。
pkgmk -o -r / -d /tmp -f Prototype
这个命令表示创建软件包,覆盖所有以前的尝试,使用'/'作为根目录来查找文件,在/tmp目录构建软件包,从Prototype文件里来读取构建软件包的配置。
命令的输出是
## Processing pkginfo file.
## Attempting to volumize 19 entries in pkgmap.
part 1 -- 990 blocks, 21 entries
## Packaging one part.
/tmp/GNUbison/pkgmap
/tmp/GNUbison/pkginfo
/tmp/GNUbison/root/usr/local/bin/bison
/tmp/GNUbison/root/usr/local/info/bison.info
/tmp/GNUbison/root/usr/local/info/bison.info-1
/tmp/GNUbison/root/usr/local/info/bison.info-2
/tmp/GNUbison/root/usr/local/info/bison.info-3
/tmp/GNUbison/root/usr/local/info/bison.info-4
/tmp/GNUbison/root/usr/local/info/bison.info-5
/tmp/GNUbison/root/usr/local/man/man1/bison.1
/tmp/GNUbison/root/usr/local/share/bison.hairy
/tmp/GNUbison/root/usr/local/share/bison.simple
## Packaging complete.
这将在/tmp下建立目录GNUbison.在GNUbison目录中包含两个文件 pkgmap和pkginfo.pkgmap包含了所有文件的路径,权限,还有每个文件的校验和。pkginfo的内容跟你刚才在/tmp目录下创建的pkginfo文件内容相同,在GNUbison目录中包含一个目录名为"root",这里面包含了将要被安装的软件的文件,如果你包含了checkinstall(preinstall,postinstall)脚本,他们将出现在文件夹install中,你不用担心在最顶层目录中包含了那些文件,除非你需要修复一些bug.
为了存储,传输方便,我们需要创建一个.tar.gz的压缩包
cd /tmp
tar czvf GNUbison.1.25.SPARC.pkg.tar.gz GNUbison

解压并安装软件包
tar zxvf GNUbison.1.25.SPARC.pkg.tar.gz
su -
pkgadd -d $PWD
你将被提示是否安装GNUbison软件包,确认并安装。

有用的文件
[code]
pkginfo

PKG="GNUbison"
NAME="GNU bison 1.24 SPARC Solaris 2.6"
VERSION="1.24"
ARCH="sparc"
CLASSES="none"
CATEGORY="utility"
VENDOR="GNU"
PSTAMP="12thAugust2004"
EMAIL="request@gnu.ai.mit.edu"
ISTATES="S s 1 2 3"
RSTATES="S s 1 2 3"
BASEDIR="/"


Prototype

i pkginfo
i checkinstall
d none /usr/local/bin 0755 root root
d none /usr/local/man 0755 root root
d none /usr/local/man/man1 0755 root root
d none /usr/local/lib 0755 root root
d none /usr/local/etc 0755 root root
d none /usr/local/info 0755 root root
d none /usr/local/share 0755 root root
f none /usr/local/bin/bison 0755 root root
f none /usr/local/man/man1/bison.1 0644 root root
f none /usr/local/info/bison.info 0644 root root
f none /usr/local/info/bison.info-1 0644 root root
f none /usr/local/info/bison.info-2 0644 root root
f none /usr/local/info/bison.info-3 0644 root root
f none /usr/local/info/bison.info-4 0644 root root
f none /usr/local/info/bison.info-5 0644 root root
f none /usr/local/share/bison.simple 0644 root root
f none /usr/local/share/bison.hairy 0644 root root


mkpkg

#!/bin/sh
pkg=GNUbison
pkgfile=GNUbison.1.24.SPARC.Solaris.2.6.pkg.tgz
pkgmk -o -r / -d /tmp -f Prototype
echo "Setting file permissions in /tmp/${pkg} tree to 644."
find /tmp/${pkg} -type f -print | xargs chmod a+r
find /tmp/${pkg} -type f -print | xargs chmod u+w
echo "Setting directory permissions in /tmp/${pkg} tree to 755."
find /tmp/${pkg} -type d -print | xargs chmod 755
if [ -f /tmp/${pkg}/install/preinstall ]; then
chmod 755 /tmp/${pkg}/install/preinstall
fi
if [ -f /tmp/${pkg}/install/postinstall ]; then
chmod 755 /tmp/${pkg}/install/postinstall
fi
if [ -f /tmp/${pkg}/install/preremove ]; then
chmod 755 /tmp/${pkg}/install/preremove
fi
if [ -f /tmp/${pkg}/install/postremove ]; then
chmod 755 /tmp/${pkg}/install/postremove
fi
if [ -f /tmp/${pkg}/install/request ]; then
chmod 755 /tmp/${pkg}/install/request
fi
if [ -f /tmp/${pkg}/install/checkinstall ]; then
chmod 755 /tmp/${pkg}/install/checkinstall
fi
cd /tmp
echo Gzipping /tmp/$pkg into /tmp/$pkgfile...
/usr/bin/tar -cf - $pkg | gzip -9c > /tmp/$pkgfile


checkinstall

#!/bin/sh
#
# expected_release="5.6"
expected_platform="sparc"
#
release=`uname -r`
platform=`uname -p`
#
if [ ${platform} != ${expected_platform} ]; then
echo "\n\n\n\tThis package must be installed on a ${expected_platform} architecture\n"
echo "\tAborting installation.\n\n\n"
exit 1
fi
# if [ ${release} != ${expected_release} ]; then
# echo "\n\n\n\tThis package must be installed on a ${expected_release} machine\n"
# echo "\tAborting installation.\n\n\n"
# exit 1
# fi

exit 0
[/code]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值