Solaris下发布软件包最多的公司应该是Sun公司,它的纳斯达克上市股票代号为SUNW,所以我们常常可以看到以SUNW前缀软件包,如SUNWman, SUNWcsr。而随着开方源代码和自由软件的兴起,为了方便Solaris用户安装使用开源软件,一个非营利的网站提供了一些著名的开源软件的Solaris软件包,这些软件包名都以SMC为前缀。
软件包有两种格式,即文件系统格式和数据流格式。前者实际上就是按照一定目录结构组织的文件集合,后者则是将这些文件打包成一个文件以方便传输。通常Solaris软件包在光盘介质中以文件系统格式发布,而在因特网上以数据流格式发布。文件系统格式的软件包通常用软件包名作为顶层目录名,该目录中至少有pkginfo和pkgmap两个文件,这两个文件描述软件包的元信息。例如在Solaris10的光盘中的Solaris_10/Product目录下存放许多以文件系统格式发布软件包,查看其中的SUNWcsr软件包;
-bash-3.00# cd /cdrom/cdrom0/Solaris_10/Product/
-bash-3.00# ls -ld SUNWcsr
dr-xr-xr-x 5 root root 2048 Dec 7 23:58 SUNWcsr
-bash-3.00# cd SUNWcsr
-bash-3.00# ls -l
total 78
dr-xr-xr-x 2 root root 2048 Dec 7 23:58 archive
dr-xr-xr-x 2 root root 6144 Dec 7 23:58 install
-r--r--r-- 1 root root 3342 Dec 7 23:24 pkginfo
-r--r--r-- 1 root root 26025 Dec 7 23:24 pkgmap
dr-xr-xr-x 6 root root 2048 Dec 7 23:58 reloc
文件系统格式和数据流格式可以互相转换。/var/sadm/install/contents文件中记录了所有软件包的所有文件的安装的位置、属主、权限等信息。该文件是Solaris系统的已安装软件包信息库。
-bash-3.00# more /var/sadm/install/contents
......
/usr/bin/newform f none 0555 root bin 16308 54888 1106448826 SUNWesu
/usr/bin/newgrp f none 4755 root sys 10324 56620 1106447294 SUNWcsu
/usr/bin/news f none 0555 root bin 10128 27837 1106448826 SUNWesu
/usr/bin/newsp=./mailp s none SUNWmp
/usr/bin/newtask=../../usr/lib/isaexec l none SUNWcsu
/usr/bin/nfsstat f none 0555 root bin 23936 33443 1106444303 SUNWnfscu
/usr/bin/nice f none 0555 root bin 5768 49667 1106447294 SUNWcsu
/usr/bin/nisaddcred f none 0555 root bin 31224 40868 1106444342 SUNWnisu
/usr/bin/niscat f none 0555 root bin 9964 29056 1106444342 SUNWnisu
/usr/bin/nischgrp f none 0555 root bin 14248 41511 1106444342 SUNWnisu
/usr/bin/nischmod=../../usr/bin/nischgrp l none SUNWnisu
/usr/bin/nischown=../../usr/bin/nischgrp l none SUNWnisu
......
可见如果知道具体文件位置可以用查到该文件所属的软件包名称。
以下命令找出ifconfig命令所属软件包为SUNWcsr:
-bash-3.00# grep bin/ifconfig /var/sadm/install/contents
/sbin/ifconfig f none 0555 root bin 63956 59090 1132684929 SUNWcsr
/usr/sbin/ifconfig=../../sbin/ifconfig s none SUNWcsu
Solaris下有6个用于软件包管理的命令行工具:
pkgadd -- 用于安装或缓存(spool)软件包
pkgrm -- 用于删除软件包或清除软件包缓存(spool)
pkginfo -- 用于获取软件包信息
pkgchk -- 用于检查软件包中文件的完整性
pkgtrans -- 用于软件包格式转换
pkgask -- 用于录制含有交互式脚本软件包安装时需要的用户输入
除了pkgask、pkgrm外,这些命令都接受软件包名作为可选的最后一个参数,如果不指定命令会提示用户输入,也可以用all代表所有。指定软件包的位置用-d选项,对于文件系统格式软件包只要指定到包含该软件包的目录即可,对于数据流格式的软件包需要指定到文件名称。
软件包管理的常见任务
软件包管理的常见任务有:获得软件包信息、安装软件包、删除软件包、软件包格式转换、缓存软件包等。以下以实例分别介绍每个任务的操作步骤。
获得软件包信息
获得软件包信息的命令主要是pkginfo。pkgchk -v则可以用来获得软件包中的文件列表。如果要查看未安的装软件包的信息,需要用-d选项指定软件包所在的位置。查看系统上安装的软件包则不需要使用-d选项。
pkginfo命令不带任何参数显示当前系统安装的所有软件包的概要信息,包括分类、名称、描述。
-bash-3.00# pkginfo |more
system CADP160 Adaptec Ultra160 SCSI Host Adapter Driver
system HPFC Agilent Fibre Channel HBA Driver
ALE SUNW5xmft Traditional Chinese (BIG5) X Windows Platform minimum required Fonts Package
system SUNWGlib GLIB - Library of useful routines for C programming
system SUNWGtkr GTK - The GIMP Toolkit (Root)
system SUNWGtku GTK - The GIMP Toolkit (Usr)
GNOME2 SUNWPython The Python interpreter, libraries and utilities
system SUNWTk Tk - TCL GUI Toolkit
system SUNWa2psr a2ps - GNU Any to PostScript filter (root)
system SUNWa2psu a2ps - GNU Any to PostScript filter (user)
system SUNWaac Adaptec AdvanceRaid Controller SCSI HBA Driver
system SUNWad810 SUNW W1100z & W2100z Audio Drivers
system SUNWadmap System administration applications
system SUNWadmc System administration core libraries
system SUNWadmfr System & Network Administration Framework Configuration
system SUNWadmfw System & Network Administration Framework
system SUNWadmj Admin/Install Java Extension Libraries
system SUNWadmlib-sysid System and Network identification libraries
system SUNWadmr System & Network Administration Root
system SUNWadp Adaptec 29xx/39/xx/78xx Family of SCSI HBA
system SUNWadpu320 Adaptec Ultra320 Driver
......
pkginfo -l则列出软件包的详细信息:
-bash-3.00# pkginfo -d . -l SMCapch22
PKGINST: SMCapch22
NAME: apache
CATEGORY: application
ARCH: sparc
VERSION: 2.2.0
BASEDIR: /usr/local/apache2
VENDOR: The Apache Group
PSTAMP: Steve Christensen
EMAIL:
STATUS: spooled
FILES: 2198 spooled pathnames
66 directories
72 executables
2 package information files
44173 blocks used (approx)
pkgchk命令用来检查软件包是否安装、软件包中的文件是否有所改动等信息。如果软件包成功安装并且没有任何文件改动过,该命令无任何输出,否则在标准错误上输出相关的信息。pkgchk不带任何参数则检查当前系统安装的所有软件包,并列出检查结果的概要信息,如果要详细信息可以用-l选项。如果要限定某个具体软件包,最后一个参数写上该软件包名称即可。如果只要检查某个软件包的某个文件可以用-p选项加上该文件的完全路径即可,如果不知道完全路径可以使用-P选项加文件的部分路径。例如:
-bash-3.00# pkgchk -p /etc/shadow
ERROR: /etc/shadow
modtime <01/22/05 07:46:05 AM> expected <02/13/06 01:36:36 PM> actual
file size <296> expected <373> actual
file cksum <20180> expected <26166> actual
检查/etc/shadow自安装以来是否发生变化。有输出说明有变化,没有输出则表示没有变化。
-bash-3.00# pkgchk -l -p /usr/bin/showrev
Pathname: /usr/bin/showrev
Type: regular file
Expected mode: 0755
Expected owner: root
Expected group: sys
Expected file size (bytes): 28148
Expected sum(1) of contents: 7605
Expected last modification: Jan 23 09:40:57 2005
Referenced by the following packages:
SUNWadmc
Current status: installed
列出/usr/bin/showrev文件在软件包中的属主、权限、所属软件包名称等信息。
-bash-3.00# pkgchk -l -P showrev
Pathname: /usr/bin/showrev
Type: regular file
Expected mode: 0755
Expected owner: root
Expected group: sys
Expected file size (bytes): 28148
Expected sum(1) of contents: 7605
Expected last modification: Jan 23 09:40:57 2005
Referenced by the following packages:
SUNWadmc
Current status: installed
Pathname: /usr/share/man/man1m/showrev.1m
Type: regular file
Expected mode: 0644
Expected owner: root
Expected group: root
Expected file size (bytes): 3744
Expected sum(1) of contents: 56811
Expected last modification: Oct 22 08:51:42 2005
Referenced by the following packages:
SUNWman
Current status: installed
列出含有showrev文件的软件包中该文件的相关信息。可见如果知道某个文件的完全路径名或部分路径名可以通过pkgchk -lp或pkgchk -lP命令查找出该文件所属的软件包。
pkgchk -v pkg_name用来列出指名称的软件包所包含的文件。下面的命令用分页显示列出软件包SMCapch22中所包含的文件列表:
-bash-3.00# ls -l
total 3002
-rw-r--r-- 1 root root 75782 Feb 25 20:56 1
drwxr-xr-x 3 root root 512 Feb 25 18:09 SMCapch22
drwxr-xr-x 5 root root 512 Feb 25 17:15 SUNWcsr
-rw-r--r-- 1 root root 1216512 Feb 25 17:09 SUNWcsr.pkg
-rw-r--r-- 1 root root 220672 Feb 25 17:59 zone.pkg
-bash-3.00# pkgchk -d . -v SMCapch22 2>&1 | more
bin/ab
bin/apachectl
bin/apxs
bin/checkgid
bin/dbmmanage
bin/envvars
bin/envvars-std
bin/htcacheclean
bin/htdbm
bin/htdigest
bin/htpasswd
bin/httpd
bin/httxt2dbm
bin/logresolve
bin/rotatelogs
build/config.nice
build/config_vars.mk
build/instdso.sh
build/library.mk
build/ltlib.mk
build/mkdir.sh
build/program.mk
--More--
要注意的是pkgchk命令只往标准错误输出文件列表,所以使用管道时需要重定向到标准输出。
安装软件包
安装软件包用pkgadd命令,该命令可以安装文件系统各式的软件包:
-bash-3.00# cd /cdrom/cdrom0/Solaris_10/ExtraValue/CoBundled/SunVTS_6.1/Packages
-bash-3.00# pkgadd -d . SUNWvts
Processing package instance from raValue/CoBundled/SunVTS_6.1/Packages>
SunVTS Framework(i386) 6.1,REV=2005.11.10.13.29
Copyright 2004 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
## Executing checkinstall script.
Using as the package base directory.
## Processing package information.
## Processing system information.
## Verifying package dependencies.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.
This package contains scripts which will be executed with super-user
permission during the process of installing this package.
Do you want to continue with the installation of [y,n,?] y
Installing SunVTS Framework as
## Installing part 1 of 1.
5254 blocks
Installation of was successful.
也可以安装数据流格式的本地软件包:
-bash-3.00# pkgadd -d cvs-bundle.pkg all
Processing package instance from
cvs(x86) 1.11.20
FSF
The selected base directory must exist before
installation is attempted.
Do you want this directory created now [y,n,?,q] y
Using as the package base directory.
## Processing package information.
## Processing system information.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.
Installing cvs as
## Installing part 1 of 1.
/usr/local/bin/cvs
/usr/local/bin/cvsbug
/usr/local/bin/rcs2log
......
/usr/local/man/man1/cvs.1
/usr/local/man/man5/cvs.5
/usr/local/man/man8/cvsbug.8
[ verifying class ]
Installation of was successful.
Processing package instance from
gzip(intel) 1.3.5
Free Software Foundation
Using as the package base directory.
## Processing package information.
## Processing system information.
5 package pathnames are already properly installed.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.
Installing gzip as
## Installing part 1 of 1.
/usr/local/bin/gzexe
/usr/local/bin/gzip
/usr/local/man/man1/gzip.1
......
[ verifying class ]
/usr/local/bin/gunzip
/usr/local/bin/zcat
/usr/local/bin/zcmp
/usr/local/bin/zegrep
/usr/local/bin/zfgrep
Installation of was successful.
最新版的pkgadd命令还支持http方式安装远程的数据流格式软件包:
-bash-3.00# pkgadd -d all
## Downloading...
..............25%..............50%..............75%..............100%
## Download Complete
Processing package instance from <>
cvs(x86) 1.11.20
FSF
Using as the package base directory.
## Processing package information.
## Processing system information.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.
Installing cvs as
## Installing part 1 of 1.
/usr/local/bin/cvs
/usr/local/bin/cvsbug
......
[ verifying class ]
Installation of was successful.
Processing package instance from <>
gzip(intel) 1.3.5
Free Software Foundation
Using as the package base directory.
## Processing package information.
## Processing system information.
5 package pathnames are already properly installed.
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.
Installing gzip as
## Installing part 1 of 1.
/usr/local/bin/gzexe
/usr/local/bin/gzip
......
Installation of was successful.
要注意的是有些软件包有它所依赖的其它软件包,如果这些依赖没有安装,那么pkgadd将会报错。遇到这种情形应当首先安装依赖的软件包。此外,如果需要无人值守的情况下安装那些需要用户输入的软件包时,可以事先使用pkgask将设置记录到一个文件中,然后使用pkgadd的-r选项告诉pkgadd命令使用该文件的的用户输入。
删除软件包
删除软件包用pkgrm命令:
-bash-3.00# pkgrm SMCgzip
The following package is currently installed:
SMCgzip gzip
(intel) 1.3.5
Do you want to remove this package? [y,n,?,q] y
## Removing installed package instance
## Verifying package dependencies in global zone
## Processing package information.
## Removing pathnames in class
/usr/local/man/man1
/usr/local/man
/usr/local/info/gzip.info
/usr/local/info
/usr/local/doc
/usr/local/bin/zcat
/usr/local/bin/gzip
/usr/local/bin/gzexe
/usr/local/bin/gunzip
/usr/local/bin
## Updating system information.
Removal of was successful.
如果试图删除被其它软件包依赖的软件包,pkgrm命令会提出警告,并让用户选择是否继续,如果继续软件包会被强制删除。如:
-bash-3.00# pkgrm SUNWapchr
The following package is currently installed:
SUNWapchr Apache Web Server (root)
(i386) 11.10.0,REV=2005.01.08.01.09
Do you want to remove this package? [y,n,?,q] y
## Removing installed package instance
## Verifying package dependencies in global zone
WARNING:
The package depends on the package
currently being removed.
WARNING:
The package depends on the package
currently being removed.
WARNING:
The package depends on the package
currently being removed.
Dependency checking failed.
Do you want to continue with the removal of this package [y,n,?,q]
缓存软件包
缓存软件包即把常用的软件从光盘等其它介质拷贝到/var/spool/pkg目录下,使得安装更为方便快捷。缓存软件包用pkgadd命令的-s spool选项。比如把上述cvs-bundle.pkg缓存到/var/spool/pkg目录下可以使用以下命令:
-bash-3.00# pkgadd -d cvs-bundle.pkg -s spool all
Transferring package instance
Transferring package instance
-bash-3.00# ls -l /var/spool/pkg
total 4
drwxr-xr-x 3 root root 512 Feb 26 01:03 SMCcvs
drwxr-xr-x 3 root root 512 Feb 26 01:03 SMCgzip
删除缓存的软件包用pkgrm -s spool pkg_name,例如:
-bash-3.00# pkgrm -s spool SMCcvs
The following package is currently spooled:
SMCcvs cvs
(x86) 1.11.20
Do you want to remove this package? [y,n,?,q] y
Removing spooled package instance
-bash-3.00# ls -l /var/spool/pkg/
total 2
drwxr-xr-x 3 root root 512 Feb 26 01:03 SMCgzip
安装已经缓存了的软件包只需运行pkgadd pkg_name即可。
-bash-3.00# pkgadd SMCgzip
Processing package instance from
gzip(intel) 1.3.5
......
软件包格式转换
pkgtrans命令是软件包格式转换工具,它的用法是:
pkgtrans file_or_dir_path file_or_dir_path [package_name ...]
如果是将文件系统格式转换成数据流格式,第一个参数指定软件包所在的目录,第二个参数指定转换后数据流格式软件包存放文件名;如果是将数据流格式转换成文件系统格式,第一个参数指定数据流格式软件包文件名,第二个参数指定转换后文件系统格式软件包存放目录。如果不指定要转换的软件包名称,pkgtrans将会根据第一个参数中可选的软件包提示用户输入要转换的软件包名称。
以下命令将Solaris10安装光盘中的SUNWzoner和SUNWzoneu转换成数据流格式的软件包:
-bash-3.00# cd /cdrom/cdrom0/Solaris_10/Product/
-bash-3.00# pkgtrans . /export/home/justin/pkg/zone.pkg SUNWzoner SUNWzoneu
Transferring package instance
Transferring package instance
-bash-3.00# file zone.pkg
zone.pkg: package datastream
-bash-3.00# head /export/home/justin/pkg/zone.pkg
# PaCkAgE DaTaStReAm
SUNWzoner 1 50
SUNWzoneu 1 450
# end of header
BASEDIR=/
CATEGORY=system
DESC=Solaris Zones Configuration Files
EMAIL=
HOTLINE=Please contact your local service provider
MAXINST=1000
以下命令将数据流格式的Apache2.2软件包转换成文件系统格式:
-bash-3.00# pkgtrans apache-2.2.0-sol10-x86-local . SMCapch22
Transferring package instance
-bash-3.00# ls -ld SMCapch22
drwxr-xr-x 3 root root 512 Feb 25 18:09 SMCapch22
-bash-3.00# ls -l SMCapch22/
total 356
-rw-r--r-- 1 10 staff 186 Jan 1 16:39 pkginfo
-rw-r--r-- 1 10 staff 171631 Jan 1 16:39 pkgmap
drwxr-xr-x 14 10 staff 512 Feb 25 18:09 reloc
阅读(1892) | 评论(0) | 转发(0) |