-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
308 lines (275 loc) · 12.3 KB
/
Copy pathsetup.ps1
File metadata and controls
308 lines (275 loc) · 12.3 KB
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# City2TABULA PowerShell Setup Script
# This script provides the same functionality as the makefile for Windows PowerShell users
param(
[Parameter(Position=0)]
[string]$Command = "help"
)
function Show-Help {
Write-Host "City2TABULA PowerShell Commands" -ForegroundColor Cyan
Write-Host "================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Usage: .\setup.ps1 <command>" -ForegroundColor Yellow
Write-Host ""
Write-Host "Recommended Workflow:" -ForegroundColor Magenta
Write-Host " 1. .\setup.ps1 configure - Set country, DB credentials in environment\docker.env"
Write-Host " 2. .\setup.ps1 build - Build the Docker image"
Write-Host " 3. .\setup.ps1 create-db - Create database schemas and import CityDB data"
Write-Host " (If database already exists, run: .\setup.ps1 reset-db)"
Write-Host " 4. .\setup.ps1 extract-features - Run the feature extraction pipeline"
Write-Host ""
Write-Host "Docker Environment:" -ForegroundColor Green
Write-Host " build Build the Docker environment"
Write-Host " up Start the Docker environment"
Write-Host " down Stop the Docker environment"
Write-Host " logs View Docker logs"
Write-Host " status Check container status"
Write-Host ""
Write-Host "Application Commands:" -ForegroundColor Green
Write-Host " dev Start development environment with shell"
Write-Host " create-db Create database and setup schemas"
Write-Host " extract-features Extract building features"
Write-Host " reset-db Reset the entire database"
Write-Host " version (v) Check City2TABULA version"
Write-Host ""
Write-Host "Complete Workflows:" -ForegroundColor Green
Write-Host " configure Interactive setup: select country and enter password"
Write-Host " configure-manual Instructions for manual editing of docker.env"
Write-Host " setup Build environment, configure, and start containers"
Write-Host " quick-start Complete setup and processing"
Write-Host ""
Write-Host "Cleanup:" -ForegroundColor Green
Write-Host " clean Stop containers and remove volumes"
Write-Host " clean-all Remove containers, volumes, and images"
Write-Host ""
Write-Host "Examples:" -ForegroundColor Yellow
Write-Host " .\setup.ps1 configure"
Write-Host " .\setup.ps1 build"
Write-Host " .\setup.ps1 create-db"
Write-Host " .\setup.ps1 version"
Write-Host " .\setup.ps1 v"
}
function Invoke-Configure {
Write-Host "Interactive City2TABULA Configuration" -ForegroundColor Magenta
Write-Host "=====================================" -ForegroundColor Magenta
Write-Host ""
# Country selection with mapping
$countries = @{
1 = @{Name="austria"; SRID="31256"; SRS="MGI / Austria GK East"}
2 = @{Name="belgium"; SRID="31370"; SRS="Belgian Lambert 72"}
3 = @{Name="cyprus"; SRID="3879"; SRS="GRS 1980 / Cyprus TM"}
4 = @{Name="czechia"; SRID="5514"; SRS="S-JTSK / Krovak East North"}
5 = @{Name="denmark"; SRID="25832"; SRS="ETRS89 / UTM zone 32N"}
6 = @{Name="france"; SRID="2154"; SRS="RGF93 / Lambert-93"}
7 = @{Name="germany"; SRID="25832"; SRS="ETRS89 / UTM zone 32N"}
8 = @{Name="greece"; SRID="2100"; SRS="GGRS87 / Greek Grid"}
9 = @{Name="hungary"; SRID="23700"; SRS="EOV"}
10 = @{Name="ireland"; SRID="29902"; SRS="Irish National Grid"}
11 = @{Name="italy"; SRID="3003"; SRS="Monte Mario / Italy zone 1"}
12 = @{Name="netherlands"; SRID="28992"; SRS="Amersfoort / RD New"}
13 = @{Name="norway"; SRID="25833"; SRS="ETRS89 / UTM zone 33N"}
14 = @{Name="poland"; SRID="2180"; SRS="ETRS89 / Poland CS2000 zone 5"}
15 = @{Name="serbia"; SRID="3114"; SRS="Serbian 1970 / Serbian Grid"}
16 = @{Name="slovenia"; SRID="3794"; SRS="Slovenia 1996 / Slovene National Grid"}
17 = @{Name="spain"; SRID="25830"; SRS="ETRS89 / UTM zone 30N"}
18 = @{Name="sweden"; SRID="3006"; SRS="SWEREF99 TM"}
19 = @{Name="united_kingdom"; SRID="27700"; SRS="OSGB 1936 / British National Grid"}
}
Write-Host "Available Countries:" -ForegroundColor Green
Write-Host "===================" -ForegroundColor Green
foreach ($key in $countries.Keys | Sort-Object) {
$country = $countries[$key]
Write-Host ("{0,2}) {1,-15} - SRID: {2,-5} ({3})" -f $key, $country.Name, $country.SRID, $country.SRS)
}
Write-Host ""
do {
$countryChoice = Read-Host "For which country would you like to configure City2TABULA? Enter a number (1-19):"
$countryChoice = [int]$countryChoice -as [int]
if ($countries.ContainsKey($countryChoice)) {
$selectedCountry = $countries[$countryChoice]
break
} else {
Write-Host "Invalid selection. Please enter a number (1-19)." -ForegroundColor Red
}
} while ($true)
Write-Host ""
Write-Host "Selected: $($selectedCountry.Name) (SRID: $($selectedCountry.SRID))" -ForegroundColor Green
Write-Host ""
# Get database credentials
Write-Host "Database Configuration:" -ForegroundColor Green
Write-Host "======================" -ForegroundColor Green
# Get username with default
$pgUser = Read-Host "Enter PostgreSQL username [default: postgres]"
if ([string]::IsNullOrWhiteSpace($pgUser)) {
$pgUser = "postgres"
}
# Get password
do {
$pgPassword = Read-Host "Enter PostgreSQL password" -AsSecureString
$pgPasswordPlain = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pgPassword))
if ($pgPasswordPlain.Length -gt 0) {
break
} else {
Write-Host "Password cannot be empty. Please try again." -ForegroundColor Red
}
} while ($true)
# Get database name with default
$pgName = Read-Host "Enter Database name [default: c2t_$($selectedCountry.Name)]"
if ([string]::IsNullOrWhiteSpace($pgName)) {
$pgName = "c2t_$($selectedCountry.Name)"
}
Write-Host ""
Write-Host "Updating configuration file..." -ForegroundColor Blue
# Update environment/docker.env file
$content = Get-Content "environment\docker.env"
$content = $content -replace "^COUNTRY=.*", "COUNTRY=$($selectedCountry.Name)"
$content = $content -replace "^CITYDB_SRID=.*", "CITYDB_SRID=$($selectedCountry.SRID)"
$content = $content -replace "^CITYDB_SRS_NAME=.*", "CITYDB_SRS_NAME=$($selectedCountry.SRS)"
$content = $content -replace "^DB_USER=.*", "DB_USER=$pgUser"
$content = $content -replace "^DB_PASSWORD=.*", "DB_PASSWORD=$pgPasswordPlain"
$content = $content -replace "^DB_NAME=.*", "DB_NAME=$pgName"
$content | Set-Content "environment\docker.env"
Write-Host "Configuration completed!" -ForegroundColor Green
Write-Host ""
Write-Host "Summary:" -ForegroundColor Cyan
Write-Host "========" -ForegroundColor Cyan
Write-Host "Country: $($selectedCountry.Name)" -ForegroundColor White
Write-Host "SRID: $($selectedCountry.SRID)" -ForegroundColor White
Write-Host "SRS Name: $($selectedCountry.SRS)" -ForegroundColor White
Write-Host "Database: Configured" -ForegroundColor White
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Yellow
Write-Host "- Place your data in data\lod2\$($selectedCountry.Name)\ and data\lod3\$($selectedCountry.Name)\"
Write-Host "- Run '.\setup.ps1 build' to build the Docker image"
Write-Host "- Run '.\setup.ps1 create-db' to create database and import data"
Write-Host "- Run '.\setup.ps1 extract-features' to extract building features"
}
function Invoke-ConfigureManual {
Write-Host "Manual configuration mode..." -ForegroundColor Blue
Write-Host "Please edit docker.env manually:" -ForegroundColor Yellow
Write-Host " - Set COUNTRY to your target country" -ForegroundColor Yellow
Write-Host " - Set CITYDB_SRID to the appropriate SRID" -ForegroundColor Yellow
Write-Host " - Set CITYDB_SRS_NAME to the appropriate SRS name" -ForegroundColor Yellow
Write-Host " - Replace '<your_pg_password>' with your PostgreSQL password" -ForegroundColor Yellow
Write-Host ""
Write-Host "You can edit the file with:" -ForegroundColor Cyan
Write-Host " notepad docker.env" -ForegroundColor White
Write-Host " code docker.env" -ForegroundColor White
}
function Invoke-Build {
Write-Host "Building Docker environment..." -ForegroundColor Blue
Set-Location "environment"
docker compose --env-file docker.env build --no-cache
Set-Location ".."
}
function Invoke-Up {
Write-Host "Starting Docker environment..." -ForegroundColor Blue
Set-Location "environment"
docker compose --env-file docker.env up -d
Set-Location ".."
}
function Invoke-Down {
Write-Host "Stopping Docker environment..." -ForegroundColor Blue
Set-Location "environment"
docker compose --env-file docker.env down
Set-Location ".."
}
function Invoke-Dev {
Write-Host "Starting development environment..." -ForegroundColor Blue
Set-Location "environment"
docker compose --env-file docker.env up -d
docker exec -it city2tabula-environment bash
Set-Location ".."
}
function Invoke-CreateDb {
Invoke-Up
Write-Host "Creating database and setting up schemas..." -ForegroundColor Blue
Set-Location "environment"
docker exec -it city2tabula-environment ./city2tabula -create-db
Set-Location ".."
}
function Invoke-ExtractFeatures {
Invoke-Up
Write-Host "Extracting building features..." -ForegroundColor Blue
Set-Location "environment"
docker exec -it city2tabula-environment ./city2tabula -extract-features
Set-Location ".."
}
function Invoke-ResetDb {
Invoke-Up
Write-Host "Resetting the entire database..." -ForegroundColor Blue
Set-Location "environment"
docker exec -it city2tabula-environment ./city2tabula -reset-db
Set-Location ".."
}
function Invoke-Version {
Invoke-Up
Write-Host "Checking City2TABULA version..." -ForegroundColor Blue
Set-Location "environment"
docker exec -it city2tabula-environment ./city2tabula -version
Set-Location ".."
}
function Invoke-v {
Invoke-Version
}
function Invoke-Setup {
Write-Host "Setting up City2TABULA environment..." -ForegroundColor Magenta
Invoke-Build
Invoke-Configure
Invoke-Up
Write-Host "Environment is ready! Run '.\setup.ps1 dev' to access the shell" -ForegroundColor Green
}
function Invoke-QuickStart {
Write-Host "Running complete City2TABULA pipeline..." -ForegroundColor Magenta
Invoke-Setup
Invoke-CreateDb
Invoke-ExtractFeatures
Write-Host "Quick start complete!" -ForegroundColor Green
}
function Invoke-Status {
Write-Host "Checking container status..." -ForegroundColor Blue
Set-Location "environment"
docker compose --env-file docker.env ps
Set-Location ".."
}
function Invoke-Logs {
Write-Host "Viewing Docker logs..." -ForegroundColor Blue
Set-Location "environment"
docker compose --env-file docker.env logs -f
Set-Location ".."
}
function Invoke-Clean {
Write-Host "Stopping containers and removing volumes..." -ForegroundColor Blue
Set-Location "environment"
docker compose --env-file docker.env down -v
Set-Location ".."
}
function Invoke-CleanAll {
Write-Host "Removing containers, volumes, and images..." -ForegroundColor Blue
Set-Location "environment"
docker compose --env-file docker.env down -v --rmi all
Set-Location ".."
}
# Main command dispatcher
switch ($Command.ToLower()) {
"help" { Show-Help }
"configure" { Invoke-Configure }
"configure-manual" { Invoke-ConfigureManual }
"build" { Invoke-Build }
"up" { Invoke-Up }
"down" { Invoke-Down }
"dev" { Invoke-Dev }
"create-db" { Invoke-CreateDb }
"extract-features" { Invoke-ExtractFeatures }
"reset-db" { Invoke-ResetDb }
"setup" { Invoke-Setup }
"quick-start" { Invoke-QuickStart }
"status" { Invoke-Status }
"logs" { Invoke-Logs }
"clean" { Invoke-Clean }
"clean-all" { Invoke-CleanAll }
default {
Write-Host "Unknown command: $Command" -ForegroundColor Red
Write-Host ""
Show-Help
}
}