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>
53 lines
1.6 KiB
PowerShell
53 lines
1.6 KiB
PowerShell
# LocalNav 一键安装(无需预先克隆)
|
|
# 用法:在 PowerShell 中执行 .\scripts\install.ps1
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$DefaultRepo = "https://git.bz121.com/dekun/LocalNav.git"
|
|
$DefaultDir = Join-Path (Get-Location) "LocalNav"
|
|
|
|
function Need-Cmd($name) {
|
|
if (-not (Get-Command $name -ErrorAction SilentlyContinue)) {
|
|
Write-Error "[FAIL] 未找到 $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"
|
|
|
|
if (Test-Path $installPy) {
|
|
python $installPy --repo $repo --dir $dest
|
|
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")
|