Debian Codegraph @

scripts/windows/Setup.ps1

raw
1 # Configure a fresh installation of Windows via SSH.
2
3 param (
4 [switch] $RunOnce = $false
5 )
6
7 if ($RunOnce) {
8 # Visual Studio really doesn't seem to like being installed via SSH, so
9 # we invoke from a RunOnce script.
10 Invoke-WebRequest 'https://raw.githubusercontent.com/microsoft/ebpf-for-windows/main/scripts/Setup-DevEnv.ps1' -OutFile $env:TEMP\Setup-DevEnv.ps1
11 &"$env:TEMP\Setup-DevEnv.ps1"
12
13 # sshd needs to be restarted to pick up new environment variables.
14 Restart-Service sshd
15
16 return
17 }
18
19 # Enable Developer Mode (so that symlinks work)
20 # See https://stackoverflow.com/a/40033638
21 $RegistryKeyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
22 New-Item -Path $RegistryKeyPath -ItemType Directory -Force
23 New-ItemProperty -Path $RegistryKeyPath -Name AllowDevelopmentWithoutDevLicense -PropertyType DWORD -Value 1 -Force
24
25 # Ensure we have a PROFILE.
26 #
27 # This also allows chocolatey to add its hooks.
28 if (!(Test-Path -Path $PROFILE)) {
29 New-Item -ItemType File -Path $PROFILE -Force
30 }
31
32 # Add VS tools to PATH
33 $addVsToolsToPath = @'
34 # Add VS to PATH
35 function Import-VsEnv {
36 $vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
37 $vspath = & $vswherePath -property installationPath
38 $vsDevShell = "${vspath}\Common7\Tools\Launch-VsDevShell.ps1"
39 & $vsDevShell -SkipAutomaticLocation
40 }
41 '@
42
43 if (-not (Get-Content $PROFILE | Select-String "Add VS to PATH")) {
44 $addVsToolsToPath | Add-Content -Path $PROFILE
45 }
46
47 # Enable git symlink support globally.
48 $gitConfig = "${HOME}/.gitconfig"
49 if (!(Test-Path -Path $gitConfig)) {
50 New-Item -ItemType File -Path $gitConfig -Force
51 }
52
53 if (-not (Get-Content $gitConfig | Select-String "symlinks = true")) {
54 @'
55 [core]
56 symlinks = true
57 '@ | Add-Content -Path $gitConfig
58 }
59
60 # Install winget version which supports configure -f
61 # if ([version]($(winget --version).substring(1)) -lt [version]'1.6.0') {
62 # echo "Updating winget"
63 # # From https://andrewstaylor.com/2023/11/28/winget-powershell-module/
64 # Get-PackageProvider NuGet -ForceBootstrap | Out-Null
65 # install-module microsoft.winget.client -Force -AllowClobber
66 # import-module microsoft.winget.client
67 # repair-wingetpackagemanager -Force -Latest -AllUsers
68 # }
69
70 echo "Scheduling installation of eBPF for Windows dependencies for next reboot."
71 Set-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name 'InstallEFWDependencies' -Value "powershell.exe -command `"start -verb runas powershell.exe -argumentlist \`"-file $PSCommandPath -RunOnce\`""
72
73 echo "Rebooting."
74 Restart-Computer -Force