Skip to content

Commit 7a01e76

Browse files
committed
harden AE6E66 module installer
1 parent c8826c6 commit 7a01e76

1 file changed

Lines changed: 37 additions & 33 deletions

File tree

modules/AE6E66/install/install.sh

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# AE6E66™ — Module Install Script
3-
# Ensures UFW firewall is installed/enabled and module ports are open.
4-
# Usage: sudo bash install/install.sh
5-
set -e
3+
# Location-independent, idempotent module installation.
4+
set -euo pipefail
65

7-
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
87
MOD_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
9-
NWE_ROOT="$(cd "$MOD_ROOT/../.." 2>/dev/null && pwd)"
10-
[ -f "$NWE_ROOT/scripts/nwe-ports.sh" ] && source "$NWE_ROOT/scripts/nwe-ports.sh"
8+
NWE_ROOT="$(cd "$MOD_ROOT/../.." && pwd)"
9+
PORTS_LIB="$NWE_ROOT/scripts/nwe-ports.sh"
10+
DB_SETUP="$MOD_ROOT/servlets/setup-db.sh"
11+
12+
[[ -d "$NWE_ROOT" && -d "$NWE_ROOT/scripts" ]] || {
13+
echo "[FAIL] Unable to resolve NWE repository root: $NWE_ROOT" >&2
14+
exit 1
15+
}
16+
17+
if [[ -f "$PORTS_LIB" ]]; then
18+
# shellcheck source=/dev/null
19+
source "$PORTS_LIB"
20+
fi
1121

1222
echo "═══════════════════════════════════════════════════════════════"
1323
echo " AE6E66™ — Module Install"
24+
echo " Repository: $NWE_ROOT"
1425
echo "═══════════════════════════════════════════════════════════════"
15-
echo ""
1626

17-
# 1. Database setup
1827
echo "[1/2] Database setup..."
19-
if [ -f "$MOD_ROOT/servlets/setup-db.sh" ]; then
20-
bash "$MOD_ROOT/servlets/setup-db.sh" && echo " [✓] Database nwe_ae6e66 ready" || echo " [!] Database setup had issues"
28+
if [[ -f "$DB_SETUP" ]]; then
29+
bash "$DB_SETUP"
30+
echo " [✓] Database setup completed"
2131
else
22-
echo " [--] No setup-db.sh found (database may already exist)"
32+
echo " [--] No setup-db.sh found; database setup skipped"
2333
fi
2434

25-
# 2. Firewall (UFW install + enable + open ports)
26-
echo ""
35+
echo
2736
echo "[2/2] Configuring firewall..."
28-
if type nwe_ensure_ufw &>/dev/null; then
37+
if declare -F nwe_ensure_ufw >/dev/null 2>&1; then
2938
nwe_ensure_ufw
30-
sudo ufw allow 8080/tcp >/dev/null 2>&1 && echo " [✓] Port 8080 (Tomcat) opened" || true
31-
32-
else
33-
echo " [--] NWE port library not available — installing UFW manually..."
34-
if command -v apt-get &>/dev/null; then
35-
sudo apt-get install -y -qq ufw >/dev/null 2>&1
36-
elif command -v dnf &>/dev/null; then
37-
sudo dnf install -y -q ufw >/dev/null 2>&1
38-
fi
39-
if command -v ufw &>/dev/null; then
40-
sudo ufw allow 22/tcp >/dev/null 2>&1
41-
sudo ufw allow 8080/tcp >/dev/null 2>&1
39+
fi
4240

43-
sudo ufw --force enable >/dev/null 2>&1
44-
echo " [✓] UFW installed and ports opened"
41+
if command -v ufw >/dev/null 2>&1; then
42+
if [[ "$(id -u)" -eq 0 ]]; then
43+
ufw allow 8080/tcp >/dev/null
44+
elif command -v sudo >/dev/null 2>&1; then
45+
sudo ufw allow 8080/tcp >/dev/null
4546
else
46-
echo " [!] Could not install UFW — open ports manually"
47+
echo "[FAIL] UFW is installed but root/sudo access is unavailable." >&2
48+
exit 1
4749
fi
50+
echo " [✓] Port 8080 (Tomcat) configured"
51+
else
52+
echo " [--] UFW unavailable; firewall configuration skipped"
4853
fi
4954

50-
echo ""
55+
echo
5156
echo "═══════════════════════════════════════════════════════════════"
5257
echo " AE6E66™ install complete."
53-
54-
echo " Frontend: http://localhost:8080/ae6e66/"
58+
echo " Frontend: http://localhost:8080/ae6e66/"
5559
echo "═══════════════════════════════════════════════════════════════"

0 commit comments

Comments
 (0)