autoDeploy/ossUpgrade.sh
zhangkun9038@dingtalk.com 34886a52c6 调试那个多下载的bug+
2023-05-05 11:42:45 +08:00

84 lines
2.1 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
if [ "${upstreamOssInfoMd5}" = "${locOssInfoMd5}" ];then
return 0
else
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