-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup-windows.ps1
124 lines (101 loc) · 3.92 KB
/
setup-windows.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
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
#Requires -RunAsAdministrator
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'
function Confirm-Return-Code {
$ReturnCode = $?
if (-not $ReturnCode)
{
throw "Native Failure. Got return code: $ReturnCode"
}
}
function Install-Chocolatey {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingInvokeExpression", "", Justification = "Trusting Chocolatey installer")]
param()
Write-Output "Checking if Chocolatey is installed..."
if (!$Env:ChocolateyInstall) {
Write-Output "Installing Chocolatey..."
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}
else {
Write-Output "Chocolatey is already installed."
}
# Make `refreshenv` available right away, by defining the $env:ChocolateyInstall
# variable and importing the Chocolatey profile module.
$env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.."
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
# refreshenv is now an alias for Update-SessionEnvironment
# (rather than invoking refreshenv.cmd, the *batch file* for use with cmd.exe)
Write-Output "Refreshing the environment because we might have installed chocolatey..."
refreshenv
}
function Install-Chocolatey-Package {
Write-Output "Currently installed Chocolatey packages:"
& "choco" list
Confirm-Return-Code
& "choco" upgrade chocolatey --yes --no-progress
Confirm-Return-Code
$Packages =
'7zip',
'conemu',
'googlechrome',
'vlc',
'vscode'
ForEach ($Package in $Packages) {
# choco upgrade installs the package if missing not installed.
# See https://docs.chocolatey.org/en-us/choco/commands/upgrade
& "choco" upgrade $Package --yes --no-progress
Confirm-Return-Code
}
Write-Output "Refreshing the environment because we might have installed new packages..."
refreshenv
Write-Output "Current path: $env:PATH"
Write-Output "Currently installed Chocolatey packages:"
& "choco" list
Confirm-Return-Code
}
function Initialize-VSCode {
Write-Output "Initializing Visual Studio Code"
$VsCodeConfigSourcePath = ".\.config\Code\User\settings.json"
$VsCodeConfigDestinationPath = "$Env:APPDATA\Code\User\settings.json"
Write-Output "Creating a symbolic link to the VS Code configuration files. Source: $VsCodeConfigSourcePath, destination: $VsCodeConfigDestinationPath..."
New-Item -Force -ItemType SymbolicLink -Path $VsCodeConfigDestinationPath -Value $VsCodeConfigSourcePath
}
function Install-VSCode-Extension {
Get-Content ".\.config\ferrarimarco-dotfiles\vs-code\extensions.txt" | ForEach-Object {
& "code" --force --install-extension $_
Confirm-Return-Code
}
}
function Install-WSL {
Write-Output "Installing WSL..."
& "wsl" --install
Confirm-Return-Code
Write-Output "WSL distribution list:"
& "wsl" --list --online
Confirm-Return-Code
$WslPackage = Get-AppxPackage -AllUsers -Name CanonicalGroupLimited.Ubuntu22.04onWindows
if (!$WslPackage) {
Write-Output "Installing Ubuntu (WSL)..."
Invoke-WebRequest -Uri https://aka.ms/wslubuntu2204 -OutFile Ubuntu.appx -UseBasicParsing
Add-AppxPackage .\Ubuntu.appx
Remove-Item .\Ubuntu.appx
}
else {
Write-Output "The WSL package is already installed."
}
Write-Output "Installed WSL distributions:"
& "wsl" --list --verbose
Confirm-Return-Code
}
if ($env:GITHUB_ACTIONS -ne "true")
{
Write-Output "Not running in the CI environment, so we can install WSL2 that needs virtualization support."
Install-WSL
}
else{
Write-Output "Running in a CI environment, skipping WSL2 installation."
}
Install-Chocolatey
Install-Chocolatey-Package
Initialize-VSCode
Install-VSCode-Extension