autoDeploy/ossUpgrade.sh
2025-02-25 21:52:14 +08:00

86 lines
2.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#usage:
# ./ossUpgrade.sh "stage/ztsjxxxt/frontEnd/" html.zip ztsjxxxt
# set -xt
PATH=PATH:/usr/bin:/usr/sbin:/usr/local/bin
ossPath=$1 #末尾别忘了加/
fileName=$2
preName="${fileName%.*}"
protol=oss
basePath=$3
if [ ! -d $basePath ]; then
mkdir $basePath -p
fi
function compare(){
if [ ! -d $basePath ]; then
mkdir $basePath
fi
cd $basePath
if [ ! -f ${fileName}_oss.info ]; then
touch ${fileName}_oss.info
fi
echo upstream ossPath: ${protol}://${ossPath}$fileName
( ossutil stat ${protol}://${ossPath}$fileName | head -n -2) > ${fileName}_upstream_oss.info
upstreamOssInfoMd5=$(md5sum ${fileName}_upstream_oss.info)
upstreamOssInfoMd5="${upstreamOssInfoMd5% *}"
locOssInfoMd5=$(md5sum ${fileName}_oss.info)
locOssInfoMd5="${locOssInfoMd5% *}"
echo "upstream $fileName ossInfo md5: |${upstreamOssInfoMd5}|"
echo "localTep $fileName ossInfo md5: |${locOssInfoMd5}|"
echo "upstream:" $(pwd)/${fileName}_upstream_oss.info
cat ${fileName}_upstream_oss.info
echo "localTem:" $(pwd)/${fileName}_oss.info
cat ${fileName}_oss.info
# 当上游oss文件meta信息跟下游缓存文件meta信息匹配时, 无需更新
if [ "${upstreamOssInfoMd5}" = "${locOssInfoMd5}" ];then
return 0
else
# 当上游oss文件meta信息跟下游缓存文件meta信息不符时如果上游信息是空下游非空则忽略更新因为有可能是误判
if [ "${upstreamOssInfoMd5}" = "d41d8cd98f00b204e9800998ecf8427e" ] && [ "${locOssInfoMd5}" != "d41d8cd98f00b204e9800998ecf8427e" ];then
echo "maybe a mistake, ignore upgrade"
return 0
else
return 1
fi
fi
}
function downloadFromOss(){
cd $basePath
echo "fileName: " $fileName
ossutil cp -f ${protol}://${ossPath}${fileName} ${fileName}_tmp
rm $fileName
mv ${fileName}_tmp $fileName
( ossutil stat ${protol}://${ossPath}$fileName | head -n -2) > ${fileName}_oss.info
}
function main(){
echo " "
echo "start ossUpgrade service"
compare
result=$?
if [ $result = 0 ];then
# uploadLog
echo "local temp file $fileName is same with oss fileno need to replace"
echo "end ossUpgrade service"
echo " "
exit 0
else
echo "local temp file $fileName is different from oss, will download..."
fi
downloadFromOss
echo "end ossUpgrade service"
echo " "
}
main