nex_math/scripts/init.sh

34 lines
1.0 KiB
Bash
Raw Normal View History

2026-09-18 05:28:05 +00:00
#!/usr/bin/env bash
# 初始化:安装后端依赖并写入种子数据(data/math.db)。
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"
mkdir -p data
if [[ ! -x backend/.venv/bin/python ]]; then
if command -v uv >/dev/null 2>&1; then
echo "[init] 使用 uv 创建 Python 虚拟环境…"
(cd backend && uv venv .venv --python 3.12)
else
if python3 -c 'import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)' 2>/dev/null; then
echo "[init] 使用 python3 创建虚拟环境…"
python3 -m venv backend/.venv
else
echo "[init] 未找到 Python 3.10+,请安装 uv(https://docs.astral.sh/uv/)后重试。" >&2
exit 1
fi
fi
fi
if command -v uv >/dev/null 2>&1; then
uv pip install --python backend/.venv/bin/python -r backend/requirements.txt
else
backend/.venv/bin/pip install -r backend/requirements.txt
fi
(cd backend && .venv/bin/python -m seed)
echo "[init] 完成。启动方式:./scripts/start.sh"