Skip to content

Commit eebdeec

Browse files
committed
Science Commit 5.
1 parent 5cb47f3 commit eebdeec

4 files changed

Lines changed: 229 additions & 0 deletions

File tree

logging/event.social.log

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[2026-07-14 19:42:31] [BrarnerAlete] GET https://github.com/mearvk/Brarner.M.Alete/ — interesting (400578 bytes)
2+
[2026-07-14 19:42:31] [BrarnerAlete] GET https://api.github.com/repos/mearvk/Brarner.M.Alete — successful (5348 bytes)
3+
[2026-07-14 19:42:32] [BrarnerAlete] GET https://raw.githubusercontent.com/mearvk/Brarner.M.Alete/main/README.md — interesting (58 bytes)
4+
[2026-07-14 19:42:32] [BrarnerAlete] POST https://api.github.com/repos/mearvk/Brarner.M.Alete/dispatches — successful (117 bytes)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11295

scripts/deploy-remote-linux.sh

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
#!/bin/bash
2+
# ═══════════════════════════════════════════════════════════════════════════════
3+
# NitroWebExpress™ — Remote Linux Server Deploy
4+
# Deploys the full NWE system to a remote server via SSH/SCP.
5+
# Runs post-clone.sh on the remote after transferring the codebase.
6+
#
7+
# Usage: bash scripts/deploy-remote-linux.sh [user@host] [remote_path]
8+
#
9+
# Prerequisites:
10+
# - SSH key access (run ssh-copy-id first) OR sshpass installed
11+
# - Remote server: Ubuntu/Debian or RHEL/Fedora
12+
#
13+
# Capitalization reference: configuration/print-method.xml §script-descriptors
14+
# ═══════════════════════════════════════════════════════════════════════════════
15+
set -uo pipefail
16+
17+
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
18+
source "$PROJECT_ROOT/scripts/print-descriptor.sh" 2>/dev/null || true
19+
20+
# ── Configuration ─────────────────────────────────────────────────────────────
21+
DEFAULT_HOST="45.32.31.139"
22+
DEFAULT_USER="root"
23+
DEFAULT_PATH="/opt/NitroWebExpress"
24+
25+
REMOTE="${1:-${NWE_REMOTE_USER:-$DEFAULT_USER}@${NWE_REMOTE_HOST:-$DEFAULT_HOST}}"
26+
REMOTE_PATH="${2:-$DEFAULT_PATH}"
27+
REMOTE_USER="${REMOTE%%@*}"
28+
REMOTE_HOST="${REMOTE##*@}"
29+
30+
SSH_OPTS="-o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new -o ServerAliveInterval=15 -o ServerAliveCountMax=3"
31+
32+
echo "╔═══════════════════════════════════════════════════════════════════════════╗"
33+
echo "║ NitroWebExpress™ — Remote Linux Server Deploy ║"
34+
echo "║ Target: $REMOTE_USER@$REMOTE_HOST:$REMOTE_PATH"
35+
echo "║ Source: $PROJECT_ROOT"
36+
echo "╚═══════════════════════════════════════════════════════════════════════════╝"
37+
echo ""
38+
39+
# ── 1. SSH Connectivity ───────────────────────────────────────────────────────
40+
echo "[1/6] Verifying SSH access..."
41+
42+
# Check port reachable
43+
if ! timeout 5 bash -c "echo >/dev/tcp/$REMOTE_HOST/22" 2>/dev/null; then
44+
echo " [!] Port 22 not reachable on $REMOTE_HOST"
45+
exit 1
46+
fi
47+
48+
# Try key-based auth first
49+
SSH_CMD="ssh $SSH_OPTS"
50+
SCP_CMD="scp -o ConnectTimeout=10"
51+
USE_SSHPASS=false
52+
53+
if ! $SSH_CMD -o BatchMode=yes "$REMOTE" "echo OK" &>/dev/null; then
54+
echo " [*] Key-based SSH failed — trying password auth..."
55+
if ! command -v sshpass &>/dev/null; then
56+
echo " [*] Installing sshpass..."
57+
sudo apt-get install -y -qq sshpass 2>/dev/null || sudo dnf install -y -q sshpass 2>/dev/null || true
58+
fi
59+
if command -v sshpass &>/dev/null; then
60+
read -rsp " SSH password for $REMOTE: " SSH_PASS
61+
echo ""
62+
if sshpass -p "$SSH_PASS" ssh $SSH_OPTS "$REMOTE" "echo OK" &>/dev/null; then
63+
SSH_CMD="sshpass -p $SSH_PASS ssh $SSH_OPTS"
64+
SCP_CMD="sshpass -p $SSH_PASS scp -o ConnectTimeout=10"
65+
USE_SSHPASS=true
66+
echo " [✓] Password auth successful"
67+
68+
# Offer to copy SSH key for future passwordless access
69+
echo " [*] Copying SSH key for future passwordless access..."
70+
if [ ! -f ~/.ssh/id_ed25519 ] && [ ! -f ~/.ssh/id_rsa ]; then
71+
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N "" -q
72+
fi
73+
sshpass -p "$SSH_PASS" ssh-copy-id -o StrictHostKeyChecking=accept-new "$REMOTE" &>/dev/null && \
74+
echo " [✓] SSH key installed — password not needed next time" || true
75+
else
76+
echo " [!] Password auth failed"
77+
exit 1
78+
fi
79+
else
80+
echo " [!] Cannot authenticate. Install sshpass or run: ssh-copy-id $REMOTE"
81+
exit 1
82+
fi
83+
else
84+
echo " [✓] SSH key auth successful"
85+
fi
86+
87+
echo ""
88+
89+
# ── 2. Remote Preparation ────────────────────────────────────────────────────
90+
echo "[2/6] Preparing remote server..."
91+
92+
$SSH_CMD "$REMOTE" bash -s "$REMOTE_PATH" <<'REMOTE_PREP'
93+
set -e
94+
REMOTE_PATH="$1"
95+
96+
# Install essentials
97+
if command -v apt-get &>/dev/null; then
98+
export DEBIAN_FRONTEND=noninteractive
99+
apt-get update -qq 2>/dev/null
100+
apt-get install -y -qq rsync git curl ufw 2>/dev/null
101+
elif command -v dnf &>/dev/null; then
102+
dnf install -y -q rsync git curl 2>/dev/null
103+
fi
104+
105+
# Create target directory
106+
mkdir -p "$REMOTE_PATH"
107+
echo "OK"
108+
REMOTE_PREP
109+
110+
echo " [✓] Remote dependencies installed"
111+
echo ""
112+
113+
# ── 3. Transfer Codebase ─────────────────────────────────────────────────────
114+
echo "[3/6] Transferring codebase to $REMOTE_HOST:$REMOTE_PATH..."
115+
echo " (excluding .git, out/, target/, node_modules, large binaries)"
116+
117+
# Use rsync if available (faster, incremental), fall back to scp
118+
if command -v rsync &>/dev/null; then
119+
RSYNC_OPTS="-az --delete --progress --stats"
120+
RSYNC_EXCLUDE="--exclude=.git --exclude=out --exclude=target --exclude=node_modules --exclude=*.jar --exclude=.djl.ai --exclude='*.MOV' --exclude='*.MP4' --exclude='*.zip'"
121+
122+
if [ "$USE_SSHPASS" = true ]; then
123+
RSYNC_SSH="sshpass -p $SSH_PASS ssh $SSH_OPTS"
124+
else
125+
RSYNC_SSH="ssh $SSH_OPTS"
126+
fi
127+
128+
rsync $RSYNC_OPTS $RSYNC_EXCLUDE -e "$RSYNC_SSH" \
129+
"$PROJECT_ROOT/" "$REMOTE:$REMOTE_PATH/" 2>&1 | tail -5
130+
else
131+
# Fallback: tar + scp
132+
echo " [*] rsync not found — using tar+scp (slower)..."
133+
TARBALL="/tmp/nwe-deploy-$(date +%s).tar.gz"
134+
tar czf "$TARBALL" -C "$(dirname "$PROJECT_ROOT")" \
135+
--exclude='.git' --exclude='out' --exclude='target' \
136+
--exclude='node_modules' --exclude='*.jar' \
137+
"$(basename "$PROJECT_ROOT")"
138+
$SCP_CMD "$TARBALL" "$REMOTE:/tmp/"
139+
$SSH_CMD "$REMOTE" "tar xzf /tmp/$(basename $TARBALL) -C $(dirname $REMOTE_PATH) && rm -f /tmp/$(basename $TARBALL)"
140+
rm -f "$TARBALL"
141+
fi
142+
143+
echo " [✓] Codebase transferred"
144+
echo ""
145+
146+
# ── 4. Transfer JARs (separate — large files) ────────────────────────────────
147+
echo "[4/6] Transferring JAR dependencies..."
148+
149+
$SSH_CMD "$REMOTE" "mkdir -p $REMOTE_PATH/jars/mysql $REMOTE_PATH/jars/djl"
150+
151+
# MySQL connector
152+
MYSQL_JAR=$(find "$PROJECT_ROOT/jars/mysql" -name "mysql-connector-j*.jar" -type f 2>/dev/null | head -1)
153+
if [ -n "$MYSQL_JAR" ]; then
154+
$SCP_CMD "$MYSQL_JAR" "$REMOTE:$REMOTE_PATH/jars/mysql/"
155+
echo " [✓] MySQL connector: $(basename "$MYSQL_JAR")"
156+
fi
157+
158+
# Lanterna
159+
LANTERNA_JAR="$PROJECT_ROOT/jars/lanterna-3.1.5.jar"
160+
if [ -f "$LANTERNA_JAR" ]; then
161+
$SCP_CMD "$LANTERNA_JAR" "$REMOTE:$REMOTE_PATH/jars/"
162+
echo " [✓] Lanterna"
163+
fi
164+
165+
# DJL jars (skip native — too large, download on remote)
166+
find "$PROJECT_ROOT/jars/djl" -name "*.jar" ! -name "*native*" -type f 2>/dev/null | while read -r JAR; do
167+
$SCP_CMD "$JAR" "$REMOTE:$REMOTE_PATH/jars/djl/" 2>/dev/null
168+
done
169+
echo " [✓] DJL JARs"
170+
echo ""
171+
172+
# ── 5. Transfer Credentials ──────────────────────────────────────────────────
173+
echo "[5/6] Configuring remote credentials..."
174+
175+
if [ -f "$PROJECT_ROOT/.nwe-credentials" ]; then
176+
$SCP_CMD "$PROJECT_ROOT/.nwe-credentials" "$REMOTE:$REMOTE_PATH/.nwe-credentials"
177+
$SSH_CMD "$REMOTE" "chmod 600 $REMOTE_PATH/.nwe-credentials"
178+
echo " [✓] .nwe-credentials copied (mode 600)"
179+
else
180+
echo " [!] No local .nwe-credentials — remote will prompt during post-clone"
181+
fi
182+
echo ""
183+
184+
# ── 6. Run Post-Clone on Remote ──────────────────────────────────────────────
185+
echo "[6/6] Running post-clone setup on remote..."
186+
echo " (Java 21, MySQL, Tomcat, UFW, databases, deploy, start)"
187+
echo ""
188+
189+
$SSH_CMD -t "$REMOTE" bash -s "$REMOTE_PATH" <<'REMOTE_INSTALL'
190+
set -e
191+
REMOTE_PATH="$1"
192+
cd "$REMOTE_PATH"
193+
194+
# Make scripts executable
195+
find . -name "*.sh" -exec chmod +x {} \;
196+
197+
# Run post-clone (handles everything)
198+
bash scripts/web/post-clone.sh
199+
200+
# Compile
201+
bash scripts/compile-all-modules.sh
202+
203+
# Start everything
204+
bash scripts/start-all.sh
205+
REMOTE_INSTALL
206+
207+
echo ""
208+
echo "╔═══════════════════════════════════════════════════════════════════════════╗"
209+
echo "║ Remote Deploy Complete ║"
210+
echo "║ ║"
211+
echo "║ Server: $REMOTE_HOST"
212+
echo "║ Path: $REMOTE_PATH"
213+
echo "║ Tomcat: http://$REMOTE_HOST:8080 ║"
214+
echo "║ ║"
215+
echo "║ Verify: ║"
216+
echo "║ ssh $REMOTE 'bash $REMOTE_PATH/scripts/status.sh' ║"
217+
echo "║ curl http://$REMOTE_HOST:8080/ae6e66/ ║"
218+
echo "║ ║"
219+
echo "║ SSH: ssh $REMOTE"
220+
echo "║ Logs: ssh $REMOTE 'tail -f $REMOTE_PATH/logging/nwe-main.log' ║"
221+
echo "╚═══════════════════════════════════════════════════════════════════════════╝"
222+
echo ""

scripts/web/post-clone.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ DEPLOY_SCRIPTS=(
164164
"modules/black/presidential/Brarner.M.Alete/install/deploy-local.sh"
165165
)
166166

167+
set +e # Disable exit-on-error for deploy loop (individual failures are handled)
167168
for DS in "${DEPLOY_SCRIPTS[@]}"; do
168169
FULL="$PROJECT_ROOT/$DS"
169170
MODULE_NAME=$(echo "$DS" | sed 's|modules/||;s|/servlets.*||;s|/install.*||;s|source/||')
@@ -185,6 +186,7 @@ for DS in "${DEPLOY_SCRIPTS[@]}"; do
185186
DEPLOY_FAIL=$((DEPLOY_FAIL + 1))
186187
fi
187188
done
189+
set -e # Re-enable exit-on-error
188190

189191
echo ""
190192
echo "[OK] Deployed: $DEPLOY_PASS | Failed: $DEPLOY_FAIL"

0 commit comments

Comments
 (0)