Add interactive navctl menu for install, uninstall, and update.
Provide navctl.py with a numbered menu, persist install path in config, and support curl bootstrap without pre-cloning the repo. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+14
-34
@@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
# LocalNav 一键安装(无需预先克隆)
|
||||
# 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"
|
||||
RAW_BASE="${DEFAULT_REPO%.git}/raw/main/scripts"
|
||||
|
||||
need_cmd() {
|
||||
command -v "$1" >/dev/null 2>&1 || {
|
||||
@@ -16,39 +16,19 @@ need_cmd() {
|
||||
}
|
||||
|
||||
need_cmd python3
|
||||
need_cmd git
|
||||
|
||||
REPO="${NAV_INSTALL_REPO:-}"
|
||||
DEST="${NAV_INSTALL_DIR:-}"
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd || true)"
|
||||
NAVCTL_PY="${SCRIPT_DIR}/navctl.py"
|
||||
|
||||
if [ -z "$REPO" ]; then
|
||||
read -rp "Git 仓库地址 [${DEFAULT_REPO}]: " REPO
|
||||
REPO="${REPO:-$DEFAULT_REPO}"
|
||||
if [ ! -f "$NAVCTL_PY" ]; then
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMP_DIR"' EXIT
|
||||
echo "[OK] 正在下载部署管理脚本..."
|
||||
curl -fsSL "${RAW_BASE}/navctl.py" -o "${TMP_DIR}/navctl.py"
|
||||
curl -fsSL "${RAW_BASE}/nav_common.py" -o "${TMP_DIR}/nav_common.py"
|
||||
export PYTHONPATH="${TMP_DIR}:${PYTHONPATH:-}"
|
||||
exec python3 "${TMP_DIR}/navctl.py" "$@"
|
||||
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"
|
||||
cd "$(dirname "$NAVCTL_PY")"
|
||||
exec python3 "$NAVCTL_PY" "$@"
|
||||
|
||||
Reference in New Issue
Block a user