-
Notifications
You must be signed in to change notification settings - Fork 6
/
win-prereqs-setup.ps1
99 lines (81 loc) · 3.79 KB
/
win-prereqs-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
Add-Type -AssemblyName System.IO.Compression.FileSystem
$workshopPath = "C:\Users\Administrator\Desktop\workshop-content"
$downloadPath = "C:\Users\Administrator\Downloads\"
# Beats used in the workshop
$filebeat_link = 'https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.2.0-windows-x86_64.zip'
$metricbeat_link = 'https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.2.0-windows-x86_64.zip'
$heartbeat_link = 'https://artifacts.elastic.co/downloads/beats/heartbeat/heartbeat-7.2.0-windows-x86_64.zip'
$winlogbeat_link = 'https://artifacts.elastic.co/downloads/beats/winlogbeat/winlogbeat-7.2.0-windows-x86_64.zip'
function Setup-Prereqs ()
{
# Notepad++ for users to work with files
$prereq_1 = 'https://notepad-plus-plus.org/repository/7.x/7.6.6/npp.7.6.6.Installer.x64.exe'
If (!(Test-Path -Path $downloadPath -PathType Container)) {New-Item -Path $downloadPath -ItemType Directory | Out-Null}
$packages = @(
@{title='Notepad++ 7.6.6';url=$prereq_1;Arguments=' /Q /S';Destination=$downloadPath}
#add other prereq details here
)
foreach ($package in $packages) {
$packageName = $package.title
$fileName = Split-Path $package.url -Leaf
$destinationPath = $package.Destination + "\" + $fileName
If (!(Test-Path -Path $destinationPath -PathType Leaf)) {
Write-Host "Downloading $packageName"
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($package.url,$destinationPath)
}
}
foreach ($package in $packages) {
$packageName = $package.title
$fileName = Split-Path $package.url -Leaf
$destinationPath = $package.Destination + "\" + $fileName
$Arguments = $package.Arguments
Write-Output "Installing $packageName"
Invoke-Expression -Command "$destinationPath $Arguments"
}
}
# Download and Unzip Beats
function Download-Beats(){
If (!(Test-Path -Path $workshopPath -PathType Container)) {New-Item -Path $workshopPath -ItemType Directory | Out-Null}
$beats = @(
@{title='Filebeat';url=$filebeat_link;Arguments=''},
@{title='Metricbeat';url=$metricbeat_link;Arguments=''},
@{title='Heartbeat';url=$heartbeat_link;Arguments=''},
@{title='Winlogbeat';url=$winlogbeat_link;Arguments=''}
)
foreach ($beat in $beats) {
$beatName = $beat.title
$fileName = Split-Path $beat.url -Leaf
$destinationPath = $workshopPath + "\" + $fileName
Write-Output "Beats Download Location = $destinationPath"
If (!(Test-Path -Path $destinationPath -PathType Leaf)) {
Write-Host "Downloading $beatName"
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($beat.url,$destinationPath)
}
}
foreach ($beat in $beats) {
$beatName = $beat.title
$fileName = Split-Path $beat.url -Leaf
$zipFile = $workshopPath + "\" + $fileName
Write-Output "Unzipping $beatName"
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipFile, $workshopPath)
}
}
function Copy-Data()
{
If (!(Test-Path -Path $downloadPath -PathType Container)) {New-Item -Path $downloadPath -ItemType Directory | Out-Null}
$downloadPath = "C:\Users\Administrator\Downloads\"
Write-Output 'downloadPath = $downloadPath'
$dataOrigin = $downloadPath +'\observability-workshop\data\*'
$dataDest = $workshopPath + '\data\logs\'
Copy-Item $dataOrigin -Destination $dataDest -Recurse
$nginxZipFile = $dataDest+'nginx\nginx.zip'
$nginxExtractLocation = $dataDest+'nginx'
Write-Output 'nginxZipFile' + $nginxExtractLocation
[System.IO.Compression.ZipFile]::ExtractToDirectory($nginxZipFile, $nginxExtractLocation)
Remove-Item $nginxZipFile
}
Setup-Prereqs
Download-Beats
Copy-Data