From cdb3237533788f631f4078c503065c287c185a1a Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 13 Jan 2025 13:59:02 +0100 Subject: [PATCH] Shorten copy&paste commands needed to get a Windows dev env by integrating Enable-WindowsOptionalFeature ... into doc/win-dev.ps1. --- doc/21-development.md | 7 +------ doc/win-dev.ps1 | 13 +++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/21-development.md b/doc/21-development.md index 3cfec12d53..258fe4491b 100644 --- a/doc/21-development.md +++ b/doc/21-development.md @@ -1736,12 +1736,7 @@ and don't care for the details, 1. ensure there are 35 GB free space on C: 2. run the following in an administrative Powershell: - 1. Windows Server only: - `Enable-WindowsOptionalFeature -FeatureName NetFx3ServerFeatures -Online` - 2. `Enable-WindowsOptionalFeature -FeatureName NetFx3 -Online` - (reboot when asked!) - 3. `powershell -NoProfile -ExecutionPolicy Bypass -Command "Invoke-Expression (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/Icinga/icinga2/master/doc/win-dev.ps1')"` - (will take some time) + `powershell -nop -ep bypass -c "iex (iwr 'https://raw.githubusercontent.com/Icinga/icinga2/master/doc/win-dev.ps1')"` This installs everything needed for cloning and building Icinga 2 on the command line (Powershell) as follows: diff --git a/doc/win-dev.ps1 b/doc/win-dev.ps1 index f64017bb0c..21a56ba61f 100644 --- a/doc/win-dev.ps1 +++ b/doc/win-dev.ps1 @@ -57,6 +57,19 @@ function Install-Exe { } +function Needs-WinFeatureRestart($feature) { + (Enable-WindowsOptionalFeature -FeatureName $feature -Online).RestartNeeded +} + + +$isServer = (Get-CimInstance -ClassName Win32_OperatingSystem).Caption -match 'Windows Server' +$serverNeedsRestart = $isServer -and (Needs-WinFeatureRestart NetFx3ServerFeatures) +$needsRestart = Needs-WinFeatureRestart NetFx3 + +if ($serverNeedsRestart -or $needsRestart) { + throw 'Restart needed' +} + try { Get-Command choco } catch {