#!/bin/bash
# PMS 部署脚本 - 测试环境

set -e

echo "=== PMS 测试环境部署 ==="

# 1. 创建目录
echo "1. 创建部署目录..."
mkdir -p /data/pms_dev/api-server
mkdir -p /data/pms_dev/device-server
mkdir -p /data/pms_dev/web

# 2. 复制文件
echo "2. 复制服务文件..."
cp software/api-server/target/release/api-server /data/pms_dev/api-server/
cp software/api-server/.env.test /data/pms_dev/api-server/.env

cp software/device-server/target/release/device-server /data/pms_dev/device-server/
cp software/device-server/.env.test /data/pms_dev/device-server/.env

# 3. 复制前端静态文件
echo "3. 复制前端文件..."
cp -r software/web/dist/* /data/pms_dev/web/

# 3. 复制systemd服务
echo "3. 安装systemd服务..."
cp deploy/pms-api-test.service /etc/systemd/system/
cp deploy/pms-device-test.service /etc/systemd/system/

# 4. 复制nginx配置
echo "4. 安装nginx配置..."
cp deploy/nginx/test.anzhizhichong.com.conf /etc/nginx/conf.d/

# 5. 重启服务
echo "5. 重启服务..."
systemctl daemon-reload
systemctl restart pms-api-test
systemctl restart pms-device-test
systemctl restart nginx

# 6. 设置开机启动
echo "6. 设置开机启动..."
systemctl enable pms-api-test
systemctl enable pms-device-test

echo "=== 部署完成 ==="
echo "测试环境: https://test.anzhizhichong.com"
echo "API端口: 3000"
echo "TCP端口: 3001"
