#!/bin/sh -l
function mvn_server(){
  source ~/.zshrc
  export JAVA_HOME=$JAVA_HOME_17
	# 执行maven命令
	log_yellow "切换jdk17"
	log_black `java -version`
	log_black "mvn clean package -Dmaven.test.skip=true"
	mvn clean package -Dmaven.test.skip=true
  export JAVA_HOME=$JAVA_HOME_8
	log_black `java -version`
	log_yellow "切换jdk8"
	LOG "编译完成"
}
function git_pull()
{
	
	# # 切换临时目录
	# log_black "rm -rf $temp_project_path"
	# rm -rf $temp_project_path

	# log_black "cd $temp_base_path"
	# cd $temp_base_path
	# # 拉取代码	
	# log_black "git clone http://gitlab.totalapp.cn:8880/$GIT_SERVICE_TYPE/$GIT_SERVICE_NAME.git"
	# git clone http://gitlab.totalapp.cn:8880/$GIT_SERVICE_TYPE/$GIT_SERVICE_NAME.git
	
	# log_black "cd $GIT_SERVICE_NAME"
	# cd $GIT_SERVICE_NAME


	#切换分支 
	log_black "git checkout $branch"
	branch_retuen=`git checkout $branch`
	if [[ ! $branch_retuen ]]; then
	  LOG "输入的分支错误，请核实"
	  exit 1
	else 
	  LOG "切换[$branch]分支,返回:"$branch_retuen
	fi

	
}

# 绿字
function LOG(){
	echo -e "\033[32m $1 \033[0m"
}

# 黄字
function log_yellow(){
	echo -e "\033[33m $1 \033[0m"
}

# 红字
function log_red(){
	echo -e "\033[31m $1 \033[0m"
}

# 黑字
function log_black(){
	echo -e "\033[47;30m $1 \033[0m"
}






log_red "使用此脚本拉取git并使用maven配置进行打包,需要记得修改,请注意!!!!"
log_red "temp_base_path sh脚本目录"
log_red "mvm_path maven文件jar目录"



branch="提交过代码后的"



cd /Users/tongzuqi/pro/dongchi/gaoxin/nestqxsdboot
pwd=`pwd`
mvm_path=/Users/ONE/maven/apache-maven-3.6.1/lib/repo
log_red "maven路径:"$mvm_path


log_red "当前路径:"$pwd
log_red "分支名:"$branch
rm -rf /Users/tongzuqi/pro/dongchi/gaoxin/nestqxsdboot/nest-lcdp-boot-server/target/
LOG "-------编译中：-----------"
mvn_server;
LOG "-------删除git临时目录-------"
set -x
pwd
chmod 755 /Users/tongzuqi/pro/dongchi/gaoxin/nestqxsdboot/nest-lcdp-boot-server/target/*.jar
file_name="nest-lcdp-boot-server-v2.jar"
file_name_time=$file_name$(date +%Y%m%d%H%M)
scp -r /Users/tongzuqi/pro/dongchi/gaoxin/nestqxsdboot/nest-lcdp-boot-server/target/nest-lcdp-boot-server.jar root@12.1.89.111:/home/gaoxin/nest-qxsd-v2/$file_name_time
ssh -tt -p 22 root@12.1.89.111  <<EOF
  cd /home/gaoxin/nest-qxsd-v2/
  #\cp -f  $file_name_time $file_name
	#sh run.sh restart
	echo "手动执行cp命令：\cp -f  $file_name_time $file_name"
	echo "手动执行启动命令：sh run.sh restart"
	echo "启动服务结束"
	exit
EOF







