autoDeploy/ossUpgrade.sh

63 lines
1.7 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:
## 这个脚本能正常工作的前提是 systemd脚本如果不是root也能通过sudo 调用高级权限来执行。
## 否则就要结合checkService.sh一起使用。那个单独放在一个服务里用root用户执行
# ./ossUpgrade.sh "stage/ztsjxxxt/frontEnd/" html.zip ztsjxxxt
ossPath=$1 #末尾别忘了加/
fileName=$2
serviceName=$3
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
logPath=${ossPath%/*}
logPath=${logPath%/*}/logs/
osslogPath=oss://ztupload/${logPath}autoDeploy.log
if [ ${ossSum} = ${curSum} ];then
sudo journalctl -n 1000 -xe -t autoDeploy > ~/autoDeploy.log
./ossutil cp ~/autoDeploy.log ${osslogPath} -f
echo "uploaded log to ${osslogPath}"
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}
sudo systemctl restart $serviceName
sleep 10
sudo journalctl -n 1000 -xe -t autoDeploy > ~/autoDeploy.log
./ossutil cp ~/autoDeploy.log osslogPath -f
echo "replaced"