-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.ps1
104 lines (96 loc) · 3.32 KB
/
setup.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
$GITHUB_REPO="opc-ua-umati-mssql-grafana"
## Don't change this
$TARGET_DIR="OPCRouter_" + $GITHUB_REPO -replace '-','_'
$GITHUB_ZIP_ADRESS = "https://api.github.com/repos/OPC-Router/" + $GITHUB_REPO + "/zipball"
$GITHUB_DIR = $GITHUB_REPO + "-main"
$WindowsVersion=(Get-ComputerInfo).OsProductType
$HostIP = (
Get-NetIPConfiguration |
Where-Object {
$_.IPv4DefaultGateway -ne $null -and
$_.NetAdapter.Status -ne "Disconnected"
}
).IPv4Address.IPAddress
function Get-UrlStatusCode([string] $Url)
{
try
{
(Invoke-WebRequest -Uri $Url -UseBasicParsing -DisableKeepAlive).StatusCode
}
catch [Net.WebException]
{
[int]$_.Exception.Response.StatusCode
}
}
Write-Host ""
Write-Host "Welcome to the OPC Router 5 docker sample with Umati OPC UA, MSSQL and Grafana!"
Write-Host ""
Try {
$test = docker --version
if($?)
{
Write-Host "docker already installed"
}
}
Catch
{
Write-Host "Docker is missing and required for using the sample. Please install Docker using the following instructions:"
switch ($WindowsVersion)
{
WorkStation
{
Write-Host ""
Write-Host "Docker Installation Windows 10/11 Guide: https://docs.docker.com/desktop/windows/install/"
Write-Host ""
Write-Host "When you are done installing Docker you can repeat the process."
sleep 10
Start-Process "https://docs.docker.com/desktop/windows/install/"
return
}
Server
{
Write-Host ""
Write-Host "Docker Installation Windows Server Guide: https://docs.microsoft.com/de-de/virtualization/windowscontainers/quick-start/set-up-environment?tabs=Windows-Server"
Write-Host ""
Write-Host "When you are done installing Docker you can repeat the process."
sleep 10
Start-Process "https://docs.microsoft.com/de-de/virtualization/windowscontainers/quick-start/set-up-environment?tabs=Windows-Server"
return
}
}
}
$DockerRunning = "False"
while ($DockerRunning -ne "True")
{
docker info | Out-Null
$DockerRunning = $?
if ($DockerRunning -ne "True")
{
Write-Host "Please start Docker Runtime and press enter"
Read-Host
}
}
$GITHUB_FILENAME = $TARGET_DIR + ".zip"
Invoke-WebRequest -Uri $GITHUB_ZIP_ADRESS -OutFile $GITHUB_FILENAME
Expand-Archive -Path $GITHUB_FILENAME -DestinationPath $TARGET_DIR -Force
Remove-Item -Path $GITHUB_FILENAME -Force
cd $TARGET_DIR
$TEMP_DIR=(Get-ChildItem -Path . | Select-Object -First 1).Name
Get-ChildItem -Path $TEMP_DIR -Directory | Move-Item -Destination .
Get-ChildItem -Path $TEMP_DIR -File | Move-Item -Destination .
Remove-Item -Path $TEMP_DIR -Force
sleep 10
docker-compose up -d
$HostAdress = "http://" + $HostIP + ":3000/d/v972rfT7k/umati-machine-data";
$OPCRouter5HostAdress = "http://" + $HostIP + ":8080/status/connections/Umati2SQL";
Write-Host "Waiting for final steps to complete"
$GRAFANA_REACHABLE=999
while ($GRAFANA_REACHABLE -ne 200)
{
$GRAFANA_REACHABLE = Get-UrlStatusCode "http://localhost:3000"
sleep 3
}
Write-Host "Sample was installed successfully! Open" $HostAdress " for grafana dashboard and " $OPCRouter5HostAdress " for OPC Router 5 Management Status in a browser!"
Write-Host "Once you finished observing the sample, you may stop it by running 'docker-compose down'"
Start-Process $HostAdress
Start-Process $OPCRouter5HostAdress