fileshare/verify_setup.sh
2025-08-10 12:57:17 +08:00

124 lines
3.2 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 服务验证脚本 - 检查服务是否正确设置和运行
echo "🔍 文件传输服务验证脚本"
echo "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "="
# 检查当前目录
if [ ! -f "app.py" ]; then
echo "❌ 请在fileshare目录中运行此脚本"
echo "💡 cd fileshare && ./verify_setup.sh"
exit 1
fi
echo "📂 检查文件结构..."
# 检查必需文件
files=("app.py" "cli.py" "requirements.txt" "static/index.html" "static/style.css" "static/app.js")
missing_files=()
for file in "${files[@]}"; do
if [ -f "$file" ]; then
echo "$file"
else
echo "❌ 缺少文件: $file"
missing_files+=("$file")
fi
done
if [ ${#missing_files[@]} -ne 0 ]; then
echo
echo "⚠️ 发现 ${#missing_files[@]} 个缺失文件,请先运行: python fix_paths.py"
exit 1
fi
echo
echo "🔧 检查Python依赖..."
# 检查Python是否安装
if ! command -v python &> /dev/null && ! command -v python3 &> /dev/null; then
echo "❌ Python 未安装"
exit 1
else
echo "✅ Python 已安装"
fi
# 检查pip是否安装
if ! command -v pip &> /dev/null && ! command -v pip3 &> /dev/null; then
echo "❌ pip 未安装"
exit 1
else
echo "✅ pip 已安装"
fi
# 检查虚拟环境(可选)
if [ -n "$VIRTUAL_ENV" ]; then
echo "✅ 当前在虚拟环境中: $(basename $VIRTUAL_ENV)"
else
echo " 未使用虚拟环境(可选)"
fi
echo
echo "📦 检查依赖包..."
# 检查主要依赖
python_cmd="python"
if command -v python3 &> /dev/null; then
python_cmd="python3"
fi
required_packages=("fastapi" "uvicorn" "httpx" "click" "rich")
missing_packages=()
for package in "${required_packages[@]}"; do
if $python_cmd -c "import $package" 2>/dev/null; then
echo "$package"
else
echo "❌ 缺少包: $package"
missing_packages+=("$package")
fi
done
if [ ${#missing_packages[@]} -ne 0 ]; then
echo
echo "⚠️ 发现 ${#missing_packages[@]} 个缺失依赖包,请运行:"
echo " pip install -r requirements.txt"
echo
fi
echo
echo "🚀 启动测试..."
# 检查端口是否被占用
if command -v lsof &> /dev/null; then
if lsof -i :8000 > /dev/null 2>&1; then
echo "⚠️ 端口 8000 已被占用"
echo " 当前占用进程:"
lsof -i :8000
echo
echo "💡 可以使用其他端口: PORT=8001 python app.py"
else
echo "✅ 端口 8000 可用"
fi
fi
# 提供启动建议
echo
echo "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "=" "="
echo "🎉 验证完成!"
echo
if [ ${#missing_files[@]} -eq 0 ] && [ ${#missing_packages[@]} -eq 0 ]; then
echo "✅ 所有检查都通过,可以启动服务了!"
echo
echo "🚀 推荐启动方式:"
echo " 1. 直接启动: python app.py"
echo " 2. 开发模式: uvicorn app:app --reload"
echo " 3. Docker启动: ./start.sh"
echo
echo "🌐 启动后访问: http://localhost:8000"
echo
echo "🧪 启动后可运行测试: python test_server.py"
else
echo "⚠️ 请先解决上述问题,然后重新运行此脚本"
fi