#!/bin/bash
# PMS 部署脚本 - 正式环境

set -e

echo "=== PMS 正式环境部署 ==="

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

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

cp software/device-server/target/release/device-server /data/pms/device-server/
cp software/device-server/.env.production /data/pms/device-server/.env

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

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

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

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

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

echo "=== 部署完成 ==="
echo "正式环境: https://app.anzhizhichong.com"
echo "API端口: 9000"
echo "TCP端口: 9001"
