autoDeploy/ossUpgrade.sh
zhangkun9038@dingtalk.com f225bc18df rebase
2023-03-02 01:29:09 +08:00

76 lines
1.8 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
projectName="${fileName%.*}"
basePath=/tmp/autoDeploy
if [ -n $3 ]; then
basePath=$3
fi
if [ ! -d $basePath ]; then
mkdir $basePath -p
fi
function compare(){
cd $basePath
if [ ! -f ${projectName}_oss.info ]; then
touch ${projectName}_oss.info
fi
echo ossPath: oss://${ossPath}$fileName
( ossutil stat oss://${ossPath}$fileName | head -n -2) > ${projectName}_upstream_oss.info
upstreamOssInfoMd5=$(md5sum ${projectName}_upstream_oss.info)
upstreamOssInfoMd5="${upstreamOssInfoMd5% *}"
locOssInfoMd5=$(md5sum ${projectName}_oss.info)
locOssInfoMd5="${locOssInfoMd5% *}"
echo "upstream $fileName ossInfo md5: |${upstreamOssInfoMd5}|"
echo "localTep $fileName ossInfo md5: |${locOssInfoMd5}|"
echo "upstream:" $(pwd)/${projectName}_upstream_oss.info
cat ${projectName}_upstream_oss.info
echo "localTem:" $(pwd)/${projectName}_oss.info
cat ${projectName}_oss.info
if [ "${upstreamOssInfoMd5}" = "${locOssInfoMd5}" || ];then
return 0
else
return 1
fi
}
function downloadFromOss(){
cd $basePath
echo "fileName: " $fileName
ossutil cp -f oss://${ossPath}${fileName} ${fileName}_tmp
rm $fileName
mv ${fileName}_tmp $fileName
( ossutil stat oss://${ossPath}$fileName | head -n -2) > ${projectName}_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