X-Git-Url: https://vilimpoc.org/repos/dotfiles/blobdiff_plain/7840e3c2b0c54c1d49bd2aa7c717892e8a3669e7..4658d6ddc8aaaa7e6b52fe3939151d3b35ddacab:/setup-windows-with-uac.ps1 diff --git a/setup-windows-with-uac.ps1 b/setup-windows-with-uac.ps1 index 52384d4..4b7ea94 100644 --- a/setup-windows-with-uac.ps1 +++ b/setup-windows-with-uac.ps1 @@ -11,8 +11,8 @@ - OpenSSH Server (sshd) capability: automatic + started + inbound TCP 22 - rsync for Windows (nuket/rsync-windows) in C:\Tools\rsync, on the machine PATH: rsync.exe plus the ssh.exe it runs, out of the release zip for this - architecture (there is no ARM64 zip; ARM64 gets the x64 one, and the - ssh.exe is kept only if it actually starts) + architecture - x86, x64 and arm64 are all published, so both binaries are + native everywhere. The ssh.exe is kept only if it actually starts. - Visual Studio Community (C++ desktop workload, x86/x64 AND ARM64 build tools, Spectre libs, Win11 SDK 26100, and - on x64 only - the WDK VSIX, Clang/LLVM, and the v141 + Windows XP targeting toolset). VS 2022 on x64, @@ -53,7 +53,7 @@ $ErrorActionPreference = 'Stop' # under .NET Framework on Prism it is not, so it is kept only as a fallback. # # $IsArm64 gates: -# - which rsync-windows release zip is fetched (there is no ARM64 one) +# - which rsync-windows release zip is fetched (x86 / x64 / arm64, all native) # - which Visual Studio generation is driven ($VsChannel: 18 on Arm, 17 on x64) # - the Visual Studio component groups: ARM64 build tools in; the v141/XP # toolset out because it has no ARM64-hosted compiler and Microsoft does not @@ -321,20 +321,23 @@ try { # --------------------------------------------------------------------------- Write-Step 'rsync for Windows' $RsyncRepo = 'nuket/rsync-windows' -# The release publishes exactly two assets - x64 and x86 - and no ARM64 one, so -# on ARM64 the x64 build is the right pick: it runs under Prism, and an emulated -# x64 rsync still moves data far faster than the ~17MB/s stdin cap that the whole -# reason for using this build is to avoid. (The transfer is I/O-bound on the -# socket, not on emulated CPU.) Selected off $HostArch rather than -# Is64BitOperatingSystem, which answers "true" on ARM64 and so cannot tell the -# two 64-bit cases apart. +# The release publishes x86, x64 and - since v3.5.0-gdeeda96f - arm64, so every +# architecture this script runs on gets a native build. ARM64 used to take the +# x64 zip under emulation, which was defensible (a transfer is bound by the +# socket, not by emulated CPU) but cost the release's ssh.exe: that x64 binary +# could not load the ARM64 libcrypto.dll in System32 and had to be deleted on +# every run. The arm64 asset ships an ARM64 rsync.exe AND an ARM64 ssh.exe, so +# both halves are now native and the fast client survives. +# +# Selected off $HostArch rather than Is64BitOperatingSystem, which answers "true" +# on ARM64 and so cannot tell the two 64-bit cases apart. $RsyncAsset = switch ($HostArch) { 'X64' { 'rsync-windows-x64.zip' } - 'Arm64' { 'rsync-windows-x64.zip' } + 'Arm64' { 'rsync-windows-arm64.zip' } default { 'rsync-windows-x86.zip' } } if ($IsArm64) { - Write-Host ' ARM64: no native asset is published, using the x64 build under emulation.' -ForegroundColor Yellow + Write-Host ' ARM64: using the native arm64 asset (rsync.exe and ssh.exe both ARM64).' -ForegroundColor Green } # The /releases/latest/download/ redirect rather than the API: unauthenticated # API calls are rate-limited to 60/hour per IP, which a provisioning run behind a @@ -360,15 +363,11 @@ try { if ($v -and ([version]($v -replace '[^0-9.]', '')) -lt [version]'3.8.2') { Write-Warning "$SysCrypto is LibreSSL $v; the release's ssh.exe is built against 3.8.2 (Windows OpenSSH Client 9.5). Update Windows, or expect ssh.exe not to start." } - if ($IsArm64) { - # On ARM64 the presence of libcrypto.dll proves less than it does on - # x64: System32 holds the ARM64 build of it, and the ssh.exe in the - # zip is x64. Whether an emulated x64 process can load that DLL comes - # down to whether it is a plain ARM64 binary or an ARM64X one - not - # something worth deciding by parsing the PE header, when running the - # binary answers it outright. Unpack it, then run it (below). - Write-Host ' ARM64: the x64 ssh.exe will be verified by running it, not by assuming.' -ForegroundColor Yellow - } + # No architecture special-case here any more: the asset chosen above + # matches the host, so the release's ssh.exe and System32's libcrypto.dll + # are the same architecture on every box. The run-it check below still + # happens on all of them - it is cheap, and it is what caught the ARM64 + # mismatch back when this took the x64 zip. } # Download and unpack beside the targets, not over them, so an interrupted @@ -422,11 +421,14 @@ try { # This matters more than it looks. rsync.exe prefers an ssh.exe sitting in its # own directory, so a present-but-unstartable one does not degrade to the # in-box client - it breaks rsync outright, and the error you get is a remote - # shell that died rather than anything naming ssh.exe. The two ways to land - # there are a missing/old System32 libcrypto.dll (x64 boxes) and an ARM64 box - # whose ARM64 libcrypto cannot be loaded by this x64 binary. Removing it is - # the repair in both cases: rsync then falls back to the ssh on the PATH, - # which on ARM64 is the native in-box client. + # shell that died rather than anything naming ssh.exe. The way to land there + # is a missing or too-old System32 libcrypto.dll. Removing it is the repair: + # rsync then falls back to the ssh on the PATH, which is the in-box client. + # + # This also used to fire on every ARM64 run, when the x64 asset was the only + # 64-bit one published and its ssh.exe could not load the ARM64 libcrypto + # (exit 0xC0000135, STATUS_DLL_NOT_FOUND). The arm64 asset fixed that at the + # source; the check stays because it is how that was found in the first place. # # EAP back to Continue for the call: ssh -V writes its version to STDERR, and # under $ErrorActionPreference = 'Stop' a native command's stderr becomes a @@ -434,13 +436,26 @@ try { # $global:LASTEXITCODE is cleared first because an exe that cannot start at # all throws without setting one, and the stale 0 from the previous native # command would otherwise read as success. + # + # DRAIN THE OUTPUT BEFORE READING $LASTEXITCODE. `... | Select-Object -First 1` + # was the original spelling here, and it is a trap: Select-Object stops the + # pipeline the instant it has its one object, and that is when ssh.exe has + # WRITTEN its banner - not when it has exited. PowerShell then tears the + # pipeline down, kills the still-running process, and reports -1. Measured on a + # healthy binary on an x64 box: 24 of 25 runs reported exit -1 through + # Select-Object, and 25 of 25 reported 0 when the output was collected first. + # + # So this check was deleting a perfectly good ssh.exe on almost every run, on + # every architecture, and the resulting fallback to the in-box client - the + # ~17MB/s one this whole step exists to avoid - looked like a property of the + # release rather than a bug in the test. Collect, THEN take the first line. $SshExe = Join-Path $RsyncDir 'ssh.exe' if ($WantSsh -and (Test-Path $SshExe)) { $prevEap = $ErrorActionPreference $ErrorActionPreference = 'Continue' $global:LASTEXITCODE = $null $sshVer = $null - try { $sshVer = (& $SshExe -V 2>&1 | Select-Object -First 1) } catch { } + try { $sshOut = (& $SshExe -V 2>&1); $sshVer = $sshOut | Select-Object -First 1 } catch { } finally { $ErrorActionPreference = $prevEap } if ($LASTEXITCODE -eq 0) { Write-Host " ssh.exe runs: $sshVer"