From 513ba7b5455320932f4531ffab3cc8d5415ca320 Mon Sep 17 00:00:00 2001 From: Steven-Qiang Date: Tue, 25 Aug 2026 14:46:11 +0800 Subject: [PATCH] fix(install.ps1): support Windows PowerShell 5.1 and fix default_base_dir - Replace PowerShell 7+-only ternary operator with if/else so the script parses and runs on Windows PowerShell 5.1 (the default 'powershell.exe'). - Force TLS 1.2 before the download; on PS 5.1 the default TLS negotiation is rejected by GitHub and the release download fails. - Define and use \ in setHOME so G_EXPERIMENTAL is only enabled when a custom base dir is used, instead of always being enabled. --- install.ps1 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/install.ps1 b/install.ps1 index 15973ee..256e67a 100644 --- a/install.ps1 +++ b/install.ps1 @@ -6,7 +6,17 @@ param ( $os = "windows" $arch = "amd64" -$base_dir = $base_dir -eq "" ? ($env:G_HOME ? $env:G_HOME : "$HOME\.g") : $base_dir +# Force TLS 1.2 so that the download works on Windows PowerShell 5.1, +# which defaults to older TLS versions that GitHub rejects. +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + +if ([string]::IsNullOrWhiteSpace($base_dir)) { + if ([string]::IsNullOrWhiteSpace($env:G_HOME)) { + $base_dir = "$HOME\.g" + } else { + $base_dir = $env:G_HOME + } +} $dest_file = "${base_dir}\downloads\g${release}.${os}-${arch}.zip" $url = "https://github.com/voidint/g/releases/download/v${release}/g${release}.${os}-${arch}.zip" @@ -28,7 +38,10 @@ function InstallG () { function setHOME() { + $default_base_dir = "$HOME\.g" if ($base_dir -ne $default_base_dir) { + # G_HOME is an experimental feature; enable the switch only when a + # custom base dir is used (i.e. not the default ~/.g). [System.Environment]::SetEnvironmentVariable("G_EXPERIMENTAL", "true", [System.EnvironmentVariableTarget]::User) } [System.Environment]::SetEnvironmentVariable("G_HOME", $base_dir, [System.EnvironmentVariableTarget]::User)