6897f88afd
Prompt for repo URL and install directory, auto git clone, then run project setup. Keep deploy.py for in-repo updates only. Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.4 KiB
Bash
55 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
# LocalNav 一键安装(无需预先克隆)
|
|
# 用法:
|
|
# curl -fsSL https://git.bz121.com/dekun/LocalNav/raw/main/scripts/install.sh | bash
|
|
# bash install.sh
|
|
set -euo pipefail
|
|
|
|
DEFAULT_REPO="https://git.bz121.com/dekun/LocalNav.git"
|
|
DEFAULT_DIR="/opt/LocalNav"
|
|
|
|
need_cmd() {
|
|
command -v "$1" >/dev/null 2>&1 || {
|
|
echo "[FAIL] 未找到 $1,请先安装" >&2
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
need_cmd python3
|
|
need_cmd git
|
|
|
|
REPO="${NAV_INSTALL_REPO:-}"
|
|
DEST="${NAV_INSTALL_DIR:-}"
|
|
|
|
if [ -z "$REPO" ]; then
|
|
read -rp "Git 仓库地址 [${DEFAULT_REPO}]: " REPO
|
|
REPO="${REPO:-$DEFAULT_REPO}"
|
|
fi
|
|
|
|
if [ -z "$DEST" ]; then
|
|
read -rp "安装目录 [${DEFAULT_DIR}]: " DEST
|
|
DEST="${DEST:-$DEFAULT_DIR}"
|
|
fi
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
INSTALL_PY="${SCRIPT_DIR}/install.py"
|
|
|
|
if [ -f "$INSTALL_PY" ]; then
|
|
exec python3 "$INSTALL_PY" --repo "$REPO" --dir "$DEST"
|
|
fi
|
|
|
|
# 通过 curl 管道执行时,本机没有 install.py,内联克隆 + 部署
|
|
if [ -d "$DEST/.git" ] && [ -f "$DEST/app.py" ]; then
|
|
echo "[OK] 目录已是 LocalNav,执行 git pull"
|
|
git -C "$DEST" pull --ff-only
|
|
elif [ -d "$DEST" ]; then
|
|
echo "[FAIL] 目录已存在且不是 LocalNav 仓库: $DEST" >&2
|
|
exit 1
|
|
else
|
|
echo "[OK] 正在克隆 $REPO -> $DEST"
|
|
mkdir -p "$(dirname "$DEST")"
|
|
git clone "$REPO" "$DEST"
|
|
fi
|
|
|
|
exec python3 "$DEST/scripts/deploy.py"
|