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
-35
@@ -1,9 +1,9 @@
|
||||
# LocalNav 一键安装(无需预先克隆)
|
||||
# 用法:在 PowerShell 中执行 .\scripts\install.ps1
|
||||
# LocalNav 交互式部署管理(无需预先克隆)
|
||||
# 用法:.\scripts\install.ps1
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$DefaultRepo = "https://git.bz121.com/dekun/LocalNav.git"
|
||||
$DefaultDir = Join-Path (Get-Location) "LocalNav"
|
||||
$RawBase = "$($DefaultRepo -replace '\.git$','')/raw/main/scripts"
|
||||
|
||||
function Need-Cmd($name) {
|
||||
if (-not (Get-Command $name -ErrorAction SilentlyContinue)) {
|
||||
@@ -12,41 +12,20 @@ function Need-Cmd($name) {
|
||||
}
|
||||
|
||||
Need-Cmd python
|
||||
Need-Cmd git
|
||||
|
||||
$repo = $env:NAV_INSTALL_REPO
|
||||
if (-not $repo) {
|
||||
$inputRepo = Read-Host "Git 仓库地址 [$DefaultRepo]"
|
||||
$repo = if ($inputRepo) { $inputRepo } else { $DefaultRepo }
|
||||
}
|
||||
|
||||
$dest = $env:NAV_INSTALL_DIR
|
||||
if (-not $dest) {
|
||||
$inputDir = Read-Host "安装目录 [$DefaultDir]"
|
||||
$dest = if ($inputDir) { $inputDir } else { $DefaultDir }
|
||||
}
|
||||
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$installPy = Join-Path $scriptDir "install.py"
|
||||
$navctlPy = Join-Path $scriptDir "navctl.py"
|
||||
|
||||
if (Test-Path $installPy) {
|
||||
python $installPy --repo $repo --dir $dest
|
||||
if (-not (Test-Path $navctlPy)) {
|
||||
$tmpDir = Join-Path $env:TEMP ("localnav-" + [guid]::NewGuid().ToString())
|
||||
New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null
|
||||
Write-Host "[OK] 正在下载部署管理脚本..."
|
||||
Invoke-WebRequest -Uri "$RawBase/navctl.py" -OutFile (Join-Path $tmpDir "navctl.py")
|
||||
Invoke-WebRequest -Uri "$RawBase/nav_common.py" -OutFile (Join-Path $tmpDir "nav_common.py")
|
||||
$env:PYTHONPATH = "$tmpDir;$env:PYTHONPATH"
|
||||
python (Join-Path $tmpDir "navctl.py") @args
|
||||
Remove-Item -Recurse -Force $tmpDir
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
|
||||
$destPath = Resolve-Path -LiteralPath $dest -ErrorAction SilentlyContinue
|
||||
if ($destPath -and (Test-Path (Join-Path $destPath "app.py"))) {
|
||||
Write-Host "[OK] 目录已是 LocalNav,执行 git pull"
|
||||
git -C $destPath pull --ff-only
|
||||
} elseif (Test-Path $dest) {
|
||||
Write-Error "[FAIL] 目录已存在且不是 LocalNav 仓库: $dest"
|
||||
} else {
|
||||
Write-Host "[OK] 正在克隆 $repo -> $dest"
|
||||
$parent = Split-Path -Parent $dest
|
||||
if ($parent -and -not (Test-Path $parent)) {
|
||||
New-Item -ItemType Directory -Path $parent -Force | Out-Null
|
||||
}
|
||||
git clone $repo $dest
|
||||
}
|
||||
|
||||
python (Join-Path $dest "scripts\deploy.py")
|
||||
python $navctlPy @args
|
||||
|
||||
Reference in New Issue
Block a user