fix(windows): skip install if Tailscale already present (avoid MSI 1603)

A prior .exe(NSIS) install leaves Tailscale on disk but not on PATH; the MSI
then fails with error 1603 trying to install over it. Now detect the existing
binary at C:\Program Files\Tailscale\tailscale.exe and skip installation, and
treat a nonzero msiexec exit as success when the binary is already present.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
PharmQ Admin
2026-05-31 01:17:07 +00:00
parent 32118e7c6c
commit 99fd031d5a
2 changed files with 43 additions and 16 deletions

View File

@@ -100,15 +100,23 @@ function Test-Requirements {
function Install-Tailscale {
Write-Status "Checking Tailscale installation..."
# Check existing installation
# Check existing installation (PATH or the default install directory).
# IMPORTANT: a prior run may have installed Tailscale via the .exe (NSIS) even
# though it wasn't on PATH. Re-installing over it with the MSI fails with
# error 1603. So if the binary already exists, skip installation entirely and
# just make sure it's on PATH for this session.
$tailscaleExe = "C:\Program Files\Tailscale\tailscale.exe"
$tailscalePath = Get-Command "tailscale" -ErrorAction SilentlyContinue
if ($tailscalePath) {
$version = & tailscale version 2>$null | Select-Object -First 1
Write-Info "Tailscale is already installed."
Write-Info "Current version: $version"
if ($tailscalePath -or (Test-Path $tailscaleExe)) {
Write-Info "Tailscale is already installed. Skipping installation."
if (-not $tailscalePath -and ($env:Path -notlike "*Tailscale*")) {
$env:Path = "$env:Path;C:\Program Files\Tailscale"
}
$version = & $tailscaleExe version 2>$null | Select-Object -First 1
if ($version) { Write-Info "Current version: $version" }
return
}
Write-Info "Installing Tailscale for Windows..."
# Use the official MSI from the 'latest' stable channel and install it with
@@ -133,14 +141,20 @@ function Install-Tailscale {
-Wait -PassThru
# 0 = success, 3010 = success but reboot required
if ($proc.ExitCode -ne 0 -and $proc.ExitCode -ne 3010) {
throw "msiexec returned exit code $($proc.ExitCode). See log: $logPath"
# 1603 etc. often means a conflicting/partial install already exists.
# If the binary is nonetheless present, treat it as installed and move on;
# otherwise surface the failure with the log path.
if (Test-Path $tailscaleExe) {
Write-Warning "msiexec exit code $($proc.ExitCode), but Tailscale is already present. Continuing."
} else {
throw "msiexec returned exit code $($proc.ExitCode). See log: $logPath"
}
}
# Refresh PATH environment variable
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# Make sure the install dir is on PATH for this session
$tailscaleExe = "C:\Program Files\Tailscale\tailscale.exe"
if (Test-Path $tailscaleExe) {
$currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine")
if ($currentPath -notlike "*Tailscale*") {