• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

[原创]如何实现Solaris安装包的反安装?

发布: 2007-6-08 22:43 | 作者: seanhe | 来源: | 查看: 26次 | 进入软件测试论坛讨论

领测软件测试网
工作中,有时需要移植一些已经安装过的Solaris包,或者对已经安装后的包进行修改,但一时又无法找到原来的安装包。系统升级时,有时也常常涉及到对原来系统的备份问题,这时需要一些能够对原来的安装包进行备份,又能够在新系统上进行安装的工具。Solaris本身并不提供直接的工具用于包的移植。

但Solaris在安装本身通用的PKG包时,会产生两个与安装包相关的文档/上录,分别在/var/sadm/pkg/<pkgname>下和/var/sadm/install/contents中,通过对这两个文档进行解析,可以实现对Solaris包的反安装,这在实现系统升级时尤其有用。

以下脚本会在当前的运行目录下产生压缩的系统安装包,Copy/Paste本脚本到Solaris机上,运行后输入需要反安装的包名即可。欢迎大家测试。

#!/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 
rm -f $PRO_DIR/Protofile 

# Now let's make the package 

$PKGMK -o -r $PRO_DIR -d $PRO_DIR -f $PRO_DIR/Prototype 
$PKGTRANS -s $PRO_DIR $PKG_DIR/$PKG_NAME-$VER-pkg $PKG_NAME 
$GZIP -f $PKG_DIR/$PKG_NAME-$VER-pkg 

rm -rf $PRO_DIR

 brucewoo 回复于:2004-03-05 11:09:38
Solaris 8
测试通过

 jackylau 回复于:2004-03-05 17:04:07
大家多发一些这样的贴子吧,我喜欢!呵呵!

 lijunv 回复于:2004-03-05 20:19:46
支持原创。

 xingshb 回复于:2004-03-05 20:45:46
虽然看不懂,但还是给鼓鼓掌!

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网