You've already forked Atomcms-edit
Fix: unbuffer for realtime output, set -euo pipefail + trap for 0 errors guarantee
This commit is contained in:
+30
-31
@@ -1,15 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit immediately if a command exits with a non-zero status
|
||||
set -e
|
||||
# Strict mode: exit on any error, undefined var, or pipe failure
|
||||
set -euo pipefail
|
||||
|
||||
# Real-time output - disable buffering zodat je bij "run update" direct ziet wat er gebeurt
|
||||
if command -v stdbuf &> /dev/null && [ -z "$_UNBUFFERED" ]; then
|
||||
# Real-time output via pseudo-terminal (unbuffer from expect)
|
||||
# Dit forceert line-buffered output voor ALLE commands, ook in web interfaces
|
||||
if [ -z "$_UNBUFFERED" ] && command -v unbuffer &> /dev/null; then
|
||||
export _UNBUFFERED=1
|
||||
exec stdbuf -oL -eL bash "$0" "$@"
|
||||
exec unbuffer bash "$0" "$@"
|
||||
fi
|
||||
exec 2>&1
|
||||
|
||||
# Trap for clean error messages
|
||||
trap 'echo "=== ❌ FOUT: Update mislukt op regel $LINENO (commando: $BASH_COMMAND) ===" >&2; exit 1' ERR
|
||||
|
||||
# --- CONFIGURATION (overridable via environment variables) ---
|
||||
DB_NAME="${NITRO_DB_NAME:-habbo}"
|
||||
DB_HOST="${NITRO_DB_HOST:-127.0.0.1}"
|
||||
@@ -49,10 +53,10 @@ mariadb-dump $MYSQL_CRED "$DB_NAME" > "$BACKUP_DIR/backup_$(date +%Y%m%d_%H%M%S)
|
||||
# --- Automatic SQL Import ---
|
||||
echo "--> Checking for new SQL files..."
|
||||
if [ -d "$SQL_DIR" ]; then
|
||||
find "$SQL_DIR" -name "*.sql" -mmin -10 -print0 | while IFS= read -r -d '' sql_file; do
|
||||
while IFS= read -r -d '' sql_file; do
|
||||
echo "--> Importing new SQL file: $(basename "$sql_file")"
|
||||
mariadb $MYSQL_CRED --force "$DB_NAME" < "$sql_file" || echo "--> Note: Some SQL rules skipped (probably already exist)."
|
||||
done
|
||||
mariadb $MYSQL_CRED --force "$DB_NAME" < "$sql_file"
|
||||
done < <(find "$SQL_DIR" -name "*.sql" -mmin -10 -print0 2>/dev/null)
|
||||
else
|
||||
echo "--> SQL directory not found, skipping SQL import."
|
||||
fi
|
||||
@@ -61,7 +65,7 @@ echo "--> Building Emulator with Maven..."
|
||||
mvn package
|
||||
|
||||
# Automatically detect the newly built .jar file
|
||||
JAR_FILE=$(basename $(ls -t target/Habbo-*-jar-with-dependencies.jar | head -n 1))
|
||||
JAR_FILE=$(basename "$(ls -t target/Habbo-*-jar-with-dependencies.jar 2>/dev/null | head -n 1)")
|
||||
|
||||
echo "--> Found jar file: $JAR_FILE"
|
||||
echo "--> Updating emulator launch file..."
|
||||
@@ -110,7 +114,7 @@ echo "--> Synchronizing Gamedata configurations..."
|
||||
mkdir -p "$GAMEDATA_CONF_DIR"
|
||||
|
||||
# --- Renderer Config Sync ---
|
||||
if [ ! -f "$GAMEDATA_CONF_DIR/renderer-config.json" ] || [ "$NITRO_SRC_DIR/renderer-config.example" -nt "$GAMEDATA_CONF_DIR/renderer-config.json" ]; then
|
||||
if [ ! -f "$GAMEDATA_CONF_DIR/renderer-config.json" ] || [ "${NITRO_SRC_DIR}/renderer-config.example" -nt "$GAMEDATA_CONF_DIR/renderer-config.json" 2>/dev/null ]; then
|
||||
if [ -f "$NITRO_SRC_DIR/renderer-config.example" ]; then
|
||||
echo "--> Updating renderer-config.json from latest example..."
|
||||
cp "$NITRO_SRC_DIR/renderer-config.example" "$GAMEDATA_CONF_DIR/renderer-config.json"
|
||||
@@ -118,7 +122,7 @@ if [ ! -f "$GAMEDATA_CONF_DIR/renderer-config.json" ] || [ "$NITRO_SRC_DIR/rende
|
||||
fi
|
||||
|
||||
# --- UI Config Sync ---
|
||||
if [ ! -f "$GAMEDATA_CONF_DIR/ui-config.json" ] || [ "$NITRO_SRC_DIR/ui-config.json.example" -nt "$GAMEDATA_CONF_DIR/ui-config.json" ]; then
|
||||
if [ ! -f "$GAMEDATA_CONF_DIR/ui-config.json" ] || [ "${NITRO_SRC_DIR}/ui-config.json.example" -nt "$GAMEDATA_CONF_DIR/ui-config.json" 2>/dev/null ]; then
|
||||
if [ -f "$NITRO_SRC_DIR/ui-config.json.example" ]; then
|
||||
echo "--> Updating ui-config.json from latest example..."
|
||||
cp "$NITRO_SRC_DIR/ui-config.json.example" "$GAMEDATA_CONF_DIR/ui-config.json"
|
||||
@@ -126,7 +130,7 @@ if [ ! -f "$GAMEDATA_CONF_DIR/ui-config.json" ] || [ "$NITRO_SRC_DIR/ui-config.j
|
||||
fi
|
||||
|
||||
# --- UITexts Sync ---
|
||||
if [ ! -f "$GAMEDATA_CONF_DIR/UITexts.json5" ] || [ "$NITRO_SRC_DIR/UITexts.json5.example" -nt "$GAMEDATA_CONF_DIR/UITexts.json5" ]; then
|
||||
if [ ! -f "$GAMEDATA_CONF_DIR/UITexts.json5" ] || [ "${NITRO_SRC_DIR}/UITexts.json5.example" -nt "$GAMEDATA_CONF_DIR/UITexts.json5" 2>/dev/null ]; then
|
||||
if [ -f "$NITRO_SRC_DIR/UITexts.json5.example" ]; then
|
||||
echo "--> Updating UITexts.json5 from latest example..."
|
||||
cp "$NITRO_SRC_DIR/UITexts.json5.example" "$GAMEDATA_CONF_DIR/UITexts.json5"
|
||||
@@ -141,13 +145,11 @@ echo "--> Starting automated cleanup..."
|
||||
|
||||
# 1. Remove emulator logs older than 14 days
|
||||
echo "--> Removing emulator logs older than 14 days..."
|
||||
find "$EMULATOR_DIR/" -name "*.log" -mtime +14 -exec rm -f {} \;
|
||||
find "$EMULATOR_DIR/" -name "*.log" -mtime +14 -exec rm -f {} \; 2>/dev/null || true
|
||||
|
||||
# 2. Keep max 5 newest database backups, delete older ones
|
||||
echo "--> Managing update backups (keeping max 5)..."
|
||||
if [ -d "$BACKUP_DIR" ]; then
|
||||
# Find all .sql files in backup dir, sort by date (newest first),
|
||||
# skip the first 5 (tail -n +6) and delete the rest.
|
||||
ls -t "$BACKUP_DIR"/*.sql 2>/dev/null | tail -n +6 | xargs -r rm -f || true
|
||||
fi
|
||||
|
||||
@@ -157,15 +159,13 @@ yarn cache clean
|
||||
|
||||
|
||||
# ----------------------------------------
|
||||
# 6. Fix Permissions (www-data) — only if sudo is available
|
||||
# 6. Fix Permissions (www-data)
|
||||
# ----------------------------------------
|
||||
if command -v sudo &> /dev/null; then
|
||||
echo "--> Setting permissions to www-data:www-data..."
|
||||
for dir in "$NITRO_CLIENT" "$NITRO_RENDERER" "$EMULATOR_DIR" "$GAMEDATA_CONF_DIR"; do
|
||||
if [ -d "$dir" ]; then
|
||||
sudo chown -R www-data:www-data "$dir" || echo "--> chown voor $dir overgeslagen"
|
||||
else
|
||||
echo "--> Directory $dir bestaat niet, chown overgeslagen"
|
||||
sudo chown -R www-data:www-data "$dir"
|
||||
fi
|
||||
done
|
||||
echo "--> Permissions successfully set to www-data:www-data"
|
||||
@@ -175,13 +175,13 @@ fi
|
||||
|
||||
|
||||
# ----------------------------------------
|
||||
# 7. Restart the Service (Veilige Check)
|
||||
# 7. Restart the Service
|
||||
# ----------------------------------------
|
||||
if systemctl list-units --type=service --all | grep -q "$EMULATOR_SERVICE.service"; then
|
||||
if systemctl list-units --type=service --all 2>/dev/null | grep -q "$EMULATOR_SERVICE.service"; then
|
||||
echo "--> Restarting $EMULATOR_SERVICE service..."
|
||||
if command -v sudo &> /dev/null; then
|
||||
sudo systemctl restart $EMULATOR_SERVICE 2>/dev/null || echo "--> Service restart via sudo failed (possible insufficient sudo rights)"
|
||||
sudo systemctl status $EMULATOR_SERVICE --no-pager -n 5 2>/dev/null || true
|
||||
sudo systemctl restart "$EMULATOR_SERVICE"
|
||||
sudo systemctl status "$EMULATOR_SERVICE" --no-pager -n 5
|
||||
else
|
||||
echo "--> Sudo not available. Restart the service manually: sudo systemctl restart $EMULATOR_SERVICE"
|
||||
fi
|
||||
@@ -190,6 +190,7 @@ else
|
||||
echo "--> If you use PM2, restart your processes manually: pm2 restart all"
|
||||
fi
|
||||
|
||||
|
||||
# ----------------------------------------
|
||||
# 8. Extra Validation — 100% check
|
||||
# ----------------------------------------
|
||||
@@ -212,22 +213,20 @@ for dir in "$NITRO_CLIENT" "$NITRO_RENDERER" "$EMULATOR_DIR" "$GAMEDATA_CONF_DIR
|
||||
if [ "$OWNER" = "www-data:www-data" ] || [ "$(id -u)" -ne 0 ]; then
|
||||
echo "--> [OK] $dir ($OWNER)"
|
||||
else
|
||||
if command -v sudo &> /dev/null; then
|
||||
echo "--> [WARN] $dir heeft eigenaar $OWNER ipv www-data:www-data"
|
||||
sudo chown -R www-data:www-data "$dir" 2>/dev/null || true
|
||||
echo "--> Hersteld"
|
||||
fi
|
||||
echo "--> [WARN] $dir heeft eigenaar $OWNER ipv www-data:www-data"
|
||||
sudo chown -R www-data:www-data "$dir" 2>/dev/null || true
|
||||
echo " Hersteld naar www-data:www-data"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if emulator service is running
|
||||
if systemctl list-units --type=service --all | grep -q "$EMULATOR_SERVICE.service"; then
|
||||
if systemctl list-units --type=service --all 2>/dev/null | grep -q "$EMULATOR_SERVICE.service"; then
|
||||
SERVICE_STATUS=$(systemctl is-active "$EMULATOR_SERVICE" 2>/dev/null || echo "unknown")
|
||||
if [ "$SERVICE_STATUS" = "active" ]; then
|
||||
echo "--> [OK] $EMULATOR_SERVICE service is $SERVICE_STATUS"
|
||||
else
|
||||
echo "--> [WARN] $EMULATOR_SERVICE service is $SERVICE_STATUS"
|
||||
echo "--> [WARN] $EMULATOR_SERVICE service is $SERVICE_STATUS (not active, check logs)"
|
||||
ERRORS=$((ERRORS + 1))
|
||||
fi
|
||||
fi
|
||||
@@ -236,4 +235,4 @@ if [ "$ERRORS" -eq 0 ]; then
|
||||
echo "=== ✅ Update 100% successfully completed! ==="
|
||||
else
|
||||
echo "=== ⚠️ Update completed with $ERRORS warning(s) — check bovenstaande output ==="
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user