From 4c7cc9d1ecbca7340e35756b5a1944c474601d7f Mon Sep 17 00:00:00 2001 From: lizw <1183409807@qq.com> Date: Fri, 2 Sep 2022 16:57:05 +0800 Subject: [PATCH] demo-deploy.sh --- wms8-demo/01yvan-ext.sh | 101 +++++++++++++++++++++++++++++++++++++++++ wms8-demo/02yvan-ext-mobile.sh | 101 +++++++++++++++++++++++++++++++++++++++++ wms8-demo/demo-deploy.sh | 4 +- 3 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 wms8-demo/01yvan-ext.sh create mode 100644 wms8-demo/02yvan-ext-mobile.sh diff --git a/wms8-demo/01yvan-ext.sh b/wms8-demo/01yvan-ext.sh new file mode 100644 index 0000000..1d9eec6 --- /dev/null +++ b/wms8-demo/01yvan-ext.sh @@ -0,0 +1,101 @@ +#!/bin/bash +#set -x +set -e + +codePath=/home/dev/deploy/yvan-ext +gitUrlArr=( + "http://git.yvanui.com/jztd/yvan-ext.git" +) + +branchArr=( + "master" +) +positionArr=( + "." +) +# 是否需要构建,-1:自动;0:不需要;1:需要 +needBuild=( +"1" +) + +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + +isChange="1" +pullCode() { + # Usage: pullCode "codePath" "gitUrl" "branch" "position" + path=$1 # 代码保存路径 + gitUrl=$2 # git仓库地址 + branch=${3:-"master"} # git分支 + position=${4:-""} # 使用“.”clone到当前文件夹 + isChange="1" + # 创建文件夹 + if [ ! -d "$path" ]; then + echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix" + exit + fi + + # git clone + echo -e "$echoPrefix cd $path $echoSuffix" + cd $path + if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then + echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix" + git clone $gitUrl $position + isChange="2" + fi + + # 进入文件夹,切换分支,git pull + if [ "$position" != "" ]; then + echo -e "$echoPrefix cd $position $echoSuffix" + cd $position + fi + echo -e "$echoPrefix git checkout $branch $echoSuffix" + git checkout $branch + echo -e "$echoPrefix git checkout . $echoSuffix" + git checkout . + echo -e "$echoPrefix git pull $echoSuffix" + if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then + isChange="0" + fi + echo "" +} + +buildCode() { + # 构建 yvan-ext + if [ "${needBuild[0]}" != "0" ]; then + echo -e "$echoPrefix cd $codePath $echoSuffix" + cd "$codePath" + echo -e "$echoPrefix yarn $echoSuffix" + yarn + echo -e "$echoPrefix yarn link $echoSuffix" + yarn link + echo -e "$echoPrefix yarn build $echoSuffix" + yarn build + echo "" + else + echo "yvan-ext 文件未变化" + fi +} + +deployPull() { + for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do + pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]} + if [ "${needBuild[idx]}" == "-1" ]; then + needBuild[idx]=$isChange + fi + done + echo "###--代码更新完成--------------------------------------------------------------------------###" + echo "" +} + +cmd=$1 +if [ "$cmd" == "deploy" ];then + deployPull + buildCode +elif [ "$cmd" == "pull" ];then + deployPull +else + echo "输入操作参数: pull deploy" +fi + +# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/wms8-demo/01yvan-ext.sh) [cmd] diff --git a/wms8-demo/02yvan-ext-mobile.sh b/wms8-demo/02yvan-ext-mobile.sh new file mode 100644 index 0000000..f46f5d9 --- /dev/null +++ b/wms8-demo/02yvan-ext-mobile.sh @@ -0,0 +1,101 @@ +#!/bin/bash +#set -x +set -e + +codePath=/home/dev/deploy/yvan-ext-mobile +gitUrlArr=( + "http://git.yvanui.com/jztd/yvan-ext-mobile.git" +) + +branchArr=( + "master" +) +positionArr=( + "." +) +# 是否需要构建,-1:自动;0:不需要;1:需要 +needBuild=( +"1" +) + +echoPrefix="\033[36m+" +echoSuffix="\033[0m" + +isChange="1" +pullCode() { + # Usage: pullCode "codePath" "gitUrl" "branch" "position" + path=$1 # 代码保存路径 + gitUrl=$2 # git仓库地址 + branch=${3:-"master"} # git分支 + position=${4:-""} # 使用“.”clone到当前文件夹 + isChange="1" + # 创建文件夹 + if [ ! -d "$path" ]; then + echo -e "$echoPrefix 请检查服务器是否正确,再执行: mkdir -p $path $echoSuffix" + exit + fi + + # git clone + echo -e "$echoPrefix cd $path $echoSuffix" + cd $path + if [ "`ls -A $path`" == "" ] || [ ! -d "$path/$position" ] || [ "`ls -A $path/$position`" = "" ]; then + echo -e "$echoPrefix git clone $gitUrl $position $echoSuffix" + git clone $gitUrl $position + isChange="2" + fi + + # 进入文件夹,切换分支,git pull + if [ "$position" != "" ]; then + echo -e "$echoPrefix cd $position $echoSuffix" + cd $position + fi + echo -e "$echoPrefix git checkout $branch $echoSuffix" + git checkout $branch + echo -e "$echoPrefix git checkout . $echoSuffix" + git checkout . + echo -e "$echoPrefix git pull $echoSuffix" + if [ "`git pull`" == "Already up-to-date." ] && [ $isChange == "1" ]; then + isChange="0" + fi + echo "" +} + +buildCode() { + # 构建 yvan-ext-mobile + if [ "${needBuild[0]}" != "0" ]; then + echo -e "$echoPrefix cd $codePath $echoSuffix" + cd "$codePath" + echo -e "$echoPrefix yarn $echoSuffix" + yarn + echo -e "$echoPrefix yarn link $echoSuffix" + yarn link + echo -e "$echoPrefix yarn build $echoSuffix" + yarn build + echo "" + else + echo "yvan-ext-mobile 文件未变化" + fi +} + +deployPull() { + for ((idx=0; idx<${#gitUrlArr[@]}; idx++)); do + pullCode $codePath ${gitUrlArr[idx]} ${branchArr[idx]} ${positionArr[idx]} + if [ "${needBuild[idx]}" == "-1" ]; then + needBuild[idx]=$isChange + fi + done + echo "###--代码更新完成--------------------------------------------------------------------------###" + echo "" +} + +cmd=$1 +if [ "$cmd" == "deploy" ];then + deployPull + buildCode +elif [ "$cmd" == "pull" ];then + deployPull +else + echo "输入操作参数: pull deploy" +fi + +# bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/wms8-demo/02yvan-ext-mobile.sh) [cmd] diff --git a/wms8-demo/demo-deploy.sh b/wms8-demo/demo-deploy.sh index 412f7cd..773b9c6 100644 --- a/wms8-demo/demo-deploy.sh +++ b/wms8-demo/demo-deploy.sh @@ -196,8 +196,8 @@ logs() { } deployYvanUI() { - bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/01yvan-ext.sh) pull - bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/00base/02yvan-ext-mobile.sh) pull + bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/wms8-demo/01yvan-ext.sh) pull + bash <(curl -s http://git.yvanui.com/lizhiwei/jztd-deploy/raw/master/wms8-demo/02yvan-ext-mobile.sh) pull } pid=`ps -ef | grep "DappName=${serverName}" | grep -v 'grep' | awk '{print $2}'`