-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·1358 lines (1160 loc) · 49.5 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·1358 lines (1160 loc) · 49.5 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
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#
# SoftClient4ES Installation Script
# For Linux and macOS
#
set -e
# =============================================================================
# Default Configuration
# =============================================================================
DEFAULT_TARGET_DIR="$HOME/softclient4es"
DEFAULT_ES_VERSION="8"
DEFAULT_SOFT_VERSION="latest"
DEFAULT_SCALA_VERSION="2.13"
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"
# =============================================================================
# Colors and Output
# =============================================================================
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# IMPORTANT: All logging goes to stderr so it doesn't pollute function return values
info() { echo -e "${BLUE}[INFO]${NC} $1" >&2; }
success() { echo -e "${GREEN}[OK]${NC} $1" >&2; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1" >&2; }
error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
# =============================================================================
# Detect OS
# =============================================================================
detect_os() {
case "$OSTYPE" in
linux*) echo "linux" ;;
darwin*) echo "macos" ;;
msys*) echo "windows" ;;
cygwin*) echo "windows" ;;
*) echo "unknown" ;;
esac
}
OS_TYPE=$(detect_os)
# =============================================================================
# Portable Version Sort
# =============================================================================
# Sort versions portably (works on both GNU and BSD)
sort_versions() {
# Try sort -V first (GNU sort)
if echo "1.0.0" | sort -V &>/dev/null; then
sort -V
else
# Fallback: numeric sort by version components
sort -t. -k1,1n -k2,2n -k3,3n -k4,4n
fi
}
# =============================================================================
# Portable JSON URI Extraction
# =============================================================================
# Extract URIs from JFrog API JSON response
# Works on both GNU grep (Linux) and BSD grep (macOS)
# Works on both compact (single-line) and pretty-printed JSON
# Filters out hidden files (starting with .) and maven-metadata.xml
extract_uris_from_json() {
# grep -oE prints each match on its own line, handles any JSON format
# Step 1: extract "uri" : "/..." substrings (path URIs starting with /)
# Step 2: extract the /value part
# Step 3: strip the leading /
grep -oE '"uri"[[:space:]]*:[[:space:]]*"/[^"]+"' \
| grep -oE '/[^"]+' \
| cut -c2- \
| grep -v '^\.' \
| grep -v '^maven-metadata' \
| grep -v '\.xml$' \
| grep -v '\.md5$' \
| grep -v '\.sha'
}
# =============================================================================
# Portable Java Version Detection
# =============================================================================
# Get Java major version (works on Linux and macOS)
get_java_version() {
local java_version_output
java_version_output=$(java -version 2>&1 | head -n 1)
local java_version=""
# Extract the version string between quotes
# Examples: "1.8.0_292", "11.0.11", "17.0.1", "21"
local version_string
version_string=$(echo "$java_version_output" | sed 's/.*"\(.*\)".*/\1/')
if [[ -z "$version_string" ]]; then
echo ""
return
fi
# Check if it starts with "1." (old format like 1.8)
if [[ "$version_string" == 1.* ]]; then
# Old format: 1.8.0_xxx -> extract 8
java_version=$(echo "$version_string" | cut -d'.' -f2)
else
# New format: 11.0.11, 17.0.1, 21 -> extract first number
java_version=$(echo "$version_string" | cut -d'.' -f1)
fi
echo "$java_version"
}
# =============================================================================
# Help
# =============================================================================
show_help() {
cat << EOF
SoftClient4ES Installation Script
Usage: $0 [OPTIONS]
Options:
-t, --target <dir> Installation directory (default: $DEFAULT_TARGET_DIR)
-e, --es-version <ver> Elasticsearch major version: 6, 7, 8, 9 (default: $DEFAULT_ES_VERSION)
-v, --version <ver> Version to install (default: latest). On the default
path this selects a BUNDLE version (the -all artifact
has its own version line); with --no-extensions (or
when no bundle matches) it selects an ENGINE version.
-s, --scala <ver> Scala version (default: $DEFAULT_SCALA_VERSION)
-l, --list-versions List available versions for the specified ES version
(bundle versions by default, engine versions with
--no-extensions)
--no-extensions Install the plain, pure Apache-2.0 engine only
(no cross-index JOINs, no materialized views)
-h, --help Show this help message
Default install = ONE self-contained -all bundle:
engine + community extensions + arrow JOIN extension + all dependencies in a
single jar (no install-time dependency resolution). The bundle contains
components under the Elastic License 2.0 plus the proprietary JOIN engine
(free to use) — it is NOT a pure Apache-2.0 artifact.
Fallback (no bundle published / engine-version -v / Java < 11): the plain
Apache-2.0 engine assembly + extensions resolved via coursier as before.
--no-extensions always yields a pure Apache-2.0 install.
Bundle bugs: https://github.com/SOFTNETWORK-APP/SoftClient4ES/issues
Extensions on the FALLBACK path (resolved with all their dependencies):
- community extensions (materialized views): always — any engine version, Java 8+
- arrow extensions (cross-index JOINs): engine >= 0.20; requires Java 11+
(Apache Arrow constraint)
Java Requirements:
ES 6, 7, 8 → Java 11 or higher (the 0.20+ CLI bundles logback 1.5.x = Java-11 bytecode)
ES 9 → Java 17 or higher
Examples:
$0
$0 --list-versions --es-version 8
$0 --target /opt/softclient4es --es-version 8 --no-extensions
$0 -t ~/tools/softclient4es -e 7 -v 0.20.4 --no-extensions
Detected OS: $OS_TYPE
EOF
exit 0
}
# =============================================================================
# Parse Arguments
# =============================================================================
TARGET_DIR="$DEFAULT_TARGET_DIR"
ES_VERSION="$DEFAULT_ES_VERSION"
SOFT_VERSION="$DEFAULT_SOFT_VERSION"
SCALA_VERSION="$DEFAULT_SCALA_VERSION"
LIST_VERSIONS=false
WITH_EXTENSIONS=true
while [[ $# -gt 0 ]]; do
case $1 in
-t|--target)
TARGET_DIR="$2"
shift 2
;;
-e|--es-version)
ES_VERSION="$2"
shift 2
;;
-v|--version)
SOFT_VERSION="$2"
shift 2
;;
-s|--scala)
SCALA_VERSION="$2"
shift 2
;;
-l|--list-versions)
LIST_VERSIONS=true
shift
;;
--no-extensions)
WITH_EXTENSIONS=false
shift
;;
--extensions)
WITH_EXTENSIONS=true
shift
;;
-h|--help)
show_help
;;
*)
error "Unknown option: $1"
show_help
;;
esac
done
# =============================================================================
# Validate Inputs
# =============================================================================
if [[ ! "$ES_VERSION" =~ ^[6-9]$ ]]; then
error "Invalid Elasticsearch version: $ES_VERSION (must be 6, 7, 8, or 9)"
exit 1
fi
# =============================================================================
# Derived Variables
# =============================================================================
# Plain artifact: the pure Apache-2.0 engine assembly (published by elasticsql).
PLAIN_ARTIFACT_NAME="softclient4es${ES_VERSION}-cli_${SCALA_VERSION}"
# Bundle artifact: the self-contained -all assembly (engine + community
# extensions + arrow JOIN extension + all dependencies), published by the
# softclient4es-repl packaging repo on its OWN version line.
BUNDLE_ARTIFACT_NAME="softclient4es${ES_VERSION}-cli-all_${SCALA_VERSION}"
# ARTIFACT_NAME is finalized by the bundle-selection block below; until then it
# refers to the plain artifact (fallback/legacy paths).
ARTIFACT_NAME="$PLAIN_ARTIFACT_NAME"
# =============================================================================
# Get Required Java Version
# =============================================================================
get_required_java_version() {
local es_ver="$1"
if [[ "$es_ver" == "9" ]]; then
echo 17
else
# The 0.20+ CLI bundles logback 1.5.x (Java-11 bytecode): the REPL
# does not start on Java 8 — verified empirically (--help crashes
# with UnsupportedClassVersionError on Zulu 8).
echo 11
fi
}
REQUIRED_JAVA_VERSION=$(get_required_java_version "$ES_VERSION")
# =============================================================================
# Fetch Versions from Repository
# =============================================================================
fetch_versions() {
local artifact="${1:-$PLAIN_ARTIFACT_NAME}"
local api_url="${JFROG_API_URL}/${artifact}"
local response=""
if command -v curl &> /dev/null; then
response=$(curl -fsSL "$api_url" 2>/dev/null)
elif command -v wget &> /dev/null; then
response=$(wget -qO- "$api_url" 2>/dev/null)
else
error "curl or wget is required"
return 1
fi
if [[ -z "$response" ]]; then
error "Failed to fetch versions from repository"
error "URL: $api_url"
error "Artifact: $artifact"
return 1
fi
# Parse JSON response and extract clean version list
echo "$response" | extract_uris_from_json | sort_versions
}
# =============================================================================
# List Available Versions
# =============================================================================
list_available_versions() {
info "Fetching available versions for ES$ES_VERSION..."
# List the versions of the artifact the install would actually download:
# the -all bundle by default (its OWN version line), the plain artifact
# under --no-extensions or when no bundle is published.
local listed_artifact versions
if [[ "$WITH_EXTENSIONS" == true ]]; then
listed_artifact="$BUNDLE_ARTIFACT_NAME"
# `|| true`: an empty bundle listing must fall through (set -e is active)
versions=$(fetch_versions "$listed_artifact" 2>/dev/null || true)
if [[ -z "$versions" ]]; then
warn "No -all bundle versions found for $listed_artifact — listing the plain artifact instead"
listed_artifact="$PLAIN_ARTIFACT_NAME"
versions=$(fetch_versions "$listed_artifact")
fi
else
listed_artifact="$PLAIN_ARTIFACT_NAME"
versions=$(fetch_versions "$listed_artifact")
fi
if [[ -z "$versions" ]]; then
error "No versions found for $listed_artifact"
exit 1
fi
echo ""
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${CYAN} Available SoftClient4ES Versions for Elasticsearch $ES_VERSION${NC}"
echo -e "${CYAN}═══════════════════════════════════════════════════════════════${NC}"
echo ""
echo -e " ${YELLOW}Artifact:${NC} $listed_artifact"
echo -e " ${YELLOW}Java required:${NC} $REQUIRED_JAVA_VERSION+"
echo ""
echo -e " ${GREEN}Versions:${NC}"
echo ""
# Display versions
local count=0
while IFS= read -r version; do
if [[ -n "$version" ]]; then
echo " • $version"
(( ++count ))
fi
done <<< "$versions"
echo ""
echo -e " ${BLUE}Total: $count version(s)${NC}"
echo ""
echo " To install a specific version:"
echo -e " ${CYAN}$0 --es-version $ES_VERSION --version <version>${NC}"
echo ""
exit 0
}
# Run list versions if requested
if [[ "$LIST_VERSIONS" == true ]]; then
list_available_versions
fi
# =============================================================================
# Resolve Latest Version
# =============================================================================
resolve_latest_version() {
info "Resolving latest version..."
# Latest of the PLAIN artifact (engine version line) — used on the
# fallback/--no-extensions paths; the bundle path resolves its latest
# from the bundle listing in the bundle-selection block below.
local versions
versions=$(fetch_versions "$PLAIN_ARTIFACT_NAME")
if [[ -z "$versions" ]]; then
error "Could not fetch versions"
echo ""
return 1
fi
# Prefer non-snapshot versions
local latest
latest=$(echo "$versions" | grep -v 'SNAPSHOT' | tail -1)
# Fallback to any version if no release found
if [[ -z "$latest" ]]; then
latest=$(echo "$versions" | tail -1)
fi
if [[ -z "$latest" ]]; then
error "Could not determine latest version"
echo ""
return 1
fi
# Return ONLY the version string (no other output)
echo "$latest"
}
# =============================================================================
# Bundle Selection: default install = ONE self-contained -all assembly
# =============================================================================
# (This block owns latest-resolution for BOTH paths: the bundle listing first,
# the plain listing on fallback. The version list consulted is always the list
# of the artifact actually downloaded — the bundle has its OWN version line.)
# Remember whether the user asked for "latest" (needed if the bundle path is
# abandoned later by the existence probe — the plain latest must be re-resolved).
REQUESTED_VERSION="$SOFT_VERSION"
USE_BUNDLE=false
if [[ "$WITH_EXTENSIONS" == true ]]; then
# NOTE: the trailing `|| true` matters — with `set -e` an empty listing
# (no bundles published yet → grep exits 1) must fall back, not abort.
bundle_versions=$(fetch_versions "$BUNDLE_ARTIFACT_NAME" 2>/dev/null | grep -v 'SNAPSHOT' || true)
if [[ -n "$bundle_versions" ]]; then
if [[ "$SOFT_VERSION" == "latest" ]]; then
SOFT_VERSION=$(echo "$bundle_versions" | tail -1) # bundle-version line (0.20.1, 0.20.2, 0.20.3, ...)
USE_BUNDLE=true
success "Resolved latest -all bundle version: $SOFT_VERSION"
elif echo "$bundle_versions" | grep -qx "$SOFT_VERSION"; then
USE_BUNDLE=true # -v selects a BUNDLE version on the default path
else
warn "No -all bundle for version $SOFT_VERSION — falling back to the plain artifact + extensions resolution"
fi
else
warn "No -all bundles published for $BUNDLE_ARTIFACT_NAME — falling back to the plain artifact + extensions resolution"
fi
# Belt-and-braces: the bundle needs Java 11+ (Arrow/logback bytecode);
# check_prerequisites aborts below the ES-version floor anyway.
java_version=$(get_java_version)
if [[ -n "$java_version" ]] && [[ "$java_version" -lt 11 ]]; then
if [[ "$USE_BUNDLE" == true ]]; then
warn "Java $java_version found — the -all bundle requires Java 11+; falling back to the plain artifact"
USE_BUNDLE=false
SOFT_VERSION="$REQUESTED_VERSION"
fi
fi
fi
if [[ "$USE_BUNDLE" != true ]] && [[ "$SOFT_VERSION" == "latest" ]]; then
# Plain/fallback path: resolve latest from the PLAIN artifact's listing
# (`|| true` keeps set -e from aborting before the empty-check below)
SOFT_VERSION=$(resolve_latest_version || true)
if [[ -z "$SOFT_VERSION" ]]; then
error "Failed to resolve latest version"
error "Try specifying a version manually with --version"
error "Or run with --list-versions to see available versions"
exit 1
fi
success "Resolved latest version: $SOFT_VERSION"
fi
if [[ "$USE_BUNDLE" == true ]]; then
ARTIFACT_NAME="$BUNDLE_ARTIFACT_NAME"
else
ARTIFACT_NAME="$PLAIN_ARTIFACT_NAME"
fi
JAR_NAME="${ARTIFACT_NAME}-${SOFT_VERSION}-assembly.jar"
DOWNLOAD_URL="${JFROG_REPO_URL}/${ARTIFACT_NAME}/${SOFT_VERSION}/${JAR_NAME}"
# ── Existence probe (belt-and-braces over the listing check: covers a pruned
# scala variant or a listing/artifact race). Self-contained — never rely on
# $DOWNLOADER, which is only set later inside check_prerequisites().
probe_url() {
local url="$1"
if command -v curl &> /dev/null; then
curl -fsI "$url" > /dev/null 2>&1
elif command -v wget &> /dev/null; then
wget -q --spider "$url" 2>/dev/null
else
return 1
fi
}
if [[ "$USE_BUNDLE" == true ]]; then
if ! probe_url "$DOWNLOAD_URL"; then
warn "-all bundle not reachable at $DOWNLOAD_URL"
warn "Falling back to the plain artifact + extensions resolution"
USE_BUNDLE=false
SOFT_VERSION="$REQUESTED_VERSION"
if [[ "$SOFT_VERSION" == "latest" ]]; then
SOFT_VERSION=$(resolve_latest_version || true)
if [[ -z "$SOFT_VERSION" ]]; then
error "Failed to resolve latest version"
exit 1
fi
success "Resolved latest version: $SOFT_VERSION"
fi
ARTIFACT_NAME="$PLAIN_ARTIFACT_NAME"
JAR_NAME="${ARTIFACT_NAME}-${SOFT_VERSION}-assembly.jar"
DOWNLOAD_URL="${JFROG_REPO_URL}/${ARTIFACT_NAME}/${SOFT_VERSION}/${JAR_NAME}"
fi
fi
# =============================================================================
# Check Prerequisites
# =============================================================================
check_prerequisites() {
info "Checking prerequisites..."
info "Detected OS: $OS_TYPE"
# Check Java
if ! command -v java &> /dev/null; then
error "Java is not installed."
error "ES$ES_VERSION requires Java $REQUIRED_JAVA_VERSION or higher."
case "$OS_TYPE" in
macos)
error "Install with: brew install openjdk@$REQUIRED_JAVA_VERSION"
;;
linux)
error "Install with: sudo apt install openjdk-$REQUIRED_JAVA_VERSION-jdk"
error " or: sudo yum install java-$REQUIRED_JAVA_VERSION-openjdk"
;;
esac
exit 1
fi
# Get Java version (portable)
local java_version
java_version=$(get_java_version)
if [[ -z "$java_version" ]]; then
warn "Could not determine Java version. Proceeding anyway..."
else
if [[ "$java_version" -lt "$REQUIRED_JAVA_VERSION" ]]; then
error "Java $REQUIRED_JAVA_VERSION or higher is required for ES$ES_VERSION."
error "Found: Java $java_version"
exit 1
fi
success "Java $java_version found (required: $REQUIRED_JAVA_VERSION+)"
fi
# Check curl or wget
if command -v curl &> /dev/null; then
DOWNLOADER="curl"
elif command -v wget &> /dev/null; then
DOWNLOADER="wget"
else
error "curl or wget is required for downloading artifacts."
exit 1
fi
success "$DOWNLOADER found"
}
# =============================================================================
# Create Directory Structure
# =============================================================================
create_directories() {
info "Creating directory structure..."
mkdir -p "$TARGET_DIR/bin"
mkdir -p "$TARGET_DIR/conf"
mkdir -p "$TARGET_DIR/lib"
mkdir -p "$TARGET_DIR/logs"
success "Created $TARGET_DIR/{bin,conf,lib,logs}"
}
# =============================================================================
# Download File Helper
# =============================================================================
download_file() {
local url="$1"
local dest="$2"
local description="$3"
info "Downloading $description..."
if [[ "$DOWNLOADER" == "curl" ]]; then
if ! curl -fsSL -o "$dest" "$url" 2>/dev/null; then
warn "Failed to download $description from $url"
return 1
fi
else
if ! wget -q -O "$dest" "$url" 2>/dev/null; then
warn "Failed to download $description from $url"
return 1
fi
fi
success "Downloaded $description"
return 0
}
# =============================================================================
# Download JAR
# =============================================================================
download_jar() {
info "Downloading $JAR_NAME..."
info "URL: $DOWNLOAD_URL"
local dest="$TARGET_DIR/lib/$JAR_NAME"
if [[ "$DOWNLOADER" == "curl" ]]; then
if ! curl -fSL --progress-bar -o "$dest" "$DOWNLOAD_URL"; then
error "Failed to download JAR from $DOWNLOAD_URL"
error "Please check that version '$SOFT_VERSION' exists."
error "Run with --list-versions to see available versions."
exit 1
fi
else
if ! wget -q --show-progress -O "$dest" "$DOWNLOAD_URL"; then
error "Failed to download JAR from $DOWNLOAD_URL"
error "Please check that version '$SOFT_VERSION' exists."
error "Run with --list-versions to see available versions."
exit 1
fi
fi
success "Downloaded to $dest"
}
# =============================================================================
# Extract the licence bundle (bundle installs only)
# The -all jar mixes Apache-2.0 + ELv2 + proprietary: materialize licenses/
# and NOTICE into the install root so the visible tree is not just the
# Apache-2.0 LICENSE. Failure-tolerant (set -e): the jar keeps the canonical
# copies either way.
# =============================================================================
extract_bundle_licenses() {
[[ "$USE_BUNDLE" == true ]] || return 0
local jar="$TARGET_DIR/lib/$JAR_NAME"
info "Extracting licence bundle (licenses/ + NOTICE) from $JAR_NAME..."
if command -v unzip >/dev/null 2>&1; then
if unzip -o -q "$jar" 'licenses/*' NOTICE -d "$TARGET_DIR" 2>/dev/null; then
success "Extracted licenses/ and NOTICE to $TARGET_DIR"
return 0
fi
elif command -v jar >/dev/null 2>&1; then
if (cd "$TARGET_DIR" && jar -xf "$jar" licenses NOTICE) 2>/dev/null; then
success "Extracted licenses/ and NOTICE to $TARGET_DIR"
return 0
fi
fi
warn "Could not extract the licence bundle (unzip/jar unavailable or failed)."
warn "The canonical copies remain inside the jar: licenses/ and NOTICE."
}
# =============================================================================
# Install Extensions (cross-index JOINs, materialized views)
# =============================================================================
# The engine assembly is launched via classpath (bin/softclient4es uses -cp
# "lib/*"), so extension jars dropped into lib/ are discovered through the
# ServiceLoader SPI. The extensions are thin jars: their full dependency
# closure (Apache Arrow, DuckDB, ...) must be resolved too — a couple of jars
# is NOT enough. We bootstrap the coursier launcher (a single portable jar
# that runs with the already-required java) to resolve everything.
COURSIER_URL="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/coursier/launchers/raw/master/coursier"
JFROG_ROOT_URL="https://softnetwork.jfrog.io/artifactory/releases"
EXTENSIONS_INSTALLED="none"
# version_ge A B — true if version A >= version B
version_ge() {
[[ "$(printf '%s\n%s\n' "$2" "$1" | sort_versions | head -1)" == "$2" ]]
}
# Resolve one extension (with its full dependency closure) into lib/.
# $1 = artifact base name (without scala suffix), $2 = version
install_one_extension() {
local ext="$1"
local ver="$2"
local artifact="${ext}_${SCALA_VERSION}"
local cs="$TARGET_DIR/bin/.coursier"
local jars jar base_jar count
info "Resolving ${artifact}:${ver} with all dependencies..."
if ! jars=$("$cs" fetch --repository "$JFROG_ROOT_URL" "app.softnetwork.elastic:${artifact}:${ver}" 2>/dev/null); then
warn "Dependency resolution failed for $artifact — skipping"
return 1
fi
count=0
while IFS= read -r jar; do
[[ -f "$jar" ]] || continue
base_jar=$(basename "$jar")
if [[ ! -f "$TARGET_DIR/lib/$base_jar" ]]; then
cp "$jar" "$TARGET_DIR/lib/$base_jar"
(( ++count )) || true
fi
done <<< "$jars"
success "Installed ${artifact}:${ver} ($count jar(s) added to lib/)"
if [[ "$EXTENSIONS_INSTALLED" == "none" ]]; then
EXTENSIONS_INSTALLED="${ext}:${ver}"
else
EXTENSIONS_INSTALLED="$EXTENSIONS_INSTALLED ${ext}:${ver}"
fi
return 0
}
install_extensions() {
if [[ "$USE_BUNDLE" == true ]]; then
info "Extensions are bundled inside $JAR_NAME — no dependency resolution needed"
EXTENSIONS_INSTALLED="bundled (community + arrow JOIN)"
extract_bundle_licenses
return 0
fi
if [[ "$WITH_EXTENSIONS" != true ]]; then
info "Skipping extensions (--no-extensions)"
return 0
fi
info "Installing extensions (materialized views + cross-index JOINs)..."
local cs="$TARGET_DIR/bin/.coursier"
if [[ ! -x "$cs" ]]; then
if ! download_file "$COURSIER_URL" "$cs" "coursier resolver"; then
warn "Could not download the coursier resolver — extensions skipped."
warn "Manual install: https://github.com/SOFTNETWORK-APP/SoftClient4ES/blob/main/documentation/client/repl.md"
return 0
fi
chmod +x "$cs"
fi
local java_version
java_version=$(get_java_version)
# ── Community extensions (materialized views) — ALWAYS installed by default.
# No Arrow dependency, runs on Java 8+. For engines < 0.20 the matching
# 0.1.x line is selected; for >= 0.20 the latest release.
local community_ver
if version_ge "$SOFT_VERSION" "0.20"; then
community_ver=$(fetch_versions "softclient4es-community-extensions_${SCALA_VERSION}" | grep -v 'SNAPSHOT' | tail -1)
else
community_ver=$(fetch_versions "softclient4es-community-extensions_${SCALA_VERSION}" | grep -v 'SNAPSHOT' | grep '^0\.1\.' | tail -1)
fi
if [[ -n "$community_ver" ]]; then
install_one_extension "softclient4es-community-extensions" "$community_ver" || true
else
warn "Could not resolve a community-extensions release for engine $SOFT_VERSION — skipping"
fi
# ── Arrow extensions (cross-index JOINs) — default for engines >= 0.20.
# Hard runtime constraint: Apache Arrow 18.x ships Java-11 bytecode
# (class file major 55) — on Java 8 the JOIN engine cannot load.
if ! version_ge "$SOFT_VERSION" "0.20"; then
info "Cross-index JOIN extension requires SoftClient4ES >= 0.20 (installing $SOFT_VERSION) — skipping"
return 0
fi
if [[ -n "$java_version" ]] && [[ "$java_version" -lt 11 ]]; then
warn "Cross-index JOINs require Java 11+ (Apache Arrow constraint) — found Java $java_version."
warn "Materialized views remain available; re-run the installer on Java 11+ to enable JOINs."
return 0
fi
local arrow_ver
arrow_ver=$(fetch_versions "softclient4es-arrow-extensions_${SCALA_VERSION}" | grep -v 'SNAPSHOT' | tail -1)
if [[ -n "$arrow_ver" ]]; then
install_one_extension "softclient4es-arrow-extensions" "$arrow_ver" || true
else
warn "Could not resolve an arrow-extensions release — skipping"
fi
}
# =============================================================================
# License Notice (AC 4b) — wording rules: the bundle is "free to use", NEVER
# "open source" / "source-available" / "Apache-2.0" as a whole.
# =============================================================================
print_license_notice() {
if [[ "$USE_BUNDLE" == true ]]; then
echo " License: this bundle contains the Apache-2.0 SoftClient4ES engine PLUS"
echo " SoftClient4ES extensions under the Elastic License 2.0 and the proprietary"
echo " cross-index JOIN engine (free to use; see the licenses/ directory and NOTICE"
echo " in the install root — canonical copies ship inside the jar)."
echo " Quota enforcement is active. For a pure Apache-2.0 install re-run with --no-extensions."
elif [[ "$WITH_EXTENSIONS" != true ]] || [[ "$EXTENSIONS_INSTALLED" == "none" ]]; then
echo " License: pure Apache-2.0 engine (no extensions)."
elif [[ "$EXTENSIONS_INSTALLED" == *arrow-extensions* ]]; then
echo " License: this installation contains the Apache-2.0 SoftClient4ES engine PLUS"
echo " SoftClient4ES extensions under the Elastic License 2.0 and the proprietary"
echo " cross-index JOIN engine (free to use). Quota enforcement is active."
echo " For a pure Apache-2.0 install re-run with --no-extensions."
else
echo " License: this installation contains the Apache-2.0 SoftClient4ES engine PLUS"
echo " SoftClient4ES extensions under the Elastic License 2.0 (free to use)."
echo " Quota enforcement is active. For a pure Apache-2.0 install re-run with --no-extensions."
fi
}
# =============================================================================
# Download Documentation and License
# =============================================================================
download_docs() {
info "Downloading documentation and license..."
# Download README.md
if download_file "$README_URL" "$TARGET_DIR/README.md" "README.md"; then
: # success already printed
else
warn "README.md download failed, creating minimal version"
create_minimal_readme
fi
# Download LICENSE
if download_file "$LICENSE_URL" "$TARGET_DIR/LICENSE" "LICENSE"; then
: # success already printed
else
warn "LICENSE download failed, skipping"
fi
}
# =============================================================================
# Create Minimal README (Fallback)
# =============================================================================
create_minimal_readme() {
cat > "$TARGET_DIR/README.md" << 'EOF'
# SoftClient4ES
SQL Gateway for Elasticsearch
## Quick Start
```bash
# Start the REPL
./bin/softclient4es
# Execute a single command
./bin/softclient4es -c "SHOW TABLES"
# Get help
./bin/softclient4es --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.
EOF
success "Created minimal README.md"
}
# =============================================================================
# Create Configuration File
# =============================================================================
create_config() {
info "Creating configuration file..."
cat > "$TARGET_DIR/conf/application.conf" << 'EOF'
# SoftClient4ES Configuration
# Override these settings or use command-line options
# Precedence: CLI flag > ELASTIC_* env var > this file > built-in defaults
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}
}
}
EOF
success "Created $TARGET_DIR/conf/application.conf"
}
# =============================================================================
# Create Launcher Script
# =============================================================================
create_launcher() {
info "Creating launcher script..."
cat > "$TARGET_DIR/bin/softclient4es" << LAUNCHER_EOF
#!/usr/bin/env bash
#
# SoftClient4ES Launcher
# Elasticsearch version: $ES_VERSION
# Required Java: $REQUIRED_JAVA_VERSION+
#
SCRIPT_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
BASE_DIR="\$(dirname "\$SCRIPT_DIR")"
JAR_FILE="\$BASE_DIR/lib/$JAR_NAME"
CONFIG_FILE="\$BASE_DIR/conf/application.conf"
LOGBACK_FILE="\$BASE_DIR/conf/logback.xml"
LOG_DIR="\$BASE_DIR/logs"
REQUIRED_JAVA=$REQUIRED_JAVA_VERSION
if [[ ! -f "\$JAR_FILE" ]]; then
echo "Error: JAR file not found: \$JAR_FILE" >&2
exit 1
fi
# Create logs directory if it doesn't exist
mkdir -p "\$LOG_DIR"
# Check Java version (portable - works on Linux and macOS)
check_java() {
if ! command -v java &> /dev/null; then
echo "Error: Java is not installed. Java \$REQUIRED_JAVA+ is required." >&2
exit 1
fi
local java_version_output
java_version_output=\$(java -version 2>&1 | head -n 1)
# Extract version string between quotes
local version_string
version_string=\$(echo "\$java_version_output" | sed 's/.*"\(.*\)".*/\1/')
local java_version=""
if [[ "\$version_string" == 1.* ]]; then
# Old format: 1.8.0_xxx -> extract 8
java_version=\$(echo "\$version_string" | cut -d'.' -f2)
else
# New format: 11.0.11, 17.0.1, 21 -> extract first number
java_version=\$(echo "\$version_string" | cut -d'.' -f1)
fi
if [[ -n "\$java_version" ]] && [[ "\$java_version" -lt "\$REQUIRED_JAVA" ]]; then
echo "Error: Java \$REQUIRED_JAVA+ is required. Found: Java \$java_version" >&2
exit 1
fi
JAVA_MAJOR="\$java_version"
}
check_java
# HOCON \${?VAR} substitution treats an env var set to "" as PRESENT and lets it
# override file/default values (empty host => http://:9200). Treat empty as unset.
# The ELASTIC_WATCHER_* family is included because the builtin conf carries the
# same \${?VAR} substitution lines for the watcher block.
for var in ELASTIC_SCHEME ELASTIC_HOST ELASTIC_IP ELASTIC_PORT \\
ELASTIC_USERNAME ELASTIC_PASSWORD ELASTIC_API_KEY ELASTIC_BEARER_TOKEN \\
ELASTIC_AUTH_METHOD \\
ELASTIC_CREDENTIALS_USERNAME ELASTIC_CREDENTIALS_PASSWORD \\
ELASTIC_CREDENTIALS_API_KEY ELASTIC_CREDENTIALS_BEARER_TOKEN \\
ELASTIC_WATCHER_SCHEME ELASTIC_WATCHER_HOST ELASTIC_WATCHER_PORT \\
ELASTIC_WATCHER_AUTH_METHOD ELASTIC_WATCHER_USERNAME ELASTIC_WATCHER_PASSWORD \\
ELASTIC_WATCHER_API_KEY ELASTIC_WATCHER_BEARER_TOKEN; do
if [[ -z "\${!var:-}" ]]; then
unset "\$var"
fi
done
# Default JVM options
JAVA_OPTS="\${JAVA_OPTS:--Xmx512m}"
# The extensions (Apache Arrow / DuckDB) need reflective access on Java 9+
EXTRA_OPTS=""
if [[ -n "\$JAVA_MAJOR" ]] && [[ "\$JAVA_MAJOR" -ge 9 ]]; then
EXTRA_OPTS="--add-opens=java.base/java.nio=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true"
fi
# Class-Data Sharing (AppCDS) — cuts JVM class-load time on every start (#163 fix 3).
# BUNDLE-ONLY: CDS_BUNDLE below is baked in AT INSTALL TIME from REPL.4's USE_BUNDLE