mirror of
https://github.com/UNITRONIX/BetterDesk.git
synced 2026-09-11 13:49:03 +00:00
fix(install): sanitize Go min version parsing and use valid download release.
Fixes #238 — handle GO_MIN_VERSION suffixes like 1.25+ and download go1.26.4 instead of missing go1.26.1.
This commit is contained in:
+17
-3
@@ -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"
|
||||
|
||||
+16
-7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user