program/start.sh

97 lines
2.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

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
# ========================================
# 智能矿山标签监测系统 - Ubuntu启动脚本
# ========================================
echo "======================================"
echo " 智能矿山标签监测系统"
echo " Intelligent Mining Tag Monitor"
echo "======================================"
# 设置脚本目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# 检查Python版本
PYTHON_CMD=""
if command -v python3 &> /dev/null; then
PYTHON_CMD="python3"
elif command -v python &> /dev/null; then
PYTHON_CMD="python"
else
echo "错误: 未找到Python请先安装Python 3.8+"
exit 1
fi
PYTHON_VERSION=$($PYTHON_CMD --version 2>&1 | cut -d' ' -f2 | cut -d'.' -f1,2)
echo "Python版本: $PYTHON_VERSION"
# 检查Python版本是否>=3.8
PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d'.' -f1)
PYTHON_MINOR=$(echo $PYTHON_VERSION | cut -d'.' -f2)
if [ "$PYTHON_MAJOR" -lt 3 ] || ([ "$PYTHON_MAJOR" -eq 3 ] && [ "$PYTHON_MINOR" -lt 8 ]); then
echo "错误: Python版本需要 3.8+,当前版本: $PYTHON_VERSION"
exit 1
fi
# 检查并创建虚拟环境
if [ ! -d "venv" ]; then
echo "正在创建Python虚拟环境..."
$PYTHON_CMD -m venv venv
if [ $? -ne 0 ]; then
echo "错误: 创建虚拟环境失败"
exit 1
fi
fi
# 激活虚拟环境
echo "激活虚拟环境..."
source venv/bin/activate
# 安装依赖
if [ -f "requirements.txt" ]; then
echo "正在检查并安装依赖..."
pip install --upgrade pip -q
pip install -r requirements.txt -q
if [ $? -ne 0 ]; then
echo "警告: 部分依赖安装失败,请检查网络或权限"
fi
fi
# 检查配置文件
if [ ! -f "config.py" ]; then
echo "警告: config.py 不存在,请检查配置文件"
fi
# 检查数据库连接
echo ""
echo "======================================"
echo " 系统配置检查"
echo "======================================"
# 检查MySQL是否可用
if command -v mysql &> /dev/null; then
echo "MySQL客户端: 已安装"
else
echo "MySQL客户端: 未安装 (客户端连接不需要)"
fi
# 检查name目录
if [ -d "../name" ]; then
CSV_COUNT=$(ls ../name/*.csv 2>/dev/null | wc -l)
echo "标签名称CSV文件: $CSV_COUNT"
else
echo "警告: name目录不存在标签中文名称可能无法显示"
echo " 请将标签CSV文件放置在 ../name/ 目录下"
fi
echo ""
echo "======================================"
echo " 启动Web服务"
echo "======================================"
echo "访问地址: http://localhost:5000"
echo "按 Ctrl+C 停止服务"
echo ""
# 启动应用
$PYTHON_CMD app.py