/
installWindows.ps1
266 lines (228 loc) · 8.67 KB
/
installWindows.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# (c) https://github.com/MontiCore/monticore
# first, make sure powershell is running with admin priviliges
#### START ELEVATE TO ADMIN #####
param(
[Parameter(Mandatory=$false)]
[switch]$shouldAssumeToBeElevated,
[Parameter(Mandatory=$false)]
[String]$workingDirOverride
)
# If parameter is not set, we are propably in non-admin execution. We set it to the current working directory so that
# the working directory of the elevated execution of this script is the current working directory
if(-not($PSBoundParameters.ContainsKey('workingDirOverride'))) {
$workingDirOverride = (Get-Location).Path
}
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
if ($shouldAssumeToBeElevated) {
Write-Output "Elevating did not work :("
} else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -shouldAssumeToBeElevated -workingDirOverride "{1}"' -f ($myinvocation.MyCommand.Definition, "$workingDirOverride"))
}
exit
}
Set-Location "$workingDirOverride"
##### END ELEVATE TO ADMIN #####
# the shell now runs in admin mode
<#
# reloads the PATH environment Variable
#>
function Reload-Path {
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
}
#
# Set "$env:SKIP_MVN = 1" to skip the maven build at the end of this script
#
<#
# checks using "Get-Command" if a specific program is installed on the system
#
# @param $ProgramName name of the program that should be checked
# @return $true if $ProgramName is already installed on the system, $false otherwise
#>
function Get-IsInstalled {
param(
[Parameter(Mandatory)][string]$ProgramName
)
Reload-Path
try{
$ErrorActionPreference = "Stop"
$CheckCommand = Get-Command $ProgramName
$ErrorActionPreference = "Continue"
return $true
}
catch {
$ErrorActionPreference = "Continue"
return $false
}
}
<#
# adds a path to the PATH environment variable
# @param $PathToAdd path to be added to PATH
#>
function AddToPath {
param(
[Parameter(Mandatory)][string]$PathToAdd
)
# modify PATH
$oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
$newpath="$oldpath;$PathToAdd"
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
Reload-Path
}
<#
# checks whether the current java version is 11
#>
function Get-JavaVersionIs11 {
$result = $false
$result = (java -version 2>&1 | Out-String).Contains('11.0.16.1')
return $result
}
##########################################
# Install WinGet CLI
##########################################
if(-not (Get-IsInstalled winget)){
# Install RTE
Invoke-Webrequest -UseBasicParsing -OutFile VCLibs.appx https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx
Add-AppxPackage -Path "$PWD\VCLibs.appx"
rm "$PWD\VCLibs.appx"
# Get architecture
$arch = "x64" # default value
Switch ($env:PROCESSOR_ARCHITECTURE) {
"AMD64" {$arch = "x64"}
"ARM64" {$arch = "arm64"}
"X86" {$arch = "x86"}
}
# Install Windows UI Library (workaround for this issue: https://github.com/microsoft/winget-cli/issues/1861)
Invoke-Webrequest -UseBasicParsing -OutFile microsoft.ui.xaml.2.7.zip https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.0
Expand-Archive -DestinationPath .\microsoft.ui.xaml.2.7 .\microsoft.ui.xaml.2.7.zip
Add-AppxPackage -path ".\microsoft.ui.xaml.2.7\tools\AppX\${arch}\Release\Microsoft.UI.Xaml.2.7.appx"
# Find current release
$data = Invoke-Webrequest -UseBasicParsing https://api.github.com/repos/microsoft/winget-cli/releases/latest
$data = $data.Content | ConvertFrom-Json
# Get URL of installer
foreach($asset in $data[0].assets)
{
if ($asset.name.endswith("msixbundle"))
{
$wingetUrl=$asset.browser_download_url
}
}
# Download and install winget
Invoke-Webrequest -UseBasicParsing -OutFile WinGet.msixbundle -Uri $wingetUrl
Add-AppxPackage -path ".\WinGet.msixbundle"
rm ".\WinGet.msixbundle"
Reload-Path
}
##########################################
# Install software available via WinGet
##########################################
if(-not (Get-IsInstalled git)){
winget install -e Git.Git --accept-source-agreements --accept-package-agreements
}
if(-not (Get-IsInstalled java) -or -not (Get-JavaVersionIs11)){
winget install -e Microsoft.OpenJDK.11 --accept-source-agreements --accept-package-agreements
Reload-Path
if(-not (Get-JavaVersionIs11)){
Write-Output "WARNING: Java 11 was installed but is not your default Java version. Please make sure to use Java 11 with montithings"
}
}
if(-not (Get-IsInstalled cmake)){
winget install -e Kitware.CMake --accept-source-agreements --accept-package-agreements
}
if(-not (Get-IsInstalled docker)){
winget install -e Docker.DockerDesktop --accept-source-agreements --accept-package-agreements
}
if(-not (Get-IsInstalled mosquitto)){
winget install -e EclipseFoundation.Mosquitto --accept-source-agreements --accept-package-agreements
AddToPath("C:\Program Files\Mosquitto")
AddToPath("C:\Program Files\CMake\bin")
}
Reload-Path
# Start Mosquitto MQTT Broker
Start-Service -Name Mosquitto
##########################################
# Install Chocolatery Package Manager
##########################################
if(-not (Get-IsInstalled choco)){
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}
##########################################
# Install Maven
##########################################
if(-not (Get-IsInstalled mvn)){
choco install -y maven
Reload-Path
}
##########################################
# Install Ninja
##########################################
if(-not (Get-IsInstalled ninja)){
# Download
Invoke-Webrequest -UseBasicParsing -OutFile Ninja.zip -Uri https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-win.zip
Expand-Archive -DestinationPath 'C:\Program Files\Ninja' Ninja.zip
rm .\Ninja.zip
AddToPath("C:\Program Files\Ninja\")
}
##########################################
# Install MinGW
##########################################
if(-not (Get-IsInstalled gcc)){
choco install -y mingw
}
##########################################
# Install OpenSSL
##########################################
if(-not (Get-IsInstalled openssl)){
choco install -y openssl
}
##########################################
# Install NNG 1.3.0
##########################################
if(-not((Test-Path -Path 'C:\nng-1.3.0') -or (Test-Path -Path 'C:\Program Files (x86)\nng'))){
Invoke-Webrequest -UseBasicParsing -OutFile nng.zip -Uri https://github.com/nanomsg/nng/archive/v1.3.0.zip
Expand-Archive -DestinationPath "$PWD" nng.zip
rm .\nng.zip
cd .\nng-1.3.0\
mkdir build
cd .\build\
cmake -G Ninja ..
ninja
ninja test
ninja install
cd ..
cd ..
}
##########################################
# Install Python
##########################################
# since winget adds an app-execution alias to the ms store for python our
# Get-IsInstalled function would see python as installed. To fix this we must check for pip here instead
if(-not (Get-IsInstalled pip)) {
winget install python --accept-source-agreements --accept-package-agreements
Reload-Path
}
##########################################
# Install Conan
##########################################
if(-not (Get-IsInstalled conan)){
pip install conan
Reload-Path
}
##########################################
# Install MontiThings
##########################################
if ( $null -eq $env:SKIP_MVN -or $env:SKIP_MVN -ne 1) {
mvn clean install "-Dmaven.test.skip=true" "-Dexec.skip"
}
"
Installed successfully!
_____ ___ __ _ ___________ _
/__ |/ / ___________ / /_(_) / ___ __/ /_ (_)___ ____ __
/ /|_/ / / __ \__/ __ \/ __/ / (_) / / / __ \/ / __ \/ __ `//_ \
/ / / /_/ /_/ / / / / / /_/ /_ __/ / / / / / / / / / /_/ /___) )_
/_/ /____\____/ /_/ /_/\__/___/ /___/ /_/ /_/_/_/ /_/\__, /(______/
/____/
"