#!/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 downloadFromOss(){ 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 isFrontEnd(){ # result=$(echo $fileName | grep ".zip") # if [[ "$result" != "" ]]; then # return 0 # else # return 1 # 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 file,no need to replace" exit 0 echo "end ossUpgrade service" echo " " else echo "local temp file $fileName is different from oss, will download..." fi downloadFromOss # uploadLog echo "local temp file replaced" # isFrontEnd # result=$? # if [ $result = 0 ];then # preName=${fileName%/*} # echo "frontEnd package ${preName} will cover to projectPath" # # fi echo "end ossUpgrade service" echo " " } main