-
Notifications
You must be signed in to change notification settings - Fork 0
/
Initialize-CommandLineInterface.ps1
91 lines (78 loc) · 4.1 KB
/
Initialize-CommandLineInterface.ps1
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
Set-StrictMode -Version Latest
$PSNativeCommandUseErrorActionPreference = $true
if ($PSNativeCommandUseErrorActionPreference) { # always true, this is a linter workaround
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
}
function CheckLastExitCode {
param ([int[]]$SuccessCodes = @(0))
if (!$?) {
if (-not (Test-Path variable://LastExitCode)) {
$LastExitCode = 1
Write-Verbose -Verbose "No LastExitCode found, setting to 1"
}
Write-Verbose -Verbose "Last CMD failed $LastExitCode"
exit
}
if (-not (Test-Path variable://LastExitCode)) {
# Write-Verbose -Verbose "No LastExitCode found, setting to 0"
$LastExitCode = 0
}
if ($SuccessCodes -notcontains $LastExitCode) {
Write-Verbose -Verbose "EXE RETURNED EXIT CODE $LastExitCode"
exit
}
}
$prefix = "$($env:CLI_PREFIX)"
if ($prefix -eq "") {
$prefix = "https://raw.githubusercontent.com/developing-today/cli/main"
Write-Verbose -Verbose "Using default prefix $prefix"
} else {
Write-Verbose -Verbose "Using custom prefix $prefix"
}
$scoop = Invoke-RestMethod "$prefix/Install-Scoop.ps1"
CheckLastExitCode
Invoke-Expression $scoop
CheckLastExitCode
$scoopApps = Invoke-RestMethod "$prefix/Install-ScoopApps.ps1"
CheckLastExitCode
Invoke-Expression $scoopApps
CheckLastExitCode
$charmScoopApps = Invoke-RestMethod "$prefix/Install-CharmScoopApps.ps1"
CheckLastExitCode
Invoke-Expression $charmScoopApps
CheckLastExitCode
$developingTodayScoopApps = Invoke-RestMethod "$prefix/Install-DevelopingTodayScoopApps.ps1"
CheckLastExitCode
Invoke-Expression $developingTodayScoopApps
CheckLastExitCode
$process0 = Start-Process powershell.exe -ArgumentList "-Command `"wsl --install -d Ubuntu`"" -PassThru
# $process0 | Wait-Process # just hope it gets done in time
winget update Microsoft.AppInstaller --accept-package-agreements --accept-source-agreements
winget update --all --include-unknown --accept-source-agreements --accept-package-agreements
winget upgrade --all --include-unknown --accept-source-agreements --accept-package-agreements
Set-PSRepository PSGallery -InstallationPolicy Trusted
$process1 = Start-Process powershell.exe -ArgumentList "-Command `"Register-PSRepository -Default ; Set-PSRepository PSGallery -InstallationPolicy Trusted ; Update-Help -ErrorAction SilentlyContinue ; update-module * ; Update-Script *`"" -PassThru
$process2 = Start-Process pwsh.exe -ArgumentList "-Command `"Register-PSRepository -Default ; Set-PSRepository PSGallery -InstallationPolicy Trusted ; Update-Help -ErrorAction SilentlyContinue ; update-module * -AcceptLicense ; Update-Script * -AcceptLicense`"" -PassThru
$process3 = Start-Process powershell.exe -ArgumentList "-Command `"Register-PSRepository -Default ; Set-PSRepository PSGallery -InstallationPolicy Trusted ; Update-Help -ErrorAction SilentlyContinue ; update-module * ; Update-Script * `"" -Verb RunAs -PassThru
$process4 = Start-Process pwsh.exe -ArgumentList "-Command `"Register-PSRepository -Default ; Set-PSRepository PSGallery -InstallationPolicy Trusted ; Update-Help -ErrorAction SilentlyContinue ; update-module * -AcceptLicense ; Update-Script * -AcceptLicense`"" -Verb RunAs -PassThru
$process1,$process2,$process3,$process4 | Wait-Process
$adminScript = @'
winget update Microsoft.AppInstaller --accept-package-agreements --accept-source-agreements
winget update --all --include-unknown --accept-source-agreements --accept-package-agreements
winget upgrade --all --include-unknown --accept-source-agreements --accept-package-agreements
choco upgrade all -y --accept-eula
scoop update *
scoop update -g *
Install-PackageProvider -Name "NuGet" -Force
Register-PSRepository -Default
Install-Module -Name PSWindowsUpdate -Force
UsoClient ScanInstallWait
wuauclt /detectnow /updatenow
Add-WUServiceManager -MicrosoftUpdate -Confirm:$false
dism.exe /Online /Cleanup-image /Restorehealth
Get-WindowsUpdate -MicrosoftUpdate -AcceptAll -Install -AutoReboot
Restart-Computer
'@
$process5 = Start-Process powershell.exe -ArgumentList "-Command `"$adminScript`"" -Verb RunAs
$process5 | Wait-Process