Commit 3d62fc8b authored by Volker Hilsheimer's avatar Volker Hilsheimer
Browse files

Consolidate package installation on Windows

parent bcdebe87
......@@ -3,8 +3,6 @@ param (
[string]$package = "mingw"
)
write-host "Installing ${package} version ${version}"
. "c:\opt\minicoin\util\install_helper.ps1"
cd "$($env:SystemDrive)\ProgramData\Chocolatey\bin"
.\choco install --no-progress -y $package --version $version
Install-Software $package $version
param (
[String[]]$Version = "2022"
[String]$Version = "2022"
)
$variables = @{
......@@ -32,21 +32,7 @@ $packages = (
chocolatey feature enable -n=allowGlobalConfirmation
ForEach ( $p in $packages ) {
$measurement = Measure-Command {
Run-KeepAlive -ScriptBlock {
param($package)
write-host "Installing $package"
& chocolatey install --no-progress --limitoutput -y $package | Out-Default
write-host "Done Installing $package"
} -Arguments $p -HeartBeat 30
}
$duration = ""
if ($measurement.TotalMinutes -lt 1) {
$duration = "$($measurement.TotalSeconds) Seconds"
} else {
$duration = $measurement.ToString("hh\:mm\:ss")
}
Write-Host "Installation of $p completed after $duration"
Install-Software $p
}
$vc_workloads = (
......@@ -55,21 +41,11 @@ $vc_workloads = (
)
ForEach ( $p in $vc_workloads ) {
$measurement = Measure-Command {
Run-KeepAlive -ScriptBlock {
param($package)
write-host "Installing Visual Studio component $package"
& "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" modify --norestart --quiet --productId Microsoft.VisualStudio.Product.BuildTools --channelId $channelId --add $package | Out-Default
write-host "Done Installing $package"
} -Arguments $p -HeartBeat 30
}
$duration = ""
if ($measurement.TotalMinutes -lt 1) {
$duration = "$($measurement.TotalSeconds) Seconds"
} else {
$duration = $measurement.ToString("hh\:mm\:ss")
}
Write-Host "Installation of $p completed after $duration"
Install-Software -package $p -command "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" -arguments @(
"modify", "--norestart", "--quiet",
"--productId", "Microsoft.VisualStudio.Product.BuildTools",
"--channelId", "$channelId", "--add"
)
}
chocolatey feature disable -n=allowGlobalConfirmation
......
function Set-RegistryKey
{
param(
[string]$Path,
[string]$Key,
[int]$Value
function UpdateRegistry {
param (
[parameter(Mandatory=$true)]
[String]$Path,
[parameter(Mandatory=$true)]
[String]$Name,
[String]$Text,
[String]$Number
)
if (!(Test-Path $Path)) {
New-Item -Path $Path -Force | Out-Null
}
New-ItemProperty -Path $Path -Name $Key -Value $Value -Type DWORD -Force | Out-Null
if ($Text) {
New-ItemProperty -Path $Path -Name $Name -Value $Text -PropertyType String -Force | Out-Null
} elseif ($Number) {
New-ItemProperty -Path $Path -Name $Name -Value $Number -PropertyType DWORD -Force | Out-Null
} else {
New-ItemProperty -Path $Path -Name $Name | Out-Null
}
}
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force | Out-Null
Set-RegistryKey -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender" -Key "DisableAntiSpyware" -Value 1
Set-RegistryKey -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Notifications" -Key "DisableEnhancedNotifications" -Value 1
Set-RegistryKey -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Notifications" -Key "DisableNotifications" -Value 1
Set-RegistryKey -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\Explorer" -Key "DisableNotificationCenter" -Value 1
Set-RegistryKey -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\UserProfileEngagement" -Key "ScoobeSystemSettingEnabled" -Value 0
Set-RegistryKey -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\PushNotifications" -Key "ToastEnabled" -Value 0
Set-RegistryKey -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\PushNotifications" -Key "NoToastApplicationNotification" -Value 1
Set-RegistryKey -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\PushNotifications" -Key "NoToastApplicationNotificationOnLockScreen" -Value 1
UpdateRegistry -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "NoAutoUpdate" -Number 1
UpdateRegistry -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" -Name "DefaultUserName" -Text "vagrant"
UpdateRegistry -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" -Name "DefaultPassword" -Text "vagrant"
UpdateRegistry -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" -Name "AutoAdminLogon" -Text "1"
UpdateRegistry -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Text "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" | Out-Null
UpdateRegistry -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender" -Name "DisableAntiSpyware" -Number 1
UpdateRegistry -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Notifications" -Name "DisableEnhancedNotifications" -Number 1
UpdateRegistry -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Notifications" -Name "DisableNotifications" -Number 1
UpdateRegistry -Path "HKCU:\SOFTWARE\Policies\Microsoft\Windows\Explorer" -Name "DisableNotificationCenter" -Number 1
UpdateRegistry -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\UserProfileEngagement" -Name "ScoobeSystemSettingEnabled" -Number 0
UpdateRegistry -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "ToastEnabled" -Number 0
UpdateRegistry -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "NoToastApplicationNotification" -Number 1
UpdateRegistry -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "NoToastApplicationNotificationOnLockScreen" -Number 1
param (
[String[]]$Packages
)
function UpdateRegistry {
param (
[parameter(Mandatory=$true)]
[String]$Path,
[parameter(Mandatory=$true)]
[String]$Name,
[String]$Text,
[String]$Number
)
if (!(Test-Path $Path)) {
New-Item -Path $Path -Force | Out-Null
}
if ($Text) {
New-ItemProperty -Path $Path -Name $Name -Value $Text -PropertyType String -FORCE | Out-Null
} elseif ($Number) {
New-ItemProperty -Path $Path -Name $Name -Value $Number -PropertyType DWORD -FORCE | Out-Null
} else {
New-ItemProperty -Path $Path -Name $Name | Out-Null
}
}
UpdateRegistry -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "NoAutoUpdate" -Number 1
UpdateRegistry -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" -Name "DefaultUserName" -Text "vagrant"
UpdateRegistry -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" -Name "DefaultPassword" -Text "vagrant"
UpdateRegistry -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" -Name "AutoAdminLogon" -Text "1"
IF(!(Test-Path C:\Users\vagrant\bin)) {
New-Item -Type Directory -Path C:\Users\vagrant\bin | Out-Null
}
......@@ -52,26 +21,15 @@ $oldpath = [Environment]::GetEnvironmentVariable("PATH",[System.EnvironmentVaria
cd $ChocoInstallPath
if (!$Packages) {
$Packages = ( "notepadplusplus", "git", "pstools",
"strawberryperl", "python2",
"cmake", "ninja" )
} else {
$Packages = $Packages.split(",")
}
$Packages = ( "notepadplusplus", "git", "pstools",
"strawberryperl", "python2",
"cmake", "ninja" )
. "c:\opt\minicoin\util\install_helper.ps1"
chocolatey feature enable -n=allowGlobalConfirmation
ForEach ( $p in $packages ) {
$measurement = Measure-Command {
& chocolatey install --no-progress --limitoutput -y $p | Out-Default
}
if ($measurement.TotalMinutes -lt 1) {
$duration = "$($measurement.TotalSeconds) Seconds"
} else {
$duration = $measurement.ToString("hh\:mm\:ss")
}
Write-Host "Installation of $p completed after $duration"
Install-Software $p
}
chocolatey feature disable -n=allowGlobalConfirmation
......
......@@ -8,6 +8,7 @@ function Run-KeepAlive {
$job = Start-Job -ScriptBlock $ScriptBlock -ArgumentList $Arguments
[int] $waitCount = 0
$startTime = $(get-date)
while ($job.State -eq "Running") {
$output = Receive-Job $job
if ($output) {
......@@ -15,8 +16,9 @@ function Run-KeepAlive {
$waitCount = 0
} else {
$waitCount += 1
if ($waitCount -gt $HeartBeat) {
write-host " working..."
if ($waitCount -ge $HeartBeat) {
$elapsedTime = new-timespan $startTime $(get-date)
write-host " $($elapsedTime.ToString("hh\:mm\:ss")) working..."
$waitCount = 0
}
Wait-Job $job -Timeout 1
......@@ -38,3 +40,34 @@ function Invoke-CmdScript {
Set-Item env:$varName -Value $varValue
}
}
function Install-Software {
param(
[Parameter(Mandatory)][String] $package,
[String] $version,
[String] $command="chocolatey",
[String[]] $arguments=@("install", "--no-progress", "--limitoutput", "-y"),
[String] $versionSelect="--version"
)
write-host -NoNewline "Installing ${package}"
$arguments += @($package)
if ( $version -ne "" ) {
write-host -NoNewline " version ${version}"
$arguments+=@($versionSelect, $version)
}
write-host "."
$measurement = Measure-Command {
Run-KeepAlive -ScriptBlock {
param($command, $arguments)
& ${command} ${arguments} | Out-Default
} -Arguments @($command, $arguments) -HeartBeat 30
}
$duration = ""
if ($measurement.TotalMinutes -lt 1) {
$duration = "$($measurement.TotalSeconds) Seconds"
} else {
$duration = $measurement.ToString("hh\:mm\:ss")
}
Write-Host "Installation of $package completed after $duration"
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment