#!/bin/bash

# Root用户依赖安装脚本

echo "=== Root用户依赖安装脚本 ==="

# 检查是否为root用户
if [ "$EUID" -ne 0 ]; then
    echo "请使用root权限运行此脚本"
    echo "命令: sudo $0"
    exit 1
fi

echo "检测到root用户，开始安装依赖..."

# 1. 升级pip
echo "1. 升级pip..."
pip3 install --upgrade pip

# 2. 安装email-validator
echo "2. 安装email-validator..."
pip3 install email-validator

# 3. 安装核心依赖
echo "3. 安装核心依赖..."
pip3 install fastapi uvicorn sqlalchemy pymysql redis python-jose passlib python-multipart pydantic pydantic-settings httpx python-dotenv loguru alembic bcrypt

# 4. 验证安装
echo "4. 验证安装..."
python3 -c "
import sys
packages = ['email_validator', 'fastapi', 'uvicorn', 'sqlalchemy', 'pymysql', 'redis', 'jose', 'passlib', 'pydantic', 'httpx', 'alembic']
success = True
for pkg in packages:
    try:
        __import__(pkg)
        print(f'✓ {pkg}')
    except ImportError as e:
        print(f'✗ {pkg}: {e}')
        success = False

if success:
    print('\\n✓ 所有依赖安装成功!')
else:
    print('\\n✗ 部分依赖安装失败')
    sys.exit(1)
"

if [ $? -eq 0 ]; then
    echo ""
    echo "=== 安装完成 ==="
    echo "现在可以启动应用:"
    echo "python3 main.py"
else
    echo "安装失败，请检查错误信息"
    exit 1
fi