# 快速部署命令

## 一键部署脚本

将以下内容保存为 `quick-deploy.sh`，然后执行：

```bash
#!/bin/bash
# Life-OS 快速部署脚本

set -e

echo "🚀 Life-OS 快速部署开始..."
echo ""

# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'

# 配置变量（请根据实际情况修改）
DOMAIN="zhshihe.cn"
EMAIL="admin@zhshihe.cn"
PROJECT_DIR="/data/MBTI"

# 检查是否为root
if [ "$EUID" -ne 0 ]; then 
    echo -e "${RED}请使用root权限运行：sudo bash quick-deploy.sh${NC}"
    exit 1
fi

echo -e "${BLUE}第1步: 检查DNS解析${NC}"
DNS_IP=$(nslookup $DOMAIN | grep -A1 "Name:" | grep "Address:" | awk '{print $2}' | head -1)
echo "域名 $DOMAIN 解析到: $DNS_IP"
echo "期望IP: 119.45.106.76"
if [ "$DNS_IP" != "119.45.106.76" ]; then
    echo -e "${YELLOW}警告: DNS解析不匹配，请先配置DNS${NC}"
    read -p "是否继续？(y/n) " -n 1 -r
    echo
    if [[ ! $REPLY =~ ^[Yy]$ ]]; then
        exit 1
    fi
fi

echo -e "\n${BLUE}第2步: 安装SSL证书${NC}"
bash $PROJECT_DIR/deploy/setup-ssl.sh

echo -e "\n${BLUE}第3步: 配置后端环境变量${NC}"
if [ ! -f "$PROJECT_DIR/life-os-backend/.env" ]; then
    cp $PROJECT_DIR/life-os-backend/.env.example $PROJECT_DIR/life-os-backend/.env
    echo -e "${YELLOW}请编辑 $PROJECT_DIR/life-os-backend/.env 填入配置${NC}"
    echo -e "${YELLOW}按回车继续...${NC}"
    read
fi

echo -e "\n${BLUE}第4步: 配置前端环境变量${NC}"
echo "NEXT_PUBLIC_API_URL=https://$DOMAIN" > $PROJECT_DIR/life-os-web/.env.local
echo -e "${GREEN}✅ 前端环境变量已配置${NC}"

echo -e "\n${BLUE}第5步: 安装依赖${NC}"
cd $PROJECT_DIR/life-os-backend
source venv/bin/activate
pip install -q -r requirements.txt
echo -e "${GREEN}✅ 后端依赖已安装${NC}"

echo -e "\n${BLUE}第6步: 重启服务${NC}"
cd $PROJECT_DIR
python stop.py || true
sleep 2
python start.py &
sleep 10

echo -e "\n${BLUE}第7步: 测试服务${NC}"
echo "测试HTTPS访问..."
curl -I https://$DOMAIN 2>&1 | grep "200 OK" && echo -e "${GREEN}✅ HTTPS访问正常${NC}" || echo -e "${RED}❌ HTTPS访问失败${NC}"

echo "测试后端API..."
curl -s https://$DOMAIN/health | grep "healthy" && echo -e "${GREEN}✅ 后端API正常${NC}" || echo -e "${RED}❌ 后端API失败${NC}"

echo -e "\n${GREEN}================================${NC}"
echo -e "${GREEN}🎉 部署完成！${NC}"
echo -e "${GREEN}================================${NC}"
echo -e "\n访问地址:"
echo -e "  前端: ${BLUE}https://$DOMAIN${NC}"
echo -e "  API文档: ${BLUE}https://$DOMAIN/docs${NC}"
echo -e "\n下一步:"
echo -e "  1. 配置微信开放平台: ${YELLOW}https://open.weixin.qq.com/${NC}"
echo -e "  2. 在微信平台配置回调地址: ${YELLOW}https://$DOMAIN/api/wechat/callback${NC}"
echo -e "  3. 将AppID和AppSecret填入: ${YELLOW}$PROJECT_DIR/life-os-backend/.env${NC}"
echo ""

