首先將需要升級的文件放到一個路徑下面。
然后指定升級命令,將參數指定到補丁文件的位置和配置文件。
假設升級文件經過上傳,到了 /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