-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdevboot.ps1
More file actions
133 lines (119 loc) · 6.33 KB
/
devboot.ps1
File metadata and controls
133 lines (119 loc) · 6.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#requires -RunAsAdministrator
<#
.SYNOPSIS
Bootstrap script to set up and run WinGet configuration for developer workstations.
.DESCRIPTION
This script automates the setup of WinGet and runs a configuration file to install development tools.
.PARAMETER Configuration
Specifies which configuration to use. Valid values are:
- 'default': Standard configuration with Visual Studio Professional (configuration.dsc.yaml)
- 'minimal': Minimal configuration without Visual Studio (configuration.dsc.minimal.yaml)
- 'withDockerDesktop': Configuration including Docker Desktop (configuration.dsc.withDockerDesktop.yaml)
.EXAMPLE
.\devboot.ps1
Runs with the default configuration.
.EXAMPLE
.\devboot.ps1 -Configuration minimal
Runs with the minimal configuration.
.EXAMPLE
.\devboot.ps1 -Configuration withDockerDesktop
Runs with the Docker Desktop configuration.
#>
param(
[ValidateSet('default', 'minimal', 'withDockerDesktop')]
[string]$Configuration = 'default'
)
# Map configuration names to file names
$configFiles = @{
'default' = 'configuration.dsc.yaml'
'minimal' = 'configuration.dsc.minimal.yaml'
'withDockerDesktop' = 'configuration.dsc.withDockerDesktop.yaml'
}
$selectedConfigFile = $configFiles[$Configuration]
Write-Host "Using configuration: $Configuration ($selectedConfigFile)"
# Check/create/switch to devboot folder
$userorg = "dmealo"
$drive = Get-PsDrive -PsProvider FileSystem | Select-Object -First 1 | Select-Object -ExpandProperty Name
$devbootPath = $drive + ':\devboot'
if (!(Test-Path $devbootPath)) {
mkdir $devbootPath
mkdir $devbootPath\.winget
}
if (!(Test-Path $devbootPath\.winget)) {
mkdir $devbootPath\.winget
}
if (!(Test-Path $devbootPath\.winget\install)) {
mkdir $devbootPath\.winget\install
}
if (!(Test-Path $devbootPath\.vsconfig)) {
mkdir $devbootPath\.vsconfig
}
if (!(Test-Path $devbootPath\.vsconfig\VS2022)) {
mkdir $devbootPath\.vsconfig\VS2022
}
# Get version number of latest release version of winget
$latestRelease = Invoke-RestMethod -Uri https://api.github.com/repos/microsoft/winget-cli/releases | ConvertTo-Json -Depth 100 | ConvertFrom-Json | Where-Object { $_.prerelease -eq $false } | Select-Object -First 1 | Select-Object -ExpandProperty tag_name
# Skip installation if latest already installed
$wingetCurrentVersion = winget --version
if ($wingetCurrentVersion -ge $latestRelease) {
Write-Host "Latest winget release version ($latestRelease) already installed (installed version: $wingetCurrentVersion; ignore following settings error prefixing version number display `
if settings not initialized by a previous run): $wingetCurrentVersion"
}
else {
# Display latest winget release version and current installed version
Write-Host "Latest winget release version: $latestRelease; installed version: $wingetCurrentVersion"
# Install latest winget release version
Push-Location $devbootPath\.winget\install
$downloadUrl = (([System.Net.HttpWebRequest]::Create('https://github.com/microsoft/winget-cli/releases/latest/').GetResponse().ResponseUri.AbsoluteUri) -Replace 'tag', 'download') + '/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle'
Start-BitsTransfer -Source $downloadUrl -Destination Microsoft.DesktopAppInstaller.msixbundle
$wingetPreviewInstaller = Get-ChildItem -Filter Microsoft.DesktopAppInstaller*.msixbundle | Sort-Object LastWriteTime | Select-Object -Last 1 | Select-Object -ExpandProperty FullName
Add-AppxPackage -Path $wingetPreviewInstaller
Pop-Location
}
# # Deprecated by general release of WinGet Configurations without requiring enablement of experimental settings
# # Check/add 'configuration' experimental setting to winget settings file
# $wingetSettingsFilePath = "$env:LocalAppData\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\"
# $settingsFileName = "settings.json"
# $wingetSettingsFilePathFull = $wingetSettingsFilePath + $settingsFileName
# $wingetSettingsFile = Get-ChildItem -Path $env:LocalAppData\Packages\Microsoft.DesktopAppInstaller*\LocalState\settings.json | Select-Object -ExpandProperty FullName
# if ($null -eq $wingetSettingsFile) {
# Write-Host "Could not find winget settings file; creating a new one"
# # Create new empty winget settings file
# New-Item -Path $wingetSettingsFilePath -Name $settingsFileName -ItemType File
# $fileModel = New-Object -TypeName PSObject
# $fileModel | Add-Member -MemberType NoteProperty -Name '$schema' -Value 'https://aka.ms/winget-settings.schema.json'
# $fileModel | ConvertTo-Json | Set-Content $wingetSettingsFilePathFull
# $wingetSettingsFile = Get-ChildItem -Path $wingetSettingsFilePathFull
# }
# $settings = Get-Content -Raw $wingetSettingsFile | ConvertFrom-Json
# $experimentalFeaturesSettings = $settings.experimentalFeatures
# if ($null -eq $experimentalFeaturesSettings) {
# $settings | Add-Member -MemberType NoteProperty -Name experimentalFeatures -Value @{}
# $settings.experimentalFeatures = @{'configuration'=$true}
# }
# else {
# $experimentalFeatures = $settings.experimentalFeatures
# if ($null -eq $experimentalFeatures.configuration) {
# $experimentalFeatures | Add-Member -MemberType NoteProperty -Name configuration -Value $true
# }
# else {
# if ($experimentalFeatures.configuration -eq $false) {
# $experimentalFeatures.configuration = $true
# }
# }
# }
# $settings | ConvertTo-Json | Set-Content $wingetSettingsFile
# Download winget configuration and dependencies (.vsconfig, etc.)
Push-Location $devbootPath
$baseGitHubUrl = "https://raw.githubusercontent.com/$userorg/devboot/main"
# Download .vsconfig only for non-minimal configurations (minimal doesn't install Visual Studio)
if ($Configuration -ne 'minimal') {
Start-BitsTransfer -Source "$baseGitHubUrl/.vsconfig/VS2022/.vsconfig" -Destination .vsconfig/VS2022/.vsconfig
}
# Download the selected configuration file
$configUrl = "$baseGitHubUrl/.winget/$selectedConfigFile"
Start-BitsTransfer -Source $configUrl -Destination .winget/$selectedConfigFile
# Run winget configure using selected configuration file with verbose output, and opening logs folder after run
# Note: using --disable-interactivity to interactive prompts other than agreeing to configuration warning causes Notepad++ and possibly other apps to fail to install, so removed for now
& winget configure -f .winget\$selectedConfigFile --verbose --logs
Pop-Location