Fix permissions script to chown entire project directory and use chmod -R

This commit is contained in:
root
2026-06-10 12:15:06 +02:00
parent 5288dbd917
commit 3b3551d48c
16 changed files with 214 additions and 213 deletions
+22 -22
View File
@@ -3,7 +3,7 @@
# Strict mode: exit on any error, undefined var, or pipe failure
set -euo pipefail
# Laad .env bestand uit dezelfde directory als dit script
# Load .env from the same directory as this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -f "$SCRIPT_DIR/.env" ]; then
set -a
@@ -19,9 +19,9 @@ fi
exec 2>&1
# Trap for clean error messages
trap 'echo "=== ❌ FOUT: Update mislukt op regel $LINENO (commando: $BASH_COMMAND) ===" >&2; exit 1' ERR
trap 'echo "=== ❌ ERROR: Update failed at line $LINENO (command: $BASH_COMMAND) ===" >&2; exit 1' ERR
# --- CONFIGURATION (uit env vars, met defaults) ---
# --- CONFIGURATION (from env vars, with defaults) ---
DB_NAME="${NITRO_DB_NAME:-habbo}"
DB_HOST="${NITRO_DB_HOST:-127.0.0.1}"
DB_PORT="${NITRO_DB_PORT:-3306}"
@@ -36,7 +36,7 @@ BACKUP_DIR="${NITRO_BACKUP_DIR:-$EMULATOR_DIR/Database Updates/backups}"
NITRO_CLIENT="${NITRO_CLIENT_SRC:-/var/www/Nitro-V3}"
NITRO_RENDERER="${NITRO_RENDERER_SRC:-/var/www/Nitro_Render_V3}"
# Kritieke URLs voor catalog icons (uit env, met huidige server defaults)
# Critical URLs for catalog icons (from env, with current server defaults)
NITRO_IMAGE_LIBRARY_URL="${NITRO_IMAGE_LIBRARY_URL:-https://epicnabbo.nl/gamedata/c_images/}"
NITRO_HOF_FURNITURE_URL="${NITRO_HOF_FURNITURE_URL:-https://epicnabbo.nl/gamedata/icons}"
NITRO_API_URL="${NITRO_API_URL:-https://ws.epicnabbo.nl}"
@@ -53,7 +53,7 @@ if [ -n "$DB_PASS" ]; then
fi
# ---------------------
# Helper: verwijder node_modules geforceerd (met sudo fallback) en herstel directory-eigenaar
# Helper: forcefully remove node_modules (with sudo fallback) and restore directory owner
clean_node_modules() {
rm -rf node_modules 2>/dev/null || sudo rm -rf node_modules 2>/dev/null || true
if [ "$(stat -c '%U' .)" != "$(whoami)" ] && command -v sudo &> /dev/null; then
@@ -73,14 +73,14 @@ git stash --include-untracked || true && git pull
# --- Automatic Safe Database Backup ---
echo "--> Creating automatic database backup before update..."
mkdir -p "$BACKUP_DIR"
mariadb-dump $MYSQL_CRED --force --skip-lock-tables "$DB_NAME" > "$BACKUP_DIR/backup_$(date +%Y%m%d_%H%M%S).sql" || echo "--> Backup heeft ontbrekende tabellen (niet kritisch) — update gaat verder"
mariadb-dump $MYSQL_CRED --force --skip-lock-tables "$DB_NAME" > "$BACKUP_DIR/backup_$(date +%Y%m%d_%H%M%S).sql" || echo "--> Backup has missing tables (not critical) — update continues"
# --- Automatic SQL Import (exclusief backup dir) ---
echo "--> Checking for new SQL files..."
if [ -d "$SQL_DIR" ]; then
find "$SQL_DIR" -name "*.sql" -mmin -10 -not -path "$BACKUP_DIR/*" -print0 2>/dev/null | 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 "--> Fout bij importeren $(basename "$sql_file"), naar volgende..."
mariadb $MYSQL_CRED --force "$DB_NAME" < "$sql_file" || echo "--> Error importing $(basename "$sql_file"), moving to next..."
done
else
echo "--> SQL directory not found, skipping SQL import."
@@ -94,7 +94,7 @@ JAR_PATTERN="target/Habbo-*-jar-with-dependencies.jar"
JAR_FILE=$(basename "$(ls -t $JAR_PATTERN 2>/dev/null | head -n 1)")
if [ -z "$JAR_FILE" ]; then
echo "=== ❌ Geen jar-bestand gevonden met pattern: $JAR_PATTERN ==="
echo "=== ❌ No jar file found with pattern: $JAR_PATTERN ==="
exit 1
fi
@@ -152,15 +152,15 @@ fi
# ----------------------------------------
# 4. Sync Configs & UITexts (.example logica)
# 4. Sync Configs & UITexts (.example logic)
# ----------------------------------------
echo "--> Synchronizing configurations..."
mkdir -p "$GAMEDATA_CONF_DIR"
MERGE_SCRIPT="$(dirname "$0")/scripts/merge-config.cjs"
# Fase 1: Merge .example met live configs in dezelfde public directory
# zodat de Nitro client zelf altijd 100% complete configs heeft
# Phase 1: Merge .example with live configs in the same public directory
# so the Nitro client always has 100% complete configs
echo "--> Merging .example files with live configs in $NITRO_SRC_DIR..."
for example_file in "$NITRO_SRC_DIR"/*.example; do
[ -f "$example_file" ] || continue
@@ -175,7 +175,7 @@ for example_file in "$NITRO_SRC_DIR"/*.example; do
node "$MERGE_SCRIPT" "$example_file" "$live_path"
done
# Fase 2: Daarna dezelfde merge naar Gamedata/config voor de website
# Phase 2: Then merge the same to Gamedata/config for the website
echo "--> Merging Nitro config examples into Gamedata/config..."
for example_file in "$NITRO_SRC_DIR"/*.example; do
[ -f "$example_file" ] || continue
@@ -190,7 +190,7 @@ for example_file in "$NITRO_SRC_DIR"/*.example; do
node "$MERGE_SCRIPT" "$example_file" "$target_path"
done
# Fase 3: Sync de gemergde configs naar dist/configuration voor de live client
# Phase 3: Sync merged configs to dist/configuration for the live client
NITRO_DIST_CONFIG_DIR="$NITRO_CLIENT/dist/configuration"
if [ -d "$NITRO_DIST_CONFIG_DIR" ]; then
echo "--> Syncing merged configs to dist/configuration/..."
@@ -209,8 +209,8 @@ if [ -d "$NITRO_DIST_CONFIG_DIR" ]; then
done
fi
# Fase 4: Herstel kritieke icon URLs in renderer-config en ui-config
# (voorkomt dat git pull de URLs overschrijft met voorbeeldwaarden)
# Phase 4: Restore critical icon URLs in renderer-config and ui-config
# (prevents git pull from overwriting URLs with example values)
echo "--> Ensuring critical catalog icon URLs are correct..."
FORCE_CONFIG_SCRIPT=$(cat << 'PYEOF'
import json, sys, os
@@ -236,18 +236,18 @@ for path in paths:
env_val = os.environ.get(f'NITRO_{key.upper().replace(".", "_")}')
if env_val:
data[key] = env_val
# Forceer /config/ pad voor radio en soundboard
# Force /config/ path for radio and soundboard
if 'gamedata.url' in data:
data['radio.url'] = data['gamedata.url'] + '/config/radio-stations.json5?t=%timestamp%'
data['soundboard.url'] = data['gamedata.url'] + '/config/soundboard-sounds.json5?t=%timestamp%'
# Zet Google Ads uit
# Disable Google Ads
if 'show.google.ads' in data:
data['show.google.ads'] = False
with open(path, 'w') as f:
json.dump(data, f, indent=(4 if 'dist' not in path else None), separators=(',', ':') if 'dist' in path else (',', ': '))
print(f'--> [OK] Hersteld: {os.path.basename(path)}')
print(f'--> [OK] Fixed: {os.path.basename(path)}')
print('--> [OK] Catalog icon URLs zijn correct ingesteld')
print('--> [OK] Catalog icon URLs are set correctly')
PYEOF
)
cd "$NITRO_CLIENT" && NITRO_SRC_DIR="$NITRO_SRC_DIR" NITRO_DIST_CONFIG_DIR="$NITRO_DIST_CONFIG_DIR" \
@@ -337,9 +337,9 @@ 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
echo "--> [WARN] $dir heeft eigenaar $OWNER ipv www-data:www-data"
echo "--> [WARN] $dir has owner $OWNER instead of www-data:www-data"
sudo chown -R www-data:www-data "$dir" 2>/dev/null || true
echo " Hersteld naar www-data:www-data"
echo " Restored to www-data:www-data"
fi
fi
done
@@ -358,5 +358,5 @@ fi
if [ "$ERRORS" -eq 0 ]; then
echo "=== ✅ Update 100% successfully completed! ==="
else
echo "=== ⚠️ Update completed with $ERRORS warning(s) — check bovenstaande output ==="
echo "=== ⚠️ Update completed with $ERRORS warning(s) — check output above ==="
fi