autoDeploy/ossUpgrade.sh
zhangkun9038@dingtalk.com 66b020b005 checkService
2022-09-08 14:23:26 +00:00

47 lines
1.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
ossPath=$1 #末尾别忘了加/
fileName=$2
projectName="${fileName%.*}"
PATH=PATH:/usr/bin:/usr/sbin
cd ~
./ossutil stat oss://ztupload/${ossPath}$fileName > ${projectName}_oss.info
ossInfo=$(cat ${projectName}_oss.info)
out=${ossInfo##*Etag}
out=${out%Last*}
out=${out#*: }
ossSum=${out,,}
ossSum="${ossSum% *}"
echo "oss md5:"$ossSum
result=$(echo $ossInfo | grep "error")
if [[ "$result" != "" ]]; then
echo $result
exit 0
fi
curSum=$(md5sum $fileName)
curSum="${curSum% *}"
if [ "${curSum}" = "" ];then
./ossutil cp oss://ztupload/${ossPath}$fileName > ${fileName}
curSum=$(md5sum $fileName)
curSum="${curSum% *}"
fi
echo "local file $fileName md5:"$curSum
all=$ossSum
echo "oriMd5: "$all
all=$curSum
echo "curMd5: "$all
if [ ${ossSum} = ${curSum} ];then
echo "destination file is same with oss fileno need to replace"
exit 0
else
echo "local file $fileName is different from oss, will download..."
fi
rm $fileName
echo "fileName: " $fileName
./ossutil cp oss://ztupload/${ossPath}${fileName} ${fileName}
echo "replaced"