X-Git-Url: https://vilimpoc.org/repos/dotfiles/blobdiff_plain/452f525c182a835867d0f229c821c41118d15808..541058e34fa7259b14e8842245e854686037c4af:/setup-windows.bat diff --git a/setup-windows.bat b/setup-windows.bat index ff77716..cc12420 100644 --- a/setup-windows.bat +++ b/setup-windows.bat @@ -4,10 +4,11 @@ @rem setup-windows.bat - provision a fresh Windows box for native development @rem --------------------------------------------------------------------------- -@rem --- Non-admin (per-user) installs + git config --- +@rem --- Non-admin (per-user) winget installs --- winget install Anthropic.ClaudeCode winget install Git.Git winget install Microsoft.PowerShell Microsoft.Sysinternals.ProcessExplorer Microsoft.Sysinternals.ProcessMonitor Microsoft.Sysinternals.SDelete Microsoft.VisualStudioCode Microsoft.WindowsTerminal +winget install Oracle.VirtualBox winget install Python.Python.3.13 winget install WinMerge.WinMerge winget install WiXToolset.WiXCLI @@ -17,41 +18,6 @@ winget install WiXToolset.WiXCLI @rem which it reads). The installer elevates via UAC. winget install OpenCppCoverage.OpenCppCoverage -@rem --- Add WinMerge to the user PATH (persists to the HKCU environment) --- -@rem Runs non-elevated, so it updates THIS user's PATH (the elevated script runs -@rem as a different account). Idempotent: only appends if not already present. -powershell -NoProfile -Command "$c = @((Join-Path $env:ProgramFiles 'WinMerge'), (Join-Path ${env:ProgramFiles(x86)} 'WinMerge'), (Join-Path $env:LOCALAPPDATA 'Programs\WinMerge')); $d = $c | Where-Object { Test-Path (Join-Path $_ 'WinMergeU.exe') } | Select-Object -First 1; if (-not $d) { Write-Warning 'WinMerge not found; user PATH unchanged.'; exit 0 }; $u = [Environment]::GetEnvironmentVariable('Path','User'); if (-not $u) { $u = '' }; if (($u -split ';') -notcontains $d) { $new = if ($u.Trim()) { $u.TrimEnd(';') + ';' + $d } else { $d }; [Environment]::SetEnvironmentVariable('Path', $new, 'User'); Write-Host ('Added ' + $d + ' to user PATH (restart your shell to pick it up).') } else { Write-Host ($d + ' already in user PATH.') }" - -@rem --- BinSkim (binary hardening analyzer) - per-user install, no admin needed --- -@rem BinSkim checks the exact mitigations we enable in CMakeLists.txt (CFG/XFG, CET, -@rem ASLR/HighEntropyVA, DEP, /GS, stack cookies, DEPENDENTLOADFLAG, etc.). The -@rem Microsoft.CodeAnalysis.BinSkim NuGet package ships a self-contained win-x64 -@rem build, so this needs no .NET SDK/runtime: download the .nupkg (a zip), extract -@rem the win-x64 tool folder to %LOCALAPPDATA%\Programs\BinSkim, and add it to the -@rem user PATH. After restarting the shell: binskim analyze path\to\your.exe -@rem -@rem VERSION CHECK FIRST. The .nupkg is a large download (self-contained .NET), so -@rem we ask NuGet what the newest stable version is BEFORE fetching anything, and -@rem skip the download entirely when the installed copy already matches. The -@rem installed version is recorded in nupkg-version.txt next to the tool; for a -@rem copy installed before that marker existed we fall back to BinSkim.exe's own -@rem ProductVersion, which costs at most one more download and then self-heals. -@rem The flat-container URL pins the exact version we checked, unlike the v2 -@rem /package/ endpoint, which just redirects to whatever is newest at the -@rem moment of the request. -@rem -@rem The user PATH is refreshed on every run, including the skip path, so a lost -@rem PATH entry is repaired without re-downloading the tool to do it. -@rem A failure here only warns (exit 0) so it never aborts the rest of provisioning. -powershell -NoProfile -Command "try { $ErrorActionPreference='Stop'; [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; $dest=Join-Path $env:LOCALAPPDATA 'Programs\BinSkim'; $exe=Join-Path $dest 'BinSkim.exe'; $mark=Join-Path $dest 'nupkg-version.txt'; $have=$null; if (Test-Path $exe) { if (Test-Path $mark) { $have=(Get-Content $mark -Raw).Trim() } else { $pv=(Get-Item $exe).VersionInfo.ProductVersion; if ($pv) { $have=$pv.Split('+')[0].Trim() } } }; $latest=$null; try { $idx=Invoke-RestMethod -Uri 'https://api.nuget.org/v3-flatcontainer/microsoft.codeanalysis.binskim/index.json' -UseBasicParsing; $latest=$idx.versions | Where-Object { $_ -notmatch '-' } | Select-Object -Last 1 } catch { Write-Warning ('BinSkim version check failed: '+$_.Exception.Message) }; if (-not $latest) { if ($have) { Write-Host ('BinSkim '+$have+' kept (could not reach NuGet to check for a newer one).') } else { Write-Warning 'BinSkim not installed and NuGet unreachable; skipping.'; exit 0 } } elseif ($have -and ($have -eq $latest -or $have -eq ($latest+'.0'))) { Write-Host ('BinSkim '+$have+' is already the newest stable release; skipping download.') } else { if ($have) { Write-Host ('BinSkim '+$have+' -> '+$latest+'; downloading.') } else { Write-Host ('BinSkim '+$latest+'; downloading.') }; $tmp=Join-Path $env:TEMP ('binskim_'+[guid]::NewGuid().ToString('N')); New-Item -ItemType Directory -Force -Path $tmp | Out-Null; $zip=Join-Path $tmp 'binskim.zip'; Invoke-WebRequest -Uri ('https://api.nuget.org/v3-flatcontainer/microsoft.codeanalysis.binskim/'+$latest+'/microsoft.codeanalysis.binskim.'+$latest+'.nupkg') -OutFile $zip -UseBasicParsing; Expand-Archive -Path $zip -DestinationPath $tmp -Force; $src=Get-ChildItem -Path $tmp -Recurse -Filter 'BinSkim.exe' | Where-Object { $_.FullName -match 'win-x64' } | Sort-Object FullName | Select-Object -Last 1; if (-not $src) { throw 'BinSkim.exe (win-x64) not found in package.' }; if (Test-Path $dest) { Remove-Item -Recurse -Force $dest }; New-Item -ItemType Directory -Force -Path $dest | Out-Null; Copy-Item -Path (Join-Path $src.Directory.FullName '*') -Destination $dest -Recurse -Force; Remove-Item -Recurse -Force $tmp; Set-Content -Path $mark -Value $latest -Encoding ascii; Write-Host ('BinSkim '+$latest+' installed to '+$dest) }; $u=[Environment]::GetEnvironmentVariable('Path','User'); if (-not $u) { $u='' }; if (($u -split ';') -notcontains $dest) { $new = if ($u.Trim()) { $u.TrimEnd(';')+';'+$dest } else { $dest }; [Environment]::SetEnvironmentVariable('Path',$new,'User'); Write-Host ('Added '+$dest+' to user PATH (restart your shell to pick it up).') } else { Write-Host ($dest+' already in user PATH.') } } catch { Write-Warning ('BinSkim install failed: '+$_.Exception.Message); exit 0 }" - -@rem --- Global git identity: EDIT THESE BEFORE RUNNING --- -@rem Replace the placeholders with your own name and email, or comment the two -@rem lines out and set your identity per-repository instead. -git config --global user.name "PLACEHOLDER_NAME" -git config --global user.email "PLACEHOLDER_EMAIL" -git config --global core.sshcommand C:/Windows/System32/OpenSSH/ssh.exe - @rem --------------------------------------------------------------------------- @rem No package manager needed for the Windows build @rem @@ -79,6 +45,27 @@ if exist "%UAC_LOG%" ( echo [setup-windows] The elevated window may have been cancelled at the UAC prompt. ) +@rem --- Non-elevated PowerShell half --- +@rem WinMerge on the user PATH, BinSkim, and the global git config (identity + +@rem core.sshCommand -> a Win32-OpenSSH client, so git shares the Windows +@rem ssh-agent). EDIT THE GIT IDENTITY at the top of setup-windows-no-uac.ps1 +@rem before the first run. +@rem +@rem Deliberately NOT elevated: every step writes per-user state (the HKCU PATH, +@rem the .gitconfig under %USERPROFILE%), which the elevated half would write to +@rem the administrator profile instead. +@rem +@rem AFTER the elevated half on purpose: core.sshCommand prefers the ssh.exe that +@rem half unpacks beside rsync.exe - a push through the in-box client is capped +@rem at ~17MB/s - and it can only prefer it once it is on disk. Run either way, +@rem including when the elevated half failed above: nothing here depends on it, +@rem and the fallback is the in-box client that Windows already has. +@rem +@rem Non-fatal: these are conveniences, and the elevated half is the part worth +@rem the UAC prompt. A failure warns and provisioning continues. +powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0setup-windows-no-uac.ps1" +if not "%ERRORLEVEL%"=="0" echo [setup-windows] WARNING: setup-windows-no-uac.ps1 reported a failure ^(see above^); continuing. + if not "%UAC_RC%"=="0" ( echo. echo [setup-windows] ELEVATED SETUP FAILED ^(exit code %UAC_RC%^). See log above.