201910092 - money168/cowsay GitHub Wiki

#!/bin/sh

fontsJarName=“fonts-1.0.0.jar”

warPath=‘/tw/war/’
tempPath=‘/tmp/special-fonts-reload/’

kaiuUrl=‘http://xxx.xxx.xxx.xxx/kaiu.ttf’
mingliuUrl=‘http://xxx.xxx.xxx.xxx/mingliu.ttf’

updateProjects=(“1111” “2222” “3333” “4444”)

  1. set ###
    SUCCESS_ECHO=‘\033[0;32m’
    INFO_ECHO=‘\033[1;34m’
    DEFAULT_ECHO=‘\033[0m’
    WARNING_ECHO=‘\033[1;33m’
    ERROR_ECHO=‘\033[0;31m’

jbossServicePrefix=‘jboss-as-’
#jboss service prefix

fontsDir=‘fonts/’
warLibDir=‘WEB-INF/lib/’
jarTempDir=“${tempPath}jar/”
warTempDir=“${tempPath}war/”

hasError=false
projectExists=false
jarExists=false

  1. function定義區 ###
    function validate_url(){
    if `wget -S --spider $1 2>&1; then
    return 0;
    else
    return 1;
    fi
    }
    function echoc(){
    echo -e “${2}${1}${DEFAULT_ECHO}”
    }

echoc “update war path:${warPath}” “${INFO_ECHO}”
#echoc “update war path:${warPath}” “${INFO_ECHO}”

  1. 檢核
    if [ -d “$tempPath” ]; then
    echoc “${tempPath} exists!***ERROR***” ${ERROR_ECHO}
    hasError=true
    else
    mkdir -p “${jarTempDir}${fontsDir}”;
    mkdir -p “${warTempDir}${warLibDir}”;
    fi
  1. test stdout
  2. echo ‘-—test link start——-’
  3. wget -S —spider “$kaiuUrl” 2>&1 | grep ‘HTTP 1.1 200 OK’
  4. wget -S —spider “$mingliuUrl” 2>&1 | grep ‘HTTP 1.1 200 OK’
  5. echo ‘-—test link end——-’

if `validate_url $kaiuUrl`; then
echoc ‘cannot download kaiu.ttf’ ${ERROR_ECHO}
hasError=true
fi
if `validate_url $mingliuUrl`; then
echoc ‘cannot download mingliuUrl.ttf’ ${ERROR_ECHO}
hasError=true
fi

for index in ${!updateProjects[@]}
do
project=“${updateProjects[index]}”
if [ ! -e “${warPath}${project}.war” ]; then
echoc “${warPath}${project}.war not exists!***WARNING***” ${WARNING_ECHO}
unset ‘updateProjects[index]’
else
if [ “${jarExists}” == false ]; then
if [ ! -e “$fontsJarPath” ]; then
#get fonts from war
unzip -l “${warPath}${project}.war” | grep “${warLibDir}${fontsJarName}”

if [ “$?” == “0” ]; then echoc “copy ${fontsJarName} from ${warPath}${project}.war” “${INFO_ECHO}” unzip -p “${warPath}${project}.war” “${warLibDir}${fontsJarName}”>"${tempPath}/${fontsJarName}" jarExists=true; fi else echoc “copy ${fontsJarName} from ${fontsJarPath}” “${INFO_ECHO}” cp “$fontsJarPath” “${tempPath}/${fontsJarName}” jarExists=true; fi fi projectExists=true fi

done

if [ “${projectExists}” == false ]; then
echoc ‘no project exists!***ERROR***’ ${ERROR_ECHO}
hasError=true
fi

if [ “$hasError” = true ]; then
rm -rf “$tempPath”;
echoc ‘exists error!stop running!***ERROR***’ ${ERROR_ECHO}
exit 1
fi

wget -q -O “${jarTempDir}${fontsDir}kaiu.ttf” “$kaiuUrl”
wget -q -O “${jarTempDir}${fontsDir}mingliu.ttf” “$mingliuUrl”

cp “${jarTempDir}${fontsDir}kaiu.ttf” “${jarTempDir}${fontsDir}kaiuliu.ttf”

cd “${jarTempDir}”
zip -r -u “${tempPath}${fontsJarName}” “${fontsDir}”

cp “${tempPath}${fontsJarName}” “${warTempDir}${warLibDir}/${fontsJarName}”

cd “${warTempDir}”

for index in ${!updateProjects[@]}
do
project=“${updateProjects[index]}”
echoc “update ${warPath}${project}.war” “${INFO_ECHO}”
zip -r -u “${warPath}${project}.war” “${warLibDir}”
#jboss restart
sudo systemctl stop “${jbossServicePrefix}${project}”
sudo systemctl start “${jbossServicePrefix}${project}”
done

rm -rf “$tempPath”;

echoc “done” “${SUCCESS_ECHO}”

#exit 1

⚠️ **GitHub.com Fallback** ⚠️