diff --git a/packaging/install.ps1 b/packaging/install.ps1 index 8ce23fcb..5f1b4231 100644 --- a/packaging/install.ps1 +++ b/packaging/install.ps1 @@ -22,6 +22,9 @@ $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' function Die([string]$msg) { [Console]::Error.WriteLine("strata installer: $msg"); throw "strata installer stopped" } +# older Windows 10 builds offer only TLS 1.0/1.1 to Windows PowerShell 5.1, and GitHub accepts only 1.2; a company proxy may want the Windows sign-in +try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { } +try { if ([Net.WebRequest]::DefaultWebProxy) { [Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultNetworkCredentials } } catch { } $feed = if ($env:STRATA_FEED) { $env:STRATA_FEED } else { 'https://github.com/Niko1221/Strata/releases/latest/download' } $feed = $feed.TrimEnd('/') @@ -30,7 +33,7 @@ if (-not $feed) { } if ([Environment]::OSVersion.Platform -ne 'Win32NT') { Die 'this is the Windows installer; on Linux or macOS use install.sh.' } $arch = $env:PROCESSOR_ARCHITEW6432; if (-not $arch) { $arch = $env:PROCESSOR_ARCHITECTURE } -if ($arch -ne 'AMD64') { Die "this computer ($arch) has no Strata Terminal yet. Supported: Windows on x64." } +if ($arch -ne 'AMD64') { Die "this computer ($arch) is a Windows on ARM PC. Strata needs an NVIDIA or AMD graphics card and has no engine for ARM processors, so it could not run a model here. Run this installer on a Windows PC with an Intel or AMD processor (x64) and one of those cards." } $platform = 'windows-x86_64' $gpu = '' # a discrete card is named before a built-in one (a Ryzen's "AMD Radeon(TM) Graphics" is listed first on many PCs); this line is only for the person to read @@ -39,12 +42,13 @@ Write-Host 'Strata Terminal installer' Write-Host " This computer: Windows $arch ($platform)$(if ($gpu) { ", graphics: $gpu" })" Write-Host " Release folder: $feed" +if (-not $env:STRATA_DATA_DIR -and -not $env:LOCALAPPDATA) { Die 'Windows did not say where your user folder is. Set $env:STRATA_DATA_DIR to a folder you own, for example $env:STRATA_DATA_DIR=''C:\Strata'', and run this again.' } $data = if ($env:STRATA_DATA_DIR) { $env:STRATA_DATA_DIR } else { Join-Path $env:LOCALAPPDATA 'Strata' } $work = Join-Path ([IO.Path]::GetTempPath()) ("strata-install-" + [Guid]::NewGuid().ToString('N').Substring(0, 8)) New-Item -ItemType Directory -Path $work | Out-Null try { try { Invoke-WebRequest -UseBasicParsing -Uri "$feed/install-manifest.txt" -OutFile (Join-Path $work 'manifest.txt') } - catch { Die "could not read $feed/install-manifest.txt. Check the address and your internet connection." } + catch { Die "could not read $feed/install-manifest.txt ($($_.Exception.Message)). Check the address and your internet connection; behind a company proxy or firewall, ask for the release folder to be allowed." } $line = Get-Content (Join-Path $work 'manifest.txt') | Where-Object { $_ -match "^$platform\s" } | Select-Object -First 1 if (-not $line) { Die "this release has no Terminal for $platform." } $f = -split $line @@ -53,7 +57,7 @@ try { Write-Host 'Downloading...' $zip = Join-Path $work 'terminal.zip' try { Invoke-WebRequest -UseBasicParsing -Uri "$feed/$rel" -OutFile $zip } - catch { Die 'the download failed. Check your internet connection and run this again; nothing was installed.' } + catch { Die "the download failed ($($_.Exception.Message)). Check your internet connection and run this again; nothing was installed." } $got = (Get-FileHash -Algorithm SHA256 $zip).Hash.ToLower() if ($got -ne $want) { Die "the download does not match the release's checksum (got $got, wanted $want). It was not installed; try again." } Write-Host ' Checksum ok.' @@ -62,8 +66,17 @@ try { $incoming = "$dest.incoming" New-Item -ItemType Directory -Force -Path (Join-Path $data 'terminal') | Out-Null if (Test-Path $incoming) { Remove-Item -Recurse -Force $incoming } - try { Expand-Archive -LiteralPath $zip -DestinationPath $incoming -Force } - catch { Die 'the archive could not be unpacked (is the disk full?). Nothing was installed.' } + $tooLong = 'If it says a path is too long, set $env:STRATA_DATA_DIR to a short folder such as C:\Strata and run this again; otherwise check the free disk space.' + try { + # tar.exe (Windows 10 1803 and later) handles long paths; Expand-Archive in Windows PowerShell 5.1 does not + $tar = Get-Command tar.exe -ErrorAction SilentlyContinue + if ($tar) { + New-Item -ItemType Directory -Force -Path $incoming | Out-Null + $tarOut = & $tar.Source -xf $zip -C $incoming 2>&1 | Out-String + if ($LASTEXITCODE -ne 0) { throw $tarOut.Trim() } + } else { Expand-Archive -LiteralPath $zip -DestinationPath $incoming -Force } + } + catch { Remove-Item -Recurse -Force $incoming -ErrorAction SilentlyContinue; Die "the archive could not be unpacked ($($_.Exception.Message)). $tooLong Nothing was installed." } # the archive of a release folder is rooted at the bundle itself (control package) or in one folder (terminal archive) if (-not (Test-Path (Join-Path $incoming 'bin\strata.cmd'))) { $inner = Get-ChildItem $incoming -Directory | Where-Object { Test-Path (Join-Path $_.FullName 'bin\strata.cmd') } | Select-Object -First 1 @@ -89,11 +102,25 @@ try { } Write-Host ' Signature ok.' - if (Test-Path $dest) { Remove-Item -Recurse -Force $dest } + if (Test-Path $dest) { + try { Remove-Item -Recurse -Force $dest } + catch { Remove-Item -Recurse -Force $incoming -ErrorAction SilentlyContinue; Die "Strata $version is already installed and a program is using it (a Strata window or server is running). Close it (run: strata launch --stop), then run this again. Nothing was changed." } + } Move-Item $incoming $dest $current = Join-Path $data 'terminal\current' if (Test-Path $current) { cmd /c rmdir "$current" | Out-Null } cmd /c mklink /J "$current" "$dest" | Out-Null + if ($LASTEXITCODE -ne 0 -or -not (Test-Path (Join-Path $current 'bin\strata.cmd'))) { + # a drive that cannot hold a junction (not NTFS) or a policy that forbids it: a small launcher in its place does the same job + try { + if (Test-Path $current) { Remove-Item -Recurse -Force $current -ErrorAction SilentlyContinue } + New-Item -ItemType Directory -Force -Path (Join-Path $current 'bin') | Out-Null + Set-Content -Encoding Ascii -Path (Join-Path $current 'bin\strata.cmd') -Value @('@echo off', ('"' + (Join-Path $dest 'bin\strata.cmd') + '" %*')) + Set-Content -Encoding Ascii -Path (Join-Path $current 'current.txt') -Value $dest + Write-Host ' (this drive could not make a link, so a small launcher was used instead)' + } + catch { Die "Strata was unpacked but its start command could not be set up ($($_.Exception.Message)). Run it directly: $dest\bin\strata.cmd" } + } $bin = Join-Path $current 'bin' if ($env:STRATA_NO_PATH -ne '1') { $user = [Environment]::GetEnvironmentVariable('Path', 'User') diff --git a/tests/terminal/test_install_scripts_env.py b/tests/terminal/test_install_scripts_env.py new file mode 100644 index 00000000..30ea0b5a --- /dev/null +++ b/tests/terminal/test_install_scripts_env.py @@ -0,0 +1,53 @@ +"""install.ps1 / install.sh: an ARM computer is refused with the reason and the way out; the Windows script survives the usual environment trouble.""" + +import os +import shutil +import subprocess +import unittest +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +PS1 = ROOT / "packaging" / "install.ps1" +SH = ROOT / "packaging" / "install.sh" + + +class Text(unittest.TestCase): + def setUp(self): + self.ps1 = PS1.read_text(encoding="utf-8") + self.sh = SH.read_text(encoding="utf-8") + + def test_arm_is_refused_with_a_reason_and_a_next_step(self): + self.assertIn("Windows on ARM PC", self.ps1) + self.assertIn("no engine for ARM", self.ps1) + self.assertNotIn("has no Strata Terminal yet", self.ps1) + self.assertIn("ARM processor", self.sh) + self.assertIn("Apple silicon", self.sh) + + def test_tls12_proxy_sign_in_and_the_real_error_text(self): + self.assertIn("Tls12", self.ps1) + self.assertIn("DefaultNetworkCredentials", self.ps1) + self.assertIn("$($_.Exception.Message)", self.ps1) + + def test_long_paths_junction_and_running_version(self): + self.assertIn("tar.exe", self.ps1) + self.assertIn("STRATA_DATA_DIR to a short folder", self.ps1) + self.assertIn("$LASTEXITCODE -ne 0 -or -not (Test-Path (Join-Path $current", self.ps1) + self.assertIn("a program is using it", self.ps1) + self.assertIn("Windows did not say where your user folder is", self.ps1) + self.assertNotIn("is the disk full?", self.ps1) + + +@unittest.skipUnless(shutil.which("powershell"), "no PowerShell") +class Run(unittest.TestCase): + def test_native_arm_stops_before_any_download(self): + env = dict(os.environ, PROCESSOR_ARCHITECTURE="ARM64", STRATA_FEED="http://127.0.0.1:9") + env.pop("PROCESSOR_ARCHITEW6432", None) + done = subprocess.run(["powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(PS1)], + capture_output=True, text=True, env=env, timeout=120) + self.assertNotEqual(done.returncode, 0) + self.assertIn("Windows on ARM PC", done.stderr + done.stdout) + self.assertNotIn("Downloading", done.stdout) + + +if __name__ == "__main__": + unittest.main()