工作中,有時(shí)需要移植一些已經(jīng)安裝過的Solaris包,或者對(duì)已經(jīng)安裝后的包進(jìn)行修改,但一時(shí)又無法找到原來的安裝包 。系統(tǒng)升級(jí)時(shí),有時(shí)也常常涉及到對(duì)原來系統(tǒng)的備份問題,這時(shí)需要一些能夠?qū)υ瓉淼陌惭b包進(jìn)行備份,又能夠在新系統(tǒng)上進(jìn)行安裝的工具 。Solaris本身并不提供直接的工具用于包的移植 。
但Solaris在安裝本身通用的PKG包時(shí),會(huì)產(chǎn)生兩個(gè)與安裝包相關(guān)的文檔/上錄,分別在/var/sadm/pkg/下和/var/sadm/install/contents中,通過對(duì)這兩個(gè)文檔進(jìn)行解析,可以實(shí)現(xiàn)對(duì)Solaris包的反安裝,這在實(shí)現(xiàn)系統(tǒng)升級(jí)時(shí)尤其有用 。
以下腳本會(huì)在當(dāng)前的運(yùn)行目錄下產(chǎn)生壓縮的系統(tǒng)安裝包,Copy/Paste本腳本到Solaris機(jī)上,運(yùn)行后輸入需要反安裝的包名即可 。歡迎大家測試 。
#!/bin/ksh
##########################################################
#
# Copyright (c) 2002 ChinaUnix.net -- Solaris
#
# Module Description ::
# Script to create Sun packages from existing installation
#
##########################################################
# [Global Parameters]
#===============================================
MAIN_DIR=`pwd`
PRO_DIR=$MAIN_DIR/process
PKG_DIR=$MAIN_DIR/package
SYS_DIR=/var/sadm/pkg
CNT_FILE=/var/sadm/install/contents
ID=`/usr/bin/id | awk -F= @#{print $2}@# | awk -F( @#{print $1}@#`
VER=sol`uname -r | cut -d. -f2,2`
GREP=/bin/grep
# awk can not handle long line with many fileds.
# In Solaris, use @#nawk@# or @#gawk@# instead.
AWK=/bin/nawk
GZIP=/bin/gzip
MKDIR=/bin/mkdir
CHMOD=/bin/chmod
CHOWN=/bin/chown
CP=/bin/cp
MV=/bin/mv
PKGMK=/bin/pkgmk
PKGTRANS=/bin/pkgtrans
# [Functions]
#==================================================================
function mk_dir
{
$MKDIR -p $PRO_DIR/$3
$CHMOD $4 $PRO_DIR/$3
$CHOWN $5:$6 $PRO_DIR/$3
}
function cp_file
{
$CP -p $3 $PRO_DIR/$3
$CHMOD $4 $PRO_DIR/$3
$CHOWN $5:$6 $PRO_DIR/$3
}
# [Main]
#==================================================================
if [ ${ID} != 0 ]
then
echo ""
echo "Only Root User allow to run this script. Exit...."
sleep 1
echo ""
exit 1
fi
echo ""
echo "Please enter package name you want to create, then press Enter: "
echo "Enter Package name: c"
read pkgname
PKG_NAME=$pkgname
if [ ! -d $SYS_DIR/$PKG_NAME ]; then
echo ""
echo "This Package doesn@#t exist!!! Please check the name and try again!"
echo ""
exit 1
fi
if [ ! -d $PRO_DIR ]; then
$MKDIR $PRO_DIR
fi
if [ ! -d $PKG_DIR ]; then
$MKDIR $PKG_DIR
fi
# Producing part of Prototype file
$GREP $PKG_NAME $CNT_FILE | $GREP -v ^#.* > $PRO_DIR/cnt_pkg
$AWK @#{print $2,$3,$1,$4,$5,$6}@# $PRO_DIR/cnt_pkg > $PRO_DIR/Prototmp
$GREP ^d $PRO_DIR/Prototmp > $PRO_DIR/Protodir
$GREP ^f $PRO_DIR/Prototmp >> $PRO_DIR/Protofile
rm -f $PRO_DIR/Prototmp
rm -f $PRO_DIR/cnt_pkg
# Producing pkginfo file
cp $SYS_DIR/$PKG_NAME/pkginfo $PRO_DIR
# Making Directory with permission
i=0
while IFS=@# @# read line
do
t[$i]=$line
((i=i 1))
mk_dir $line
done < $PRO_DIR/Protodir
# Copying file to Spool directory
i=0
while IFS=@# @# read line
do
t[$i]=$line
((i=i 1))
cp_file $line
done < $PRO_DIR/Protofile
# Producing Prototype file
cat $PRO_DIR/Protodir > $PRO_DIR/Prototype
cat $PRO_DIR/Protofile >> $PRO_DIR/Prototype
(echo "i pkginfo"cat $PRO_DIR/Prototype ) > $PRO_DIR/Prototmp
mv $PRO_DIR/Prototmp $PRO_DIR/Prototype
rm -f $PRO_DIR/Protodir
推薦閱讀
- Solaris 8 共享 W2K 網(wǎng)絡(luò)打印服務(wù)
- Sun Solaris 不同規(guī)格的硬盤用Disksuite做鏡像的實(shí)現(xiàn)
- Sun Solaris 上建立帶用戶認(rèn)證功能的SQUID代理服務(wù)器
- 基本Solaris安全配置一
- 基本Solaris安全配置二
- Solaris 的掛盤經(jīng)歷
- 酷開電視怎么看電視臺(tái)
- 在Solaris上安裝帶顏色分辨的 ls
- Solaris 的系統(tǒng)幫助
- Sun Solaris 上殺掉連接已經(jīng)超時(shí)的進(jìn)程腳本
