You've already forked Atomcms-edit
Fix: unbuffer for realtime output, set -euo pipefail + trap for 0 errors guarantee
This commit is contained in:
+29
-30
@@ -1,15 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Exit immediately if a command exits with a non-zero status
|
# Strict mode: exit on any error, undefined var, or pipe failure
|
||||||
set -e
|
set -euo pipefail
|
||||||
|
|
||||||
# Real-time output - disable buffering zodat je bij "run update" direct ziet wat er gebeurt
|
# Real-time output via pseudo-terminal (unbuffer from expect)
|
||||||
if command -v stdbuf &> /dev/null && [ -z "$_UNBUFFERED" ]; then
|
# Dit forceert line-buffered output voor ALLE commands, ook in web interfaces
|
||||||
|
if [ -z "$_UNBUFFERED" ] && command -v unbuffer &> /dev/null; then
|
||||||
export _UNBUFFERED=1
|
export _UNBUFFERED=1
|
||||||
exec stdbuf -oL -eL bash "$0" "$@"
|
exec unbuffer bash "$0" "$@"
|
||||||
fi
|
fi
|
||||||
exec 2>&1
|
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) ---
|
# --- CONFIGURATION (overridable via environment variables) ---
|
||||||
DB_NAME="${NITRO_DB_NAME:-habbo}"
|
DB_NAME="${NITRO_DB_NAME:-habbo}"
|
||||||
DB_HOST="${NITRO_DB_HOST:-127.0.0.1}"
|
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 ---
|
# --- Automatic SQL Import ---
|
||||||
echo "--> Checking for new SQL files..."
|
echo "--> Checking for new SQL files..."
|
||||||
if [ -d "$SQL_DIR" ]; then
|
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")"
|
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)."
|
mariadb $MYSQL_CRED --force "$DB_NAME" < "$sql_file"
|
||||||
done
|
done < <(find "$SQL_DIR" -name "*.sql" -mmin -10 -print0 2>/dev/null)
|
||||||
else
|
else
|
||||||
echo "--> SQL directory not found, skipping SQL import."
|
echo "--> SQL directory not found, skipping SQL import."
|
||||||
fi
|
fi
|
||||||
@@ -61,7 +65,7 @@ echo "--> Building Emulator with Maven..."
|
|||||||
mvn package
|
mvn package
|
||||||
|
|
||||||
# Automatically detect the newly built .jar file
|
# 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 "--> Found jar file: $JAR_FILE"
|
||||||
echo "--> Updating emulator launch file..."
|
echo "--> Updating emulator launch file..."
|
||||||
@@ -110,7 +114,7 @@ echo "--> Synchronizing Gamedata configurations..."
|
|||||||
mkdir -p "$GAMEDATA_CONF_DIR"
|
mkdir -p "$GAMEDATA_CONF_DIR"
|
||||||
|
|
||||||
# --- Renderer Config Sync ---
|
# --- 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
|
if [ -f "$NITRO_SRC_DIR/renderer-config.example" ]; then
|
||||||
echo "--> Updating renderer-config.json from latest example..."
|
echo "--> Updating renderer-config.json from latest example..."
|
||||||
cp "$NITRO_SRC_DIR/renderer-config.example" "$GAMEDATA_CONF_DIR/renderer-config.json"
|
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
|
fi
|
||||||
|
|
||||||
# --- UI Config Sync ---
|
# --- 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
|
if [ -f "$NITRO_SRC_DIR/ui-config.json.example" ]; then
|
||||||
echo "--> Updating ui-config.json from latest example..."
|
echo "--> Updating ui-config.json from latest example..."
|
||||||
cp "$NITRO_SRC_DIR/ui-config.json.example" "$GAMEDATA_CONF_DIR/ui-config.json"
|
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
|
fi
|
||||||
|
|
||||||
# --- UITexts Sync ---
|
# --- 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
|
if [ -f "$NITRO_SRC_DIR/UITexts.json5.example" ]; then
|
||||||
echo "--> Updating UITexts.json5 from latest example..."
|
echo "--> Updating UITexts.json5 from latest example..."
|
||||||
cp "$NITRO_SRC_DIR/UITexts.json5.example" "$GAMEDATA_CONF_DIR/UITexts.json5"
|
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
|
# 1. Remove emulator logs older than 14 days
|
||||||
echo "--> Removing 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
|
# 2. Keep max 5 newest database backups, delete older ones
|
||||||
echo "--> Managing update backups (keeping max 5)..."
|
echo "--> Managing update backups (keeping max 5)..."
|
||||||
if [ -d "$BACKUP_DIR" ]; then
|
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
|
ls -t "$BACKUP_DIR"/*.sql 2>/dev/null | tail -n +6 | xargs -r rm -f || true
|
||||||
fi
|
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
|
if command -v sudo &> /dev/null; then
|
||||||
echo "--> Setting permissions to www-data:www-data..."
|
echo "--> Setting permissions to www-data:www-data..."
|
||||||
for dir in "$NITRO_CLIENT" "$NITRO_RENDERER" "$EMULATOR_DIR" "$GAMEDATA_CONF_DIR"; do
|
for dir in "$NITRO_CLIENT" "$NITRO_RENDERER" "$EMULATOR_DIR" "$GAMEDATA_CONF_DIR"; do
|
||||||
if [ -d "$dir" ]; then
|
if [ -d "$dir" ]; then
|
||||||
sudo chown -R www-data:www-data "$dir" || echo "--> chown voor $dir overgeslagen"
|
sudo chown -R www-data:www-data "$dir"
|
||||||
else
|
|
||||||
echo "--> Directory $dir bestaat niet, chown overgeslagen"
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "--> Permissions successfully set to www-data:www-data"
|
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..."
|
echo "--> Restarting $EMULATOR_SERVICE service..."
|
||||||
if command -v sudo &> /dev/null; then
|
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 restart "$EMULATOR_SERVICE"
|
||||||
sudo systemctl status $EMULATOR_SERVICE --no-pager -n 5 2>/dev/null || true
|
sudo systemctl status "$EMULATOR_SERVICE" --no-pager -n 5
|
||||||
else
|
else
|
||||||
echo "--> Sudo not available. Restart the service manually: sudo systemctl restart $EMULATOR_SERVICE"
|
echo "--> Sudo not available. Restart the service manually: sudo systemctl restart $EMULATOR_SERVICE"
|
||||||
fi
|
fi
|
||||||
@@ -190,6 +190,7 @@ else
|
|||||||
echo "--> If you use PM2, restart your processes manually: pm2 restart all"
|
echo "--> If you use PM2, restart your processes manually: pm2 restart all"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# 8. Extra Validation — 100% check
|
# 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
|
if [ "$OWNER" = "www-data:www-data" ] || [ "$(id -u)" -ne 0 ]; then
|
||||||
echo "--> [OK] $dir ($OWNER)"
|
echo "--> [OK] $dir ($OWNER)"
|
||||||
else
|
else
|
||||||
if command -v sudo &> /dev/null; then
|
echo "--> [WARN] $dir heeft eigenaar $OWNER ipv www-data:www-data"
|
||||||
echo "--> [WARN] $dir heeft eigenaar $OWNER ipv www-data:www-data"
|
sudo chown -R www-data:www-data "$dir" 2>/dev/null || true
|
||||||
sudo chown -R www-data:www-data "$dir" 2>/dev/null || true
|
echo " Hersteld naar www-data:www-data"
|
||||||
echo "--> Hersteld"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check if emulator service is running
|
# 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")
|
SERVICE_STATUS=$(systemctl is-active "$EMULATOR_SERVICE" 2>/dev/null || echo "unknown")
|
||||||
if [ "$SERVICE_STATUS" = "active" ]; then
|
if [ "$SERVICE_STATUS" = "active" ]; then
|
||||||
echo "--> [OK] $EMULATOR_SERVICE service is $SERVICE_STATUS"
|
echo "--> [OK] $EMULATOR_SERVICE service is $SERVICE_STATUS"
|
||||||
else
|
else
|
||||||
echo "--> [WARN] $EMULATOR_SERVICE service is $SERVICE_STATUS"
|
echo "--> [WARN] $EMULATOR_SERVICE service is $SERVICE_STATUS (not active, check logs)"
|
||||||
ERRORS=$((ERRORS + 1))
|
ERRORS=$((ERRORS + 1))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user