autoDeploy/ossUpgrade.sh
zhangkun9038@dingtalk.com 14d4970e82 update
2022-09-10 10:46:04 +00:00

94 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
PATH=PATH:/usr/bin:/usr/sbin
ossPath=$1 #末尾别忘了加/
fileName=$2
serviceName=$3
projectName="${fileName%.*}"
function compare(){
cd ~
./ossutil stat oss://ztupload/${ossPath}$fileName > ${projectName}_oss.info
ossInfo=$(cat ${projectName}_oss.info)
echo "${fileName} in oss info: "
echo " " $ossInfo
out=${ossInfo##*Length}
out=${out%Content-Md5*}
out=${out#*: }
ossLength=${out,,}
ossLength="${ossLength% *}"
ossLength=$(echo $ossLength)
ossLength="${ossLength%% *}"
echo "ossLength " "|"${ossLength}"|"
result=$(echo $ossInfo | grep "error")
if [[ "$result" != "" ]]; then
echo $result
exit 0
fi
curLength=$(ls -l ${fileName} | awk '{print $5}')
if [ "${curLength}" = "" ];then
echo "${fileName} not exist, download it"
./ossutil cp oss://ztupload/${ossPath}$fileName ${fileName}
curLength=$(ls -l ${fileName} | awk '{print $5}')
curLength=$(sed -i 's/\n//g' $curLength)
fi
echo "ossLength ${fileName} : "$ossLength
echo "curLength ${fileName} : "$curLength
if [ "${ossLength}" = "${curLength}" ];then
return 0
else
return 1
fi
}
function process(){
cd ~
rm $fileName
echo "fileName: " $fileName
./ossutil cp oss://ztupload/${ossPath}${fileName} ${fileName}
}
# function uploadLog(){
# logPath=${ossPath%/*}
# logPath=${logPath%/*}/logs/
# osslogPath=oss://ztupload/${logPath}autoDeploy.log
# journalctl -n 1000 -xe -t autoDeploy > ~/autoDeploy.log
# if [ $? = 0 ];then
# echo "uploaded log to ${osslogPath}"
# fi
# }
function main(){
echo " "
echo "start ossUpgrade service"
compare
result=$?
echo "result $result"
if [ $result = 0 ];then
# uploadLog
echo "local temp file is same with oss fileno need to replace"
exit 0
echo "end ossUpgrade service"
echo " "
else
echo "local temp file $fileName is different from oss, will download..."
fi
process
sleep 10
# uploadLog
echo "replaced"
echo "end ossUpgrade service"
echo " "
}
main