You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

101 lines
2.5 KiB

#!/bin/bash
#set -x
set -e
codePath=/home/www/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/00base/02yvan-ext-mobile.sh) [cmd]