From a4bead5a132a666a3e4c2f4d64be509f747a8ef2 Mon Sep 17 00:00:00 2001 From: UNITRONIX <36471318+UNITRONIX@users.noreply.github.com> Date: Sat, 4 Jul 2026 23:17:43 +0200 Subject: [PATCH] fix(install): sanitize Go min version parsing and use valid download release. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #238 — handle GO_MIN_VERSION suffixes like 1.25+ and download go1.26.4 instead of missing go1.26.1. --- betterdesk.ps1 | 20 +++++++++++++++++--- betterdesk.sh | 23 ++++++++++++++++------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/betterdesk.ps1 b/betterdesk.ps1 index 6ac64d25..7d9a6dc8 100644 --- a/betterdesk.ps1 +++ b/betterdesk.ps1 @@ -145,6 +145,7 @@ $script:RELAY_SERVERS = if ($RelayServers) { $RelayServers } elseif ($env:RELAY_ # Go server configuration $script:GO_SERVER_SOURCE = Join-Path $script:ScriptDir "betterdesk-server" $script:GO_MIN_VERSION = "1.25" +$script:GO_DOWNLOAD_VERSION = "1.26.4" # Legacy Rust checksums (deprecated, kept for migration purposes) $script:HBBS_WINDOWS_X86_64_SHA256 = "B790FA44CAC7482A057ED322412F6D178FB33F3B05327BFA753416E9879BD62F" $script:HBBR_WINDOWS_X86_64_SHA256 = "368C71E8D3AEF4C5C65177FBBBB99EA045661697A89CB7C2A703759C575E8E9F" @@ -909,6 +910,19 @@ function Print-Status { # Go Installation and Compilation Functions #=============================================================================== +function Get-GoVersionPart { + param( + [string]$Version, + [int]$Index = 0 + ) + $normalized = ($Version -replace '[^0-9.]', '') + $parts = $normalized -split '\.' + if ($Index -lt $parts.Count -and $parts[$Index] -match '^\d+$') { + return [int]$parts[$Index] + } + return 0 +} + function Test-GoInstalled { $goCmd = Get-Command go -ErrorAction SilentlyContinue if (-not $goCmd) { @@ -931,8 +945,8 @@ function Test-GoInstalled { Print-Warning "Detected vulnerable Go version $goVersion (known stdlib CVEs)." return $false } - $minMajor = [int]($script:GO_MIN_VERSION.Split('.')[0]) - $minMinor = [int]($script:GO_MIN_VERSION.Split('.')[1]) + $minMajor = Get-GoVersionPart -Version $script:GO_MIN_VERSION -Index 0 + $minMinor = Get-GoVersionPart -Version $script:GO_MIN_VERSION -Index 1 if ($currentMajor -gt $minMajor -or ($currentMajor -eq $minMajor -and $currentMinor -ge $minMinor)) { return $true @@ -945,7 +959,7 @@ function Test-GoInstalled { function Install-Golang { Print-Step "Installing Go toolchain..." - $goVersion = "1.26.1" + $goVersion = $script:GO_DOWNLOAD_VERSION $goUrl = "https://go.dev/dl/go$goVersion.windows-amd64.zip" $goZip = Join-Path $env:TEMP "go$goVersion.zip" $goRoot = "C:\Go" diff --git a/betterdesk.sh b/betterdesk.sh index 4b53b379..ccdc5c85 100644 --- a/betterdesk.sh +++ b/betterdesk.sh @@ -149,6 +149,8 @@ GO_SERVER_SOURCE="$SCRIPT_DIR/betterdesk-server" # Minimum Go version required for compilation GO_MIN_VERSION="1.25" +# Point release downloaded when system Go is missing/outdated (must exist on go.dev/dl). +GO_DOWNLOAD_VERSION="1.26.4" # Default paths (can be overridden by environment variables) RUSTDESK_PATH="${RUSTDESK_PATH:-}" @@ -1903,16 +1905,23 @@ print_status() { # Go Installation and Compilation #=============================================================================== +# Extract numeric semver component (handles "1.25+", "26rc1", etc.). +_go_version_part() { + local ver="$1" field="${2:-1}" + local part + part=$(echo "$ver" | cut -d'.' -f"$field" | grep -oE '^[0-9]+' | head -1) + echo "${part:-0}" +} + check_go_installed() { if command -v go &> /dev/null; then local go_version go_version=$(go version | awk '{print $3}' | sed 's/go//') - local go_major=$(echo "$go_version" | cut -d'.' -f1) - local go_minor=$(echo "$go_version" | cut -d'.' -f2) - local go_patch=$(echo "$go_version" | cut -d'.' -f3) - [ -z "$go_patch" ] && go_patch=0 - local min_major=$(echo "$GO_MIN_VERSION" | cut -d'.' -f1) - local min_minor=$(echo "$GO_MIN_VERSION" | cut -d'.' -f2) + local go_major=$(_go_version_part "$go_version" 1) + local go_minor=$(_go_version_part "$go_version" 2) + local go_patch=$(_go_version_part "$go_version" 3) + local min_major=$(_go_version_part "$GO_MIN_VERSION" 1) + local min_minor=$(_go_version_part "$GO_MIN_VERSION" 2) # Security hardening: reject vulnerable Go 1.26.0 stdlib. if [ "$go_major" -eq 1 ] && [ "$go_minor" -eq 26 ] && [ "$go_patch" -eq 0 ]; then @@ -1941,7 +1950,7 @@ install_golang() { return 0 fi - local go_version="1.26.1" + local go_version="$GO_DOWNLOAD_VERSION" local go_arch="" case "$ARCH_NAME" in