-
Notifications
You must be signed in to change notification settings - Fork 18
/
install_local_environment.ps1
117 lines (95 loc) · 3.4 KB
/
install_local_environment.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
Add-Type -AssemblyName System.IO.Compression.FileSystem
$localEnvironment = "localenvironment"
$dynamoDbUrl = "https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/dynamodb_local_latest.zip"
$dynamoDbPackageName = "dynamodb_local.zip"
$dynamoDbName = ".\dynamodb\"
$minioUrl = "https://dl.min.io/server/minio/release/windows-amd64/minio.exe"
$minioName = "minio.exe"
$javaUrl = "https://javadl.oracle.com/webapps/download/AutoDL?BundleId=238698_478a62b7d4e34b78b671c754eaaf38ab"
$accessKey = "AKIAIOSFODNN7EXAMPLE"
$secretKey = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
Write-Host "Proceeding to set up local environment... This may take several minutes."
Write-Host "Please keep this window open until it closes itself."
#Create folder
if (!(Test-Path $localEnvironment))
{
New-Item $localEnvironment -ItemType directory
}
#Download Local DynamoDB
if (Test-Path "$localEnvironment/$dynamoDbName")
{
Write-Host "DynamoDB found, skipping installation"
}
else
{
Write-Host "Installing local DynamoDB..."
if (!(Test-Path "$localEnvironment/$dynamoDbPackageName"))
{
Invoke-WebRequest -Uri $dynamoDbUrl -OutFile "$localEnvironment/$dynamoDbPackageName"
}
[System.IO.Compression.ZipFile]::ExtractToDirectory("$localEnvironment/$dynamoDbPackageName", "$localEnvironment/$dynamoDbName")
}
#Install Java
$javaVersion = (Get-Command java | Select-Object -ExpandProperty Version).Major
if ($javaVersion -ge 8)
{
Write-Host "Java found, skipping installation"
}
else
{
Write-Host "Installing Java..."
Invoke-WebRequest -Uri $javaUrl -OutFile "$localEnvironment/jre8.exe"
Start-Process .\$localEnvironment\jre8.exe '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' -wait
}
#Set environment variable
Write-Host "Setting Java environment variable..."
if (Test-Path "C:\Program Files (x86)\Java")
{
Start-Process -FilePath 'setx' -ArgumentList 'JAVA_HOME "C:\Program Files (x86)\Java\jre1.8.0_211\bin"'
}
else
{
Start-Process -FilePath 'setx' -ArgumentList 'JAVA_HOME "C:\Program Files\Java\jre1.8.0_211\bin"'
}
#Install and configure AWS
$myDocumentsPath = [Environment]::GetFolderPath("MyDocuments")
if (Test-Path "$($myDocumentsPath)\WindowsPowerShell\Modules\AWSPowerShell")
{
Write-Host "AWS found, skipping installation"
}
else
{
Write-Host "Installing AWS..."
Install-PackageProvider -Scope CurrentUser -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module -Scope CurrentUser -Name AWSPowerShell -Force
Set-AWSCredential -AccessKey $accessKey -SecretKey $secretKey -StoreAs default
}
#Install MinIO
if ([System.IO.File]::Exists("$localEnvironment/$minioName"))
{
Write-Host "MinIO found, skipping installation"
}
else
{
Write-Host "Installing MinIO..."
Invoke-WebRequest -Uri $minioUrl -OutFile "$localEnvironment/$minioName"
}
#Set up MinIO config
if (Test-Path "$localEnvironment/minio")
{
Write-Host "MinIO config found, skipping setup"
}
else
{
Write-Host "Setting up MinIO config..."
Start-Process "$localEnvironment/minio.exe" -ArgumentList "server $localEnvironment/minio"
sleep 2
Stop-Process -Name "minio"
$json = Get-Content .\$localEnvironment\minio\.minio.sys\config\config.json -raw | ConvertFrom-Json
$json.credential | % { $_.accessKey = $accessKey }
$json.credential | % { $_.secretKey = $secretKey }
$json | ConvertTo-Json -depth 32 | Set-Content .\$localEnvironment\minio\.minio.sys\config\config.json
}
Write-Host "Setup complete!"
sleep 5