]> vilimpoc.org git repositories - dotfiles/blame - setup-windows.bat
dotfiles: Windows XP VM provisioning
[dotfiles] / setup-windows.bat
CommitLineData
3c096107
MV
1@echo off\r
2\r
3@rem ---------------------------------------------------------------------------\r
452f525c 4@rem setup-windows.bat - provision a fresh Windows box for native development\r
3c096107
MV
5@rem ---------------------------------------------------------------------------\r
6\r
7@rem --- Non-admin (per-user) installs + git config ---\r
8winget install Anthropic.ClaudeCode\r
9winget install Git.Git\r
10winget install Microsoft.PowerShell Microsoft.Sysinternals.ProcessExplorer Microsoft.Sysinternals.ProcessMonitor Microsoft.Sysinternals.SDelete Microsoft.VisualStudioCode Microsoft.WindowsTerminal\r
11winget install Python.Python.3.13\r
12winget install WinMerge.WinMerge\r
13winget install WiXToolset.WiXCLI\r
14\r
15@rem OpenCppCoverage: native (PE) line coverage for the C++ binaries. run-coverage-occ.py drives the\r
452f525c 16@rem pytest suite under it to produce an HTML report (the binaries under test build with PDBs,\r
3c096107
MV
17@rem which it reads). The installer elevates via UAC.\r
18winget install OpenCppCoverage.OpenCppCoverage\r
19\r
20@rem --- Add WinMerge to the user PATH (persists to the HKCU environment) ---\r
21@rem Runs non-elevated, so it updates THIS user's PATH (the elevated script runs\r
22@rem as a different account). Idempotent: only appends if not already present.\r
23powershell -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.') }"\r
24\r
25@rem --- BinSkim (binary hardening analyzer) - per-user install, no admin needed ---\r
26@rem BinSkim checks the exact mitigations we enable in CMakeLists.txt (CFG/XFG, CET,\r
27@rem ASLR/HighEntropyVA, DEP, /GS, stack cookies, DEPENDENTLOADFLAG, etc.). The\r
28@rem Microsoft.CodeAnalysis.BinSkim NuGet package ships a self-contained win-x64\r
29@rem build, so this needs no .NET SDK/runtime: download the .nupkg (a zip), extract\r
30@rem the win-x64 tool folder to %LOCALAPPDATA%\Programs\BinSkim, and add it to the\r
452f525c
MV
31@rem user PATH. After restarting the shell: binskim analyze path\to\your.exe\r
32@rem\r
33@rem VERSION CHECK FIRST. The .nupkg is a large download (self-contained .NET), so\r
34@rem we ask NuGet what the newest stable version is BEFORE fetching anything, and\r
35@rem skip the download entirely when the installed copy already matches. The\r
36@rem installed version is recorded in nupkg-version.txt next to the tool; for a\r
37@rem copy installed before that marker existed we fall back to BinSkim.exe's own\r
38@rem ProductVersion, which costs at most one more download and then self-heals.\r
39@rem The flat-container URL pins the exact version we checked, unlike the v2\r
40@rem /package/<id> endpoint, which just redirects to whatever is newest at the\r
41@rem moment of the request.\r
42@rem\r
43@rem The user PATH is refreshed on every run, including the skip path, so a lost\r
44@rem PATH entry is repaired without re-downloading the tool to do it.\r
3c096107 45@rem A failure here only warns (exit 0) so it never aborts the rest of provisioning.\r
452f525c 46powershell -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 }"\r
3c096107
MV
47\r
48@rem --- Global git identity: EDIT THESE BEFORE RUNNING ---\r
49@rem Replace the placeholders with your own name and email, or comment the two\r
50@rem lines out and set your identity per-repository instead.\r
51git config --global user.name "PLACEHOLDER_NAME"\r
52git config --global user.email "PLACEHOLDER_EMAIL"\r
53git config --global core.sshcommand C:/Windows/System32/OpenSSH/ssh.exe\r
54\r
55@rem ---------------------------------------------------------------------------\r
56@rem No package manager needed for the Windows build\r
57@rem\r
58@rem Just:\r
59@rem cd windows && cmake -B build -G "Visual Studio 17 2022" -A x64 && cmake --build build --config Release\r
60@rem ---------------------------------------------------------------------------\r
61\r
62@rem --- Elevated installs (VS2022, WDK, system tools) ---\r
63@rem The elevated script runs in its own window and logs to setup-windows-uac.log.\r
64@rem -PassThru + $p.ExitCode propagates its real exit code back through to ERRORLEVEL.\r
65set "UAC_LOG=%~dp0setup-windows-uac.log"\r
66if exist "%UAC_LOG%" del "%UAC_LOG%"\r
67\r
68powershell -NoProfile -Command "$p = Start-Process powershell -Verb RunAs -ArgumentList '-NoProfile','-ExecutionPolicy','Bypass','-File','""%~dp0setup-windows-with-uac.ps1""' -Wait -PassThru; exit $p.ExitCode"\r
69set "UAC_RC=%ERRORLEVEL%"\r
70\r
71@rem --- Surface the elevated session's output (its window has already closed) ---\r
72if exist "%UAC_LOG%" (\r
73 echo.\r
74 echo ===== elevated setup log ^(%UAC_LOG%^) =====\r
75 type "%UAC_LOG%"\r
76 echo ===== end of elevated setup log =====\r
77) else (\r
78 echo [setup-windows] WARNING: no elevated log found at "%UAC_LOG%".\r
79 echo [setup-windows] The elevated window may have been cancelled at the UAC prompt.\r
80)\r
81\r
82if not "%UAC_RC%"=="0" (\r
83 echo.\r
84 echo [setup-windows] ELEVATED SETUP FAILED ^(exit code %UAC_RC%^). See log above.\r
85 exit /b %UAC_RC%\r
86)\r
87echo.\r
88echo [setup-windows] Elevated setup completed successfully.\r
89\r
90@rem Removed: this doesn't work as well as I hoped, maybe try again later\r
91@rem -- Install Headroom ---\r
92@rem py -m pip install "headroom-ai[all]"\r
93@rem npm install headroom-ai\r
94\r
95py -m pip install Pillow