-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
688 lines (546 loc) · 21.4 KB
/
install.ps1
File metadata and controls
688 lines (546 loc) · 21.4 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
#
# SoftClient4ES Installation Script
# For Windows (PowerShell)
#
param(
[string]$Target = "$env:USERPROFILE\softclient4es",
[string]$EsVersion = "8",
[string]$Version = "latest",
[string]$ScalaVersion = "2.13",
[switch]$ListVersions,
[switch]$Help
)
# =============================================================================
# Configuration
# =============================================================================
$JFROG_REPO_URL = "https://softnetwork.jfrog.io/artifactory/releases/app/softnetwork/elastic"
$JFROG_API_URL = "https://softnetwork.jfrog.io/artifactory/api/storage/releases/app/softnetwork/elastic"
$GITHUB_RAW_URL = "https://raw.githubusercontent.com/SOFTNETWORK-APP/SoftClient4ES/refs/heads/main"
$README_URL = "${GITHUB_RAW_URL}/documentation/client/repl.md"
$LICENSE_URL = "${GITHUB_RAW_URL}/LICENSE"
# =============================================================================
# Help
# =============================================================================
function Show-Help {
Write-Host @"
SoftClient4ES Installation Script
Usage: .\install.ps1 [OPTIONS]
Options:
-Target <dir> Installation directory (default: $env:USERPROFILE\softclient4es)
-EsVersion <ver> Elasticsearch major version: 6, 7, 8, 9 (default: 8)
-Version <ver> SoftClient4ES version (default: latest)
-ScalaVersion <ver> Scala version (default: 2.13)
-ListVersions List available versions for the specified ES version
-Help Show this help message
Java Requirements:
ES 6, 7, 8 -> Java 8 or higher
ES 9 -> Java 17 or higher
Examples:
.\install.ps1
.\install.ps1 -ListVersions -EsVersion 8
.\install.ps1 -Target "C:\tools\softclient4es" -EsVersion 8 -Version 1.0.0
.\install.ps1 -EsVersion 7 -Version 0.2.0
"@
exit 0
}
if ($Help) {
Show-Help
}
# =============================================================================
# Output Functions
# =============================================================================
function Write-Info($msg) { Write-Host "[INFO] $msg" -ForegroundColor Cyan }
function Write-Success($msg) { Write-Host "[OK] $msg" -ForegroundColor Green }
function Write-Warn($msg) { Write-Host "[WARN] $msg" -ForegroundColor Yellow }
function Write-Err($msg) { Write-Host "[ERROR] $msg" -ForegroundColor Red }
# =============================================================================
# Validate Inputs
# =============================================================================
if ($EsVersion -notmatch '^[6-9]$') {
Write-Err "Invalid Elasticsearch version: $EsVersion (must be 6, 7, 8, or 9)"
exit 1
}
# =============================================================================
# Derived Variables
# =============================================================================
$ARTIFACT_NAME = "softclient4es${EsVersion}-cli_${ScalaVersion}"
# =============================================================================
# Get Required Java Version
# =============================================================================
function Get-RequiredJavaVersion {
param([string]$EsVer)
if ($EsVer -eq "9") {
return 17
} else {
return 8
}
}
$REQUIRED_JAVA_VERSION = Get-RequiredJavaVersion -EsVer $EsVersion
# =============================================================================
# List Available Versions
# =============================================================================
function Get-AvailableVersions {
$apiUrl = "${JFROG_API_URL}/${ARTIFACT_NAME}"
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$response = Invoke-RestMethod -Uri $apiUrl -UseBasicParsing
$versions = $response.children |
Where-Object { $_.folder -eq $true } |
ForEach-Object { $_.uri.TrimStart('/') } |
Where-Object { $_ -notmatch '^\.' } |
Sort-Object { [Version]($_ -replace '-SNAPSHOT', '.0' -replace '[^0-9.]', '') }
return $versions
}
catch {
Write-Err "Failed to fetch versions from repository"
Write-Err "Artifact: $ARTIFACT_NAME"
Write-Err $_.Exception.Message
exit 1
}
}
if ($ListVersions) {
Write-Info "Fetching available versions for ES$EsVersion..."
$versions = Get-AvailableVersions
if (-not $versions -or $versions.Count -eq 0) {
Write-Err "No versions found for $ARTIFACT_NAME"
exit 1
}
Write-Host ""
Write-Host "==================================================================" -ForegroundColor Cyan
Write-Host " Available SoftClient4ES Versions for Elasticsearch $EsVersion" -ForegroundColor Cyan
Write-Host "==================================================================" -ForegroundColor Cyan
Write-Host ""
Write-Host " Artifact: " -NoNewline; Write-Host $ARTIFACT_NAME -ForegroundColor Yellow
Write-Host " Java required: " -NoNewline; Write-Host "${REQUIRED_JAVA_VERSION}+" -ForegroundColor Yellow
Write-Host ""
Write-Host " Versions:" -ForegroundColor Green
Write-Host ""
foreach ($ver in $versions) {
Write-Host " * $ver"
}
Write-Host ""
Write-Host " Total: $($versions.Count) version(s)" -ForegroundColor Blue
Write-Host ""
Write-Host " To install a specific version:"
Write-Host " .\install.ps1 -EsVersion $EsVersion -Version <version>" -ForegroundColor Cyan
Write-Host ""
exit 0
}
# =============================================================================
# Resolve Latest Version
# =============================================================================
function Resolve-LatestVersion {
Write-Info "Resolving latest version..."
$versions = Get-AvailableVersions
if (-not $versions -or $versions.Count -eq 0) {
Write-Err "No versions found"
exit 1
}
# Prefer non-snapshot versions
$releaseVersions = $versions | Where-Object { $_ -notmatch 'SNAPSHOT' }
if ($releaseVersions -and $releaseVersions.Count -gt 0) {
return $releaseVersions[-1]
}
# Fallback to any version
return $versions[-1]
}
if ($Version -eq "latest") {
$Version = Resolve-LatestVersion
Write-Success "Resolved latest version: $Version"
}
$JAR_NAME = "${ARTIFACT_NAME}-${Version}-assembly.jar"
$DOWNLOAD_URL = "${JFROG_REPO_URL}/${ARTIFACT_NAME}/${Version}/${JAR_NAME}"
# =============================================================================
# Check Prerequisites
# =============================================================================
function Check-Prerequisites {
Write-Info "Checking prerequisites..."
# Check Java
try {
$javaVersionOutput = & java -version 2>&1 | Select-String -Pattern 'version'
$javaVersionString = $javaVersionOutput.ToString()
# Extract version number
if ($javaVersionString -match '"1\.(\d+)') {
# Old format: 1.8.x
$javaVersion = [int]$Matches[1]
} elseif ($javaVersionString -match '"(\d+)') {
# New format: 11.x, 17.x
$javaVersion = [int]$Matches[1]
} else {
Write-Warn "Could not determine Java version"
$javaVersion = 0
}
if ($javaVersion -gt 0 -and $javaVersion -lt $REQUIRED_JAVA_VERSION) {
Write-Err "Java $REQUIRED_JAVA_VERSION or higher is required for ES$EsVersion."
Write-Err "Found: Java $javaVersion"
exit 1
}
Write-Success "Java $javaVersion found (required: ${REQUIRED_JAVA_VERSION}+)"
}
catch {
Write-Err "Java is not installed."
Write-Err "ES$EsVersion requires Java $REQUIRED_JAVA_VERSION or higher."
exit 1
}
}
# =============================================================================
# Create Directory Structure
# =============================================================================
function Create-Directories {
Write-Info "Creating directory structure..."
New-Item -ItemType Directory -Force -Path "$Target\bin" | Out-Null
New-Item -ItemType Directory -Force -Path "$Target\conf" | Out-Null
New-Item -ItemType Directory -Force -Path "$Target\lib" | Out-Null
New-Item -ItemType Directory -Force -Path "$Target\logs" | Out-Null
Write-Success "Created $Target\{bin,conf,lib,logs}"
}
# =============================================================================
# Download File Helper
# =============================================================================
function Download-File {
param(
[string]$Url,
[string]$Dest,
[string]$Description
)
Write-Info "Downloading $Description..."
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $Url -OutFile $Dest -UseBasicParsing -ErrorAction Stop
Write-Success "Downloaded $Description"
return $true
}
catch {
Write-Warn "Failed to download $Description from $Url"
return $false
}
}
# =============================================================================
# Download JAR
# =============================================================================
function Download-Jar {
Write-Info "Downloading $JAR_NAME..."
Write-Info "URL: $DOWNLOAD_URL"
$dest = "$Target\lib\$JAR_NAME"
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $DOWNLOAD_URL -OutFile $dest -UseBasicParsing
Write-Success "Downloaded to $dest"
}
catch {
Write-Err "Failed to download JAR from $DOWNLOAD_URL"
Write-Err "Please check that version '$Version' exists."
Write-Err "Run with -ListVersions to see available versions."
Write-Err $_.Exception.Message
exit 1
}
}
# =============================================================================
# Download Documentation and License
# =============================================================================
function Download-Docs {
Write-Info "Downloading documentation and license..."
# Download README.md
$readmeResult = Download-File -Url $README_URL -Dest "$Target\README.md" -Description "README.md"
if (-not $readmeResult) {
Write-Warn "README.md download failed, creating minimal version"
Create-MinimalReadme
}
# Download LICENSE
Download-File -Url $LICENSE_URL -Dest "$Target\LICENSE" -Description "LICENSE" | Out-Null
}
# =============================================================================
# Create Minimal README (Fallback)
# =============================================================================
function Create-MinimalReadme {
$readmeContent = @'
# SoftClient4ES
SQL Gateway for Elasticsearch
## Quick Start
```powershell
# Start the REPL
.\bin\softclient4es.bat
# Execute a single command
.\bin\softclient4es.bat -c "SHOW TABLES"
# Get help
.\bin\softclient4es.bat --help
```
## Configuration
Edit `conf\application.conf` to configure default connection settings.
## Documentation
Full documentation available at:
https://github.com/SOFTNETWORK-APP/SoftClient4ES
## License
See LICENSE file for details.
'@
$readmeContent | Out-File -FilePath "$Target\README.md" -Encoding UTF8
Write-Success "Created minimal README.md"
}
# =============================================================================
# Create Configuration File
# =============================================================================
function Create-Config {
Write-Info "Creating configuration file..."
$configContent = @'
# SoftClient4ES Configuration
# Override these settings or use command-line options
elastic {
credentials {
scheme = "http"
scheme = ${?ELASTIC_SCHEME}
host = "localhost"
host = ${?ELASTIC_HOST}
port = 9200
port = ${?ELASTIC_PORT}
username = ""
username = ${?ELASTIC_USERNAME}
password = ""
password = ${?ELASTIC_PASSWORD}
api-key = ""
api-key = ${?ELASTIC_API_KEY}
bearer-token = ""
bearer-token = ${?ELASTIC_BEARER_TOKEN}
}
}
'@
$configContent | Out-File -FilePath "$Target\conf\application.conf" -Encoding UTF8
Write-Success "Created $Target\conf\application.conf"
}
# =============================================================================
# Create Logback Configuration
# =============================================================================
function Create-LogbackConfig {
Write-Info "Creating logback configuration..."
$logbackContent = @'
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<variable name="LOG_DIR" value="${log.dir:-logs}" />
<variable name="LOG_FILE" value="softclient4es" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/${LOG_FILE}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/${LOG_FILE}-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>7</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<queueSize>8192</queueSize>
<neverBlock>true</neverBlock>
<appender-ref ref="FILE" />
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{HH:mm:ss.SSS} %-5level %logger{20} - %msg%n</pattern>
</encoder>
</appender>
<logger name="app.softnetwork.elastic" level="INFO" />
<logger name="org.apache.http" level="WARN" />
<logger name="org.elasticsearch" level="WARN" />
<root level="INFO">
<appender-ref ref="ASYNC" />
</root>
</configuration>
'@
$logbackContent | Out-File -FilePath "$Target\conf\logback.xml" -Encoding UTF8
Write-Success "Created $Target\conf\logback.xml"
}
# =============================================================================
# Create Launcher Scripts
# =============================================================================
function Create-Launcher {
Write-Info "Creating launcher scripts..."
# Batch file
$batchContent = @"
@echo off
setlocal
set SCRIPT_DIR=%~dp0
set BASE_DIR=%SCRIPT_DIR%..
set JAR_FILE=%BASE_DIR%\lib\$JAR_NAME
set CONFIG_FILE=%BASE_DIR%\conf\application.conf
set LOGBACK_FILE=%BASE_DIR%\conf\logback.xml
set LOG_DIR=%BASE_DIR%\logs
set REQUIRED_JAVA=$REQUIRED_JAVA_VERSION
if not exist "%JAR_FILE%" (
echo Error: JAR file not found: %JAR_FILE% >&2
exit /b 1
)
REM Create logs directory if it doesn't exist
if not exist "%LOG_DIR%" mkdir "%LOG_DIR%"
REM Check Java
java -version >nul 2>&1
if errorlevel 1 (
echo Error: Java is not installed. Java %REQUIRED_JAVA%+ is required. >&2
exit /b 1
)
if "%JAVA_OPTS%"=="" set JAVA_OPTS=-Xmx512m
REM Logback configuration
set LOGBACK_OPTS=
if exist "%LOGBACK_FILE%" set LOGBACK_OPTS=-Dlogback.configurationFile=%LOGBACK_FILE%
java %JAVA_OPTS% -Dconfig.file="%CONFIG_FILE%" -Dlog.dir="%LOG_DIR%" %LOGBACK_OPTS% -jar "%JAR_FILE%" %*
endlocal
"@
$batchContent | Out-File -FilePath "$Target\bin\softclient4es.bat" -Encoding ASCII
# PowerShell launcher
$psContent = @"
#
# SoftClient4ES Launcher
# Elasticsearch version: $EsVersion
# Required Java: ${REQUIRED_JAVA_VERSION}+
#
`$ScriptDir = Split-Path -Parent `$MyInvocation.MyCommand.Path
`$BaseDir = Split-Path -Parent `$ScriptDir
`$JarFile = "`$BaseDir\lib\$JAR_NAME"
`$ConfigFile = "`$BaseDir\conf\application.conf"
`$LogbackFile = "`$BaseDir\conf\logback.xml"
`$LogDir = "`$BaseDir\logs"
`$RequiredJava = $REQUIRED_JAVA_VERSION
if (-not (Test-Path `$JarFile)) {
Write-Error "JAR file not found: `$JarFile"
exit 1
}
# Create logs directory if it doesn't exist
if (-not (Test-Path `$LogDir)) {
New-Item -ItemType Directory -Path `$LogDir | Out-Null
}
# Check Java
try {
`$javaVersionOutput = & java -version 2>&1 | Select-String -Pattern 'version'
`$javaVersionString = `$javaVersionOutput.ToString()
if (`$javaVersionString -match '"1\.(\d+)') {
`$javaVersion = [int]`$Matches[1]
} elseif (`$javaVersionString -match '"(\d+)') {
`$javaVersion = [int]`$Matches[1]
} else {
`$javaVersion = 0
}
if (`$javaVersion -gt 0 -and `$javaVersion -lt `$RequiredJava) {
Write-Error "Java `$RequiredJava+ is required. Found: Java `$javaVersion"
exit 1
}
}
catch {
Write-Error "Java is not installed. Java `$RequiredJava+ is required."
exit 1
}
`$JavaOpts = if (`$env:JAVA_OPTS) { `$env:JAVA_OPTS } else { "-Xmx512m" }
# Logback configuration
`$LogbackOpts = @()
if (Test-Path `$LogbackFile) {
`$LogbackOpts = @("-Dlogback.configurationFile=`$LogbackFile")
}
& java `$JavaOpts "-Dconfig.file=`$ConfigFile" "-Dlog.dir=`$LogDir" @LogbackOpts -jar `$JarFile `$args
"@
$psContent | Out-File -FilePath "$Target\bin\softclient4es.ps1" -Encoding UTF8
Write-Success "Created $Target\bin\softclient4es.bat"
Write-Success "Created $Target\bin\softclient4es.ps1"
}
# =============================================================================
# Create Uninstall Script
# =============================================================================
function Create-Uninstaller {
Write-Info "Creating uninstall script..."
$uninstallContent = @"
`$Target = "$Target"
`$confirm = Read-Host "This will remove `$Target. Continue? [y/N]"
if (`$confirm -eq 'y' -or `$confirm -eq 'Y') {
Remove-Item -Recurse -Force `$Target
Write-Host "SoftClient4ES has been uninstalled."
} else {
Write-Host "Uninstall cancelled."
}
"@
$uninstallContent | Out-File -FilePath "$Target\uninstall.ps1" -Encoding UTF8
Write-Success "Created $Target\uninstall.ps1"
}
# =============================================================================
# Create Version Info File
# =============================================================================
function Create-VersionInfo {
$versionContent = @"
SoftClient4ES Installation Info
================================
Installed: $(Get-Date -Format "yyyy-MM-dd HH:mm:ss UTC")
Elasticsearch: $EsVersion
Version: $Version
Scala: $ScalaVersion
Java Required: ${REQUIRED_JAVA_VERSION}+
Artifact: $ARTIFACT_NAME
"@
$versionContent | Out-File -FilePath "$Target\VERSION" -Encoding UTF8
Write-Success "Created $Target\VERSION"
}
# =============================================================================
# Print Summary
# =============================================================================
function Print-Summary {
Write-Host ""
Write-Host "==================================================================" -ForegroundColor Green
Write-Host " SoftClient4ES Installation Complete!" -ForegroundColor Green
Write-Host "==================================================================" -ForegroundColor Green
Write-Host ""
Write-Host " Installation directory: $Target"
Write-Host " Elasticsearch version: $EsVersion"
Write-Host " SoftClient4ES version: $Version"
Write-Host " Java required: ${REQUIRED_JAVA_VERSION}+"
Write-Host ""
Write-Host " Directory structure:"
Write-Host " $Target\"
Write-Host " +-- bin\"
Write-Host " | +-- softclient4es.bat"
Write-Host " | \-- softclient4es.ps1"
Write-Host " +-- conf\"
Write-Host " | +-- application.conf"
Write-Host " | \-- logback.xml"
Write-Host " +-- lib\"
Write-Host " | \-- $JAR_NAME"
Write-Host " +-- logs\"
Write-Host " | \-- (runtime logs)"
Write-Host " +-- LICENSE"
Write-Host " +-- README.md"
Write-Host " +-- VERSION"
Write-Host " \-- uninstall.ps1"
Write-Host ""
Write-Host " To start the REPL:"
Write-Host " $Target\bin\softclient4es.bat" -ForegroundColor Cyan
Write-Host " or"
Write-Host " $Target\bin\softclient4es.ps1" -ForegroundColor Cyan
Write-Host ""
Write-Host " Or add to your PATH:"
Write-Host " `$env:PATH += `";$Target\bin`"" -ForegroundColor Cyan
Write-Host ""
Write-Host " Documentation:"
Write-Host " Get-Content $Target\README.md" -ForegroundColor Cyan
Write-Host ""
Write-Host " Configuration:"
Write-Host " Application: $Target\conf\application.conf"
Write-Host " Logging: $Target\conf\logback.xml"
Write-Host ""
Write-Host " Log files:"
Write-Host " $Target\logs\softclient4es.log" -ForegroundColor Yellow
Write-Host ""
Write-Host " To uninstall:"
Write-Host " $Target\uninstall.ps1" -ForegroundColor Cyan
Write-Host ""
}
# =============================================================================
# Main
# =============================================================================
Write-Host ""
Write-Host "==================================================================" -ForegroundColor Cyan
Write-Host " SoftClient4ES Installer" -ForegroundColor Cyan
Write-Host "==================================================================" -ForegroundColor Cyan
Write-Host ""
Check-Prerequisites
Create-Directories
Download-Jar
Download-Docs
Create-Config
Create-LogbackConfig # <-- Création du fichier logback.xml
Create-Launcher
Create-Uninstaller
Create-VersionInfo
Print-Summary