Skip to content

Commit b95054b

Browse files
committed
Science Commit 5.
1 parent 19863ff commit b95054b

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

scripts/populate-db-properties.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
# ═══════════════════════════════════════════════════════════════════════════════
3+
# NitroWebExpress™ — Populate db.properties for All Deployed Webapps
4+
# Generates db.properties from .nwe-credentials for every module in Tomcat.
5+
#
6+
# Usage: bash scripts/populate-db-properties.sh [tomcat_home]
7+
# ═══════════════════════════════════════════════════════════════════════════════
8+
set -uo pipefail
9+
10+
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
11+
TOMCAT_HOME="${1:-${CATALINA_HOME:-/home/mearvk/tomcat}}"
12+
13+
source "$PROJECT_ROOT/scripts/deploy-functions.sh"
14+
15+
# context → database name
16+
declare -A WEBAPP_DBS=(
17+
["california-fbi"]="nwe_california_fbi"
18+
["california-cia"]="nwe_california_cia"
19+
["california-nsa"]="nwe_california_nsa"
20+
["california-duke"]="nwe_duke"
21+
["library"]="nwe_library"
22+
["ae6e66"]="nwe_ae6e66"
23+
["futures"]="nwe_futures"
24+
["gdgh"]="nwe_gdgh"
25+
["gray-registry"]="nwe_gray_registry"
26+
["gray85-registry"]="nwe_gray85_registry"
27+
["brarner.m.alete"]="BrarnerScience"
28+
)
29+
30+
echo ""
31+
echo "╔═══════════════════════════════════════════════════════════════════════════╗"
32+
echo "║ NitroWebExpress™ — Populate db.properties ║"
33+
echo "║ Tomcat: $TOMCAT_HOME"
34+
echo "║ Source: $PROJECT_ROOT/.nwe-credentials"
35+
echo "╚═══════════════════════════════════════════════════════════════════════════╝"
36+
echo ""
37+
38+
# Check .nwe-credentials exists
39+
if [ ! -f "$PROJECT_ROOT/.nwe-credentials" ]; then
40+
echo "[FAIL] .nwe-credentials not found at $PROJECT_ROOT/.nwe-credentials"
41+
echo ""
42+
echo " Create it:"
43+
echo " cat > $PROJECT_ROOT/.nwe-credentials <<EOF"
44+
echo ' NWE_DB_HOST="127.0.0.1"'
45+
echo ' NWE_DB_PORT="3306"'
46+
echo ' NWE_DB_USER="root"'
47+
echo ' NWE_DB_PASS="yourpassword"'
48+
echo " EOF"
49+
echo " chmod 600 $PROJECT_ROOT/.nwe-credentials"
50+
exit 1
51+
fi
52+
53+
GENERATED=0
54+
SKIPPED=0
55+
MISSING=0
56+
57+
for CONTEXT in "${!WEBAPP_DBS[@]}"; do
58+
DB_NAME="${WEBAPP_DBS[$CONTEXT]}"
59+
WEBAPP_DIR="$TOMCAT_HOME/webapps/$CONTEXT"
60+
61+
if [ ! -d "$WEBAPP_DIR" ]; then
62+
echo " [SKIP] /$CONTEXT — webapp not deployed"
63+
MISSING=$((MISSING + 1))
64+
continue
65+
fi
66+
67+
DB_PROPS="$WEBAPP_DIR/WEB-INF/db.properties"
68+
69+
# Check if already valid
70+
if [ -f "$DB_PROPS" ] && grep -q "db.password=." "$DB_PROPS" 2>/dev/null && ! grep -q "CHANGE_ME\|PLACEHOLDER" "$DB_PROPS" 2>/dev/null; then
71+
echo " [OK] /$CONTEXT — already configured"
72+
SKIPPED=$((SKIPPED + 1))
73+
continue
74+
fi
75+
76+
# Generate
77+
nwe_ensure_db_properties "$WEBAPP_DIR" "$DB_NAME" "$PROJECT_ROOT"
78+
if [ -f "$DB_PROPS" ] && grep -q "db.password=." "$DB_PROPS" 2>/dev/null; then
79+
echo " [✓] /$CONTEXT$DB_NAME"
80+
GENERATED=$((GENERATED + 1))
81+
else
82+
echo " [FAIL] /$CONTEXT — generation failed"
83+
fi
84+
done
85+
86+
# Also populate source webapp directories (so future deploys carry them)
87+
echo ""
88+
echo " [*] Also populating source webapp directories..."
89+
90+
declare -A SOURCE_DBS=(
91+
["modules/fbi/servlets/servlet/src/main/webapp"]="nwe_california_fbi"
92+
["modules/cia/servlets/servlet/src/main/webapp"]="nwe_california_cia"
93+
["modules/nsa/servlets/servlet/src/main/webapp"]="nwe_california_nsa"
94+
["modules/duke/servlets/servlet/src/main/webapp"]="nwe_duke"
95+
["modules/library/servlets/servlet/src/main/webapp"]="nwe_library"
96+
["modules/AE6E66/servlets/servlet/src/main/webapp"]="nwe_ae6e66"
97+
["modules/red/Futures/servlets/servlet/src/main/webapp"]="nwe_futures"
98+
["modules/Green.Durham.Grass.and.Herb/servlets/servlet/src/main/webapp"]="nwe_gdgh"
99+
["modules/gray/servlets/servlet/src/main/webapp"]="nwe_gray_registry"
100+
["modules/gray.a85/servlets/servlet/src/main/webapp"]="nwe_gray85_registry"
101+
["modules/black/presidential/Brarner.M.Alete/servlets/servlet/src/main/webapp"]="BrarnerScience"
102+
)
103+
104+
for SRC_PATH in "${!SOURCE_DBS[@]}"; do
105+
FULL="$PROJECT_ROOT/$SRC_PATH"
106+
DB_NAME="${SOURCE_DBS[$SRC_PATH]}"
107+
if [ -d "$FULL" ]; then
108+
DB_PROPS="$FULL/WEB-INF/db.properties"
109+
if [ -f "$DB_PROPS" ] && grep -q "db.password=." "$DB_PROPS" 2>/dev/null && ! grep -q "CHANGE_ME\|PLACEHOLDER" "$DB_PROPS" 2>/dev/null; then
110+
continue
111+
fi
112+
nwe_ensure_db_properties "$FULL" "$DB_NAME" "$PROJECT_ROOT" >/dev/null 2>&1
113+
fi
114+
done
115+
echo " [✓] Source directories updated"
116+
117+
echo ""
118+
echo "╔═══════════════════════════════════════════════════════════════════════════╗"
119+
echo "║ Results: $GENERATED generated | $SKIPPED already OK | $MISSING not deployed"
120+
echo "╚═══════════════════════════════════════════════════════════════════════════╝"
121+
echo ""

0 commit comments

Comments
 (0)