123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #!/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"
- /home/dev/node-v12.20.0-linux-x64/bin/node_modules/.bin/yarn
- echo -e "$echoPrefix yarn link $echoSuffix"
- /home/dev/node-v12.20.0-linux-x64/bin/node_modules/.bin/yarn link
- echo -e "$echoPrefix yarn build $echoSuffix"
- /home/dev/node-v12.20.0-linux-x64/bin/node_modules/.bin/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]
|