軟件包有兩種格式,即文件系統格式和數據流格式。前者實際上就是按照一定目錄結構組織的文件集合,後者則是將這些文件打包成一個文件以方便傳輸。通常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
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 http://localhost/pkgs/cvs-bundle.pkg 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
/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