首先将需要升级的文件放到一个路径下面。
然后指定升级命令,将参数指定到补丁文件的位置和配置文件。
假设升级文件经过上传,到了 /opt/package1 中,在package1中,或许是一个单一的解压后的ifix包,或许是多个zip格式的ifix压缩包。或许是若干 rpm包。也可能是zip包和rpm包的混合。
每个ifix文件是zip格式,每个zip文件的根目录下都有一个配置文件:repository.xml
而rpm包,则是linux系统上 使用 rpm –Uvh 进行安装。
其中,ifix包使用 IBM InstallationManager的指令 imcl进行安装。
一个合理的思路就是:
1.检测package1下面有无rpm文件,有则将其整理成一个list,交给 rpm –Uvh
2.检测package1下面有无 zip文件且zip中必须含有repository.xml文件
3.如果2中检测到有符合要求的zip文件,则将其解压到/opt/package2中,将ifix 路径传给 imcl.如果没有符合要求的zip文件,则检测当前目录下,有无repository.xml 有则将package1复制到opt/package2/package1中,交给imcl处理。
install sh
#! /bin/sh
ZIPPATH=/opt/zip
IFIXTOOL=/home/hailiang/script/ifixtool.sh
# List Zips
listZips() {
for file in `find $ZIPPATH -type f -name '*.zip'`;do
(unzip -t "${file}"|grep repository.xml) &> /dev/null && echo $file
done
}
# Update IM
updateIM(){
zipList=`listZips`
echo "Applying iFixs:"$zipList
${IFIXTOOL} $zipList
}
# Update RPM
{
filename=$1
echo "Apply rpm fix file(s)"
rpm -Uvh $filename
}
# Main
echo ">> start to install ifix files "
# check if there is any .rpm file under /opt/zip
rpmCount=`expr $(ls $ZIPPATH/*.rpm 2>/dev/null|wc -l)`
if [ $rpmCount -ne 0 ]; then
fixList=`ls $ZIPPATH`
echo "installing rpm(s):"$fixList
rpmList=""
for file in $ZIPPATH/*.rpm;do
rpmList=$rpmList" "$file
done
echo "Apply rpm(s):"$rpmList
rpm -Uvh $rpmList
fi
# installing ifix and ignore some times.
echo "ensure permissions are suitable for update"
chown -hR $username:users /tmp/update
echo "installing ifix"
installed=0
#Check whether there is any zip file
zipCount=`expr $(listZips|wc -l)`
if [ $zipCount -eq 0 ]; then
# Treat is as a single ifix IM repo
cd $ZIPPATH
zip -r fix,zip `find -type f -name repository.xml -exec dirname{} \;`
cd -
zipCount=1
fi
fixtotal=$zipCount
echo $fixtotal needs to be applyed .
updateIM
else
echo " nothing happened."
fi
# Remove files
rm -rf $ZIPPATH
echo "<< exit"
tool shell
#! /bin/sh
# set -x
zipfilelist=""
for zipfile;do
if [ -f "$zipfile" ];then
zipfiledir=$(cd `dirname "${zipfile}"`;pwd)
zipfilename=$(basename "${zipfile}")
zipfilelist="${zipfiledir}/${zipfilename} ${zipfilelist}"
fi
done
echo $zipfilelist
#unzip ifix
rm -rf /tmp/im
mkdir /tmp/im
cd /tmp/im
for file in ${zipfilelist};do
if [ -f "$file" ]; then
filename=$(basename "${file}")
unzip -d ${filename%.*} "$file"
fi
done