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:
dekun
2026-07-12 12:01:01 +08:00
parent fc23a95e5c
commit f508f210f9
11 changed files with 608 additions and 278 deletions
+31 -32
View File
@@ -54,10 +54,12 @@
├── .env # 本地配置(自建,勿提交 Git)
├── ecosystem.config.cjs # PM2 守护进程配置
├── scripts/
│ ├── install.py # 一键安装(输入仓库地址,自动克隆 + 部署
│ ├── install.sh # Linux/macOS 安装封装(支持 curl | bash
│ ├── install.ps1 # Windows 安装封装
│ ├── deploy.py # 项目内更新部署(需已在仓库目录)
│ ├── navctl.py # 交互式部署管理(安装 / 卸载 / 更新
│ ├── nav_common.py # 部署脚本公共工具
│ ├── install.sh # Linux 入口(支持 curl | bash
│ ├── install.ps1 # Windows 入口
│ ├── install.py # 兼容:等价 navctl install
│ ├── deploy.py # 项目内安装逻辑(由 navctl 调用)
│ ├── deploy.sh # 项目内更新封装
│ ├── deploy.ps1 # 项目内更新封装
│ └── cleanup_gate_scout.py # 可选:清理旧「Gate 扫单」分组
@@ -79,46 +81,42 @@
## 五、一键部署(推荐,无需预先克隆)
在**新机器**无需先 `git clone`,运行安装脚本后按提示输入仓库地址即可自动克隆并完成部署
运行安装脚本后进入**交互式部署菜单**无需`git clone`
### 5.1 首次安装
### 5.1 启动菜单
```bash
# Linux / macOS(一条命令,从远程拉取安装脚本
# Linux / macOS(一条命令)
curl -fsSL https://git.bz121.com/dekun/LocalNav/raw/main/scripts/install.sh | bash
```
也可将 `install.sh` / `install.py` 拷贝到本机后执行:
```bash
bash scripts/install.sh
# 或
python3 scripts/install.py
bash scripts/install.sh
python3 scripts/navctl.py
```
**Windows PowerShell**
**Windows** `.\scripts\install.ps1`
```powershell
.\scripts\install.ps1
```
**菜单:**
**交互提示:**
| 按键 | 功能 |
|------|------|
| **1** | 一键部署安装:输入仓库地址 → 克隆 → 安装依赖 → 生成 `.env` → 自动 pm2 启动 |
| **2** | 一键卸载:停止 pm2/systemd;可选删除安装目录(含数据库,需二次确认) |
| **3** | 更新:`git pull` + 重新部署 + 自动重启 |
| **0** | 退出 |
| 提示项 | 默认值 |
|--------|--------|
| Git 仓库地址 | `https://git.bz121.com/dekun/LocalNav.git` |
| 安装目录 | Linux`/opt/LocalNav`Windows`./LocalNav` |
安装信息会保存到 `~/.config/localnav/install.json`,下次打开菜单自动识别安装目录与服务状态。
**非交互(使用默认值):**
### 5.2 非交互命令
```bash
python3 scripts/install.py -y
python3 scripts/install.py --repo https://git.bz121.com/dekun/LocalNav.git --dir /opt/LocalNav
python3 scripts/navctl.py install -y
python3 scripts/navctl.py install --repo https://git.bz121.com/dekun/LocalNav.git --dir /opt/LocalNav
python3 scripts/navctl.py update --dir /opt/LocalNav
python3 scripts/navctl.py uninstall --dir /opt/LocalNav
```
环境变量可跳过提问:`NAV_INSTALL_REPO``NAV_INSTALL_DIR`
### 5.2 自动完成的步骤
### 5.3 自动完成的步骤(安装 / 更新)
| 步骤 | 说明 |
|------|------|
@@ -132,14 +130,15 @@ python3 scripts/install.py --repo https://git.bz121.com/dekun/LocalNav.git --dir
| 内网 Cookie | 默认 `NAV_COOKIES_INSECURE_HTTP=1`(便于 `http://IP:端口` 访问) |
| **自动启动** | 若检测到 **pm2**`pm2 start``pm2 restart nav-site`;否则尝试 **systemd** `nav-site` 服务 |
**注意:** 脚本不会覆盖 `.env` 中已有的 `NAV_SECRET_KEY` 等配置。生产环境部署后请尽快登录并在「系统设置」中修改密码。仅安装不启动可加 `--no-start`
**注意:** 脚本不会覆盖 `.env` 中已有的 `NAV_SECRET_KEY` 等配置。生产环境部署后请尽快登录并在「系统设置」中修改密码。仅安装不启动可`deploy.py` `--no-start`
### 5.3 已安装后的更新
### 5.4 已安装后的更新
也可在菜单选 **3**,或:
```bash
cd /opt/LocalNav
git pull
python3 scripts/deploy.py # 或 bash scripts/deploy.sh
python3 scripts/navctl.py update
```
部署完成后启动: