#!/bin/bash

#sex -x

echo "Trigger WebHook!"

echo "Script is running as user: $USER"

# 注意 (ubuntu用户下的权限注意)：
# 1.chown -R ubuntu:ubuntu /usr/share/maven/
# 2.chown -R ubuntu:ubuntu /etc/maven/
# 3.在 ~/.ssh 上传 git 密钥

# 拉取分支最新代码
cd /home/www/project/BackendSys
git checkout develop
git pull

# 重新打包程序 (-P 配置文件)
mvn clean package -P dev


chown -R ubuntu:ubuntu ./
chmod +x ./system_config/webhook.sh
chmod +x ./system_config/deploy-script.sh

# 重启应用
./system_config/deploy-script.sh restart

# 监听控制台
# tail -f ./target/backendsys.log

## 在 backendsys.sh 中
#echo "Current directory: $(pwd)"
## 打印环境变量
#env

echo "Trigger Finish!"

/home/www/project/BackendSys/system_config/deploy-script.sh restart >> deploy-script.log 2>&1