-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.ps1
90 lines (81 loc) · 3.65 KB
/
init.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
param(
[switch]$NoK8s
)
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
throw "This script needs to be run As Admin"
}
if ($PSEdition -eq 'Core') {
if (-not (Get-InstalledScript Install-RequiredModule)) {
try {
Install-Script Install-RequiredModule -Repository PSGallery -Force
} catch {
throw "Issue installed dependency: Install-RequiredModule script: $($_)"
}
}
} else {
if (-not (Get-Module Install-RequiredModule)) {
try {
Install-Module Install-RequiredModule -Repository PSGallery -Force
} catch {
throw "Issue installed dependency: Install-RequiredModule script: $($_)"
}
}
}
try {
Install-RequiredModule -RequiredModulesFile $PSScriptRoot\requiredmodules.psd1 -TrustRegisteredRepositories -Scope CurrentUser -Quiet
} catch {
throw "Issue installing required modules: $($_)"
}
if (-not $IsMacOS) {
<# Make sure Chocolatey is installed #>
try {
$chocoDetail = Get-Command choco -CommandType Application -ErrorAction Stop
if ($chocoDetail) {
Write-Host "Choco version detected as: $(choco --version)"
}
} catch {
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}
if ($PSBoundParameters.ContainsKey('NoK8s')) {
Write-Host 'Skipping install of Kubernetes tools'
} else {
if ($chocoDetail) {
# install some stuff for Kubernetes management
Write-Output "Installing Kubernetes tools"
choco install kubernetes-cli --limitoutput --yes
choco install kubectx --limitoutput --yes
choco install kubens --limitoutput --yes
choco install k9s --limitoutput --yes
Write-Output "Do not forget to install Popeye as well: https://github.com/derailed/popeye/releases"
}
}
# install of basics
if (-not (Get-Command bicep -CommandType Application -ErrorAction SilentlyContinue)) {
choco install bicep --limitoutput --yes
}
if (-not (Get-Command git -CommandType Application -ErrorAction SilentlyContinue)) {
choco install git --limitoutput --yes
}
if (-not (Get-Command wt -CommandType Application -ErrorAction SilentlyContinue)) {
choco install windows.terminal --limitoutput --yes
}
}
# setup initial Secret vault, adjust the configuration as you want or need for security purposes
try {
if (Get-Module Microsoft.PowerShell.SecretStore -ListAvailable) {
if ((Get-SecretStoreConfiguration).Authentication -ne 'None') {
Read-Host 'Setting Secret Store to no authentication, select N if you do not want to apply this in the next prompt (enter to continue)'
Set-SecretStoreConfiguration -Authentication None -Interaction None
} else {
Write-Host 'Secret Store authentication already set to [None]'
}
if (-not (Get-SecretVault -Name myCredentials)) {
Register-SecretVault -Name myCredentials -ModuleName Microsoft.PowerShell.SecretStore -DefaultVault
} else {
Write-Warning 'Secret vault [myCredentials] already exists'
}
Write-Host 'Vault [myCredentials] can be used to store credentials used in your local scripts. Use Set-Secret to add'
}
} catch {
Write-Warning "Issue creating scripts vault: $($_)"
}