Files
zTools2/setup.sh
zikai 80b96d236f init: 从 /root/zikai 根目录迁入
把原本散落在 /root/zikai 的 FastAPI 服务整理到 server/ 子目录,
开启独立 git 与 venv。运行时数据(config.yaml / keys / uploads)
按 .gitignore 留在工作目录但不入仓。
2026-06-23 16:17:31 +00:00

53 lines
2.0 KiB
Bash
Executable File
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.

#!/usr/bin/env bash
# 一次性安装venv、依赖、数据库、SFTP 主机密钥。可重复执行。
set -euo pipefail
cd "$(dirname "$0")"
ROOT="$(pwd)"
VENV="$ROOT/.venv"
echo "==> [1/5] Python 虚拟环境"
if [ ! -x "$VENV/bin/python" ]; then
python3 -m venv "$VENV" || {
echo "venv 创建失败,尝试安装 python3-venv ..." >&2
sudo apt-get update -y >/dev/null && sudo apt-get install -y python3-venv >/dev/null
python3 -m venv "$VENV"
}
fi
echo " 使用:$($VENV/bin/python --version)"
echo "==> [2/5] pip 依赖"
"$VENV/bin/python" -m pip install --upgrade pip >/dev/null
"$VENV/bin/python" -m pip install -r "$ROOT/requirements.txt"
echo "==> [3/5] config.yaml"
if [ ! -f "$ROOT/config.yaml" ]; then
cp "$ROOT/config.example.yaml" "$ROOT/config.yaml"
echo " 已从 config.example.yaml 生成 config.yaml"
else
echo " config.yaml 已存在,保留原内容"
fi
echo "==> [4/5] MySQL 数据库(独立 DB + 账户,通过 root socket 建立)"
"$VENV/bin/python" -m app.scripts.init_db
echo "==> [5/5] 工作目录与 SFTP 主机密钥"
mkdir -p "$ROOT/uploads" "$ROOT/logs" "$ROOT/keys"
if [ ! -f "$ROOT/keys/ssh_host_ed25519_key" ]; then
ssh-keygen -q -t ed25519 -N "" -f "$ROOT/keys/ssh_host_ed25519_key" \
-C "zikai-sftp-host" || echo " (主机密钥将在 SFTP 首次启动时自动生成)"
fi
if [ ! -f "$ROOT/keys/authorized_keys" ]; then
: > "$ROOT/keys/authorized_keys"
chmod 600 "$ROOT/keys/authorized_keys"
echo " 已创建空的 keys/authorized_keys在此追加客户端公钥"
fi
echo
echo "安装完成。"
echo " - 数据库:$(grep -A1 'database:' "$ROOT/config.yaml" | tail -1 | tr -d ' ')"
echo " - HTTP 监听 127.0.0.1:6867由 apache2 在 https://f.zikai.wang 反代)"
echo " - SFTP 监听 0.0.0.0:2022请在防火墙放开 2022 端口)"
echo
echo "下一步:在 config.yaml 中设置 SFTP 密码 / 追加客户端公钥,然后 ./start.sh"