fix: use user dir on Windows, detect pipe execution for one-click install
- Windows default: $env:USERPROFILE\hapi instead of C:\hapi - PowerShell: detect iex/pipe execution ($PSCommandPath empty) to skip Read-Host prompt and enter quick install mode - Bash: detect curl|bash pipe (! -t 0) to enter quick install mode - This fixes scripts hanging on menu prompts when run via irm|iex or curl|bash via [HAPI](https://hapi.run) Co-Authored-By: HAPI <[email protected]>
This commit is contained in:
+11
-3
@@ -97,11 +97,16 @@ function Write-Err { param($msg) Write-Host "[ERR] $msg" -ForegroundColor Red;
|
||||
# 设置安装目录
|
||||
# ─────────────────────────────────────────
|
||||
function Setup-InstallDir {
|
||||
$defaultDir = "C:\hapi"
|
||||
$defaultDir = Join-Path $env:USERPROFILE "hapi"
|
||||
|
||||
if ($InstallDir) {
|
||||
$script:INSTALL_DIR = $InstallDir
|
||||
} elseif (-not $PSCommandPath) {
|
||||
# iex / 管道执行(如 irm | iex),自动使用默认值
|
||||
$script:INSTALL_DIR = $defaultDir
|
||||
Write-Info "自动使用默认目录: $defaultDir"
|
||||
} else {
|
||||
# 文件执行,询问用户
|
||||
Write-Host ""
|
||||
Write-Info "请选择 HAPI 安装目录"
|
||||
Write-Host " 默认: $defaultDir"
|
||||
@@ -1205,8 +1210,11 @@ function Run-QuickMode {
|
||||
# ─────────────────────────────────────────
|
||||
"" | Out-File $LOG_FILE
|
||||
|
||||
# 如果带有旧版参数,进入快速模式
|
||||
if ($Upgrade -or $Force -or $Source -or $SkipHub -or $InstallDir) {
|
||||
# 检测是否是 iex / 管道执行(如 irm | iex)
|
||||
$isIexExecution = -not $PSCommandPath
|
||||
|
||||
# 如果带有旧版参数,或是 iex 执行,进入快速模式
|
||||
if ($Upgrade -or $Force -or $Source -or $SkipHub -or $InstallDir -or $isIexExecution) {
|
||||
Write-Host ""
|
||||
Write-Host "╔══════════════════════════════════════════════════════════════════╗" -ForegroundColor White
|
||||
Write-Host "║ HAPI 快速模式 ║" -ForegroundColor White
|
||||
|
||||
+2
-2
@@ -1503,8 +1503,8 @@ main() {
|
||||
|
||||
: > "$LOG_FILE"
|
||||
|
||||
# 如果带有旧版参数,进入快速模式
|
||||
if [[ "$UPGRADE_ONLY" == true || "$FORCE" == true || -n "$SOURCE" || "$SKIP_HUB" == true || -n "$INSTALL_DIR_ARG" ]]; then
|
||||
# 如果带有旧版参数,或是管道执行(curl | bash),进入快速模式
|
||||
if [[ "$UPGRADE_ONLY" == true || "$FORCE" == true || -n "$SOURCE" || "$SKIP_HUB" == true || -n "$INSTALL_DIR_ARG" || ! -t 0 ]]; then
|
||||
echo ""
|
||||
echo -e "${BOLD}╔══════════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${BOLD}║${NC} HAPI 快速模式 ${BOLD}║${NC}"
|
||||
|
||||
Reference in New Issue
Block a user