-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup-leocdp-database.sh
More file actions
executable file
·94 lines (80 loc) · 2.7 KB
/
Copy pathsetup-leocdp-database.sh
File metadata and controls
executable file
·94 lines (80 loc) · 2.7 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
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# ---------------------------------------
# 🧠 LEO CDP Database Setup Script
# ---------------------------------------
BUILD_VERSION="v_0.9.0"
JAR_MAIN="leo-main-starter-${BUILD_VERSION}.jar"
METADATA_FILE="./leocdp-metadata.properties"
METADATA_SETUP_SCRIPT="./setup-leocdp-metadata.sh"
# --- Helper: print colored messages ---
info() { echo -e "\033[1;34m[INFO]\033[0m $*"; }
success() { echo -e "\033[1;32m[SUCCESS]\033[0m $*"; }
error() { echo -e "\033[1;31m[ERROR]\033[0m $*" >&2; }
# --- Verify JAR existence ---
if [[ ! -f "$JAR_MAIN" ]]; then
error "$JAR_MAIN not found in current directory: $(pwd)"
exit 1
fi
# --- Verify Java installation ---
if ! command -v java &>/dev/null; then
error "Java not found. Please install Java 11 before running this script."
exit 1
fi
# --- Verify Java version = 11 ---
JAVA_VERSION_OUTPUT=$(java -version 2>&1)
if ! echo "$JAVA_VERSION_OUTPUT" | grep -q 'version "11'; then
error "Invalid Java version detected. Required: Java 11"
echo "Detected:"
echo "$JAVA_VERSION_OUTPUT"
exit 1
fi
info "✅ Java 11 detected."
# --- Check leocdp-metadata.properties existence ---
if [[ ! -f "$METADATA_FILE" ]]; then
info "⚙️ $METADATA_FILE not found."
if [[ -x "$METADATA_SETUP_SCRIPT" ]]; then
info "Running metadata setup script: $METADATA_SETUP_SCRIPT"
bash "$METADATA_SETUP_SCRIPT"
else
error "$METADATA_SETUP_SCRIPT not found or not executable."
echo "Please create $METADATA_FILE manually or provide the setup script."
exit 1
fi
fi
# --- Verify required configs exist ---
required_keys=("superAdminEmail" "mainDatabaseConfig" "systemDatabaseConfig")
for key in "${required_keys[@]}"; do
if ! grep -q "^${key}=" "$METADATA_FILE"; then
error "Missing key '$key' in $METADATA_FILE"
exit 1
fi
done
success "✅ leocdp-metadata.properties validated."
# --- Prompt for Super Admin Password ---
info "🚀 Starting LEO CDP System Setup"
echo "----------------------------------"
read -rsp "Enter the superadmin password: " superadmin_password
echo ""
read -rsp "Confirm password: " superadmin_password_confirm
echo ""
if [[ "$superadmin_password" != "$superadmin_password_confirm" ]]; then
error "Passwords do not match. Exiting setup."
exit 1
fi
if [[ -z "$superadmin_password" ]]; then
error "Password cannot be empty."
exit 1
fi
# --- Run setup ---
info "🔑 Running system database setup..."
set +e
java -jar "$JAR_MAIN" setup-system-with-password "$superadmin_password"
setup_exit_code=$?
set -e
if [[ $setup_exit_code -ne 0 ]]; then
error "Database setup failed with exit code $setup_exit_code."
exit $setup_exit_code
fi
success "🎉 LEO CDP Database setup completed successfully!"