You've already forked Atomcms-edit
refactor: improvements to update script
This commit is contained in:
+70
-67
@@ -18,6 +18,11 @@ if [ -z "${_UNBUFFERED:-}" ] && command -v unbuffer &> /dev/null; then
|
|||||||
fi
|
fi
|
||||||
exec 2>&1
|
exec 2>&1
|
||||||
|
|
||||||
|
# Single-instance lock via flock
|
||||||
|
LOCKFILE="/tmp/$(basename "$0").lock"
|
||||||
|
exec 200>"$LOCKFILE"
|
||||||
|
flock -n 200 || { echo "=== ❌ Another instance already running, exiting ==="; exit 1; }
|
||||||
|
|
||||||
# Trap for clean error messages
|
# Trap for clean error messages
|
||||||
trap 'echo "=== ❌ ERROR: Update failed at line $LINENO (command: $BASH_COMMAND) ===" >&2; exit 1' ERR
|
trap 'echo "=== ❌ ERROR: Update failed at line $LINENO (command: $BASH_COMMAND) ===" >&2; exit 1' ERR
|
||||||
|
|
||||||
@@ -46,10 +51,10 @@ NITRO_GAMEDATA_URL="${NITRO_GAMEDATA_URL:-https://epicnabbo.nl/gamedata}"
|
|||||||
NITRO_ASSET_URL="${NITRO_ASSET_URL:-https://epicnabbo.nl/gamedata/bundled}"
|
NITRO_ASSET_URL="${NITRO_ASSET_URL:-https://epicnabbo.nl/gamedata/bundled}"
|
||||||
NITRO_FURNI_ASSET_ICON_URL="${NITRO_FURNI_ASSET_ICON_URL:-https://epicnabbo.nl/gamedata/icons/%libname%%param%_icon.png}"
|
NITRO_FURNI_ASSET_ICON_URL="${NITRO_FURNI_ASSET_ICON_URL:-https://epicnabbo.nl/gamedata/icons/%libname%%param%_icon.png}"
|
||||||
|
|
||||||
# Build MySQL/MariaDB credentials argument
|
# Build MySQL/MariaDB credentials argument (password via MYSQL_PWD — not visible in ps)
|
||||||
MYSQL_CRED="-h $DB_HOST -P $DB_PORT -u $DB_USER"
|
MYSQL_CRED="-h $DB_HOST -P $DB_PORT -u $DB_USER"
|
||||||
if [ -n "$DB_PASS" ]; then
|
if [ -n "$DB_PASS" ]; then
|
||||||
MYSQL_CRED="$MYSQL_CRED -p$DB_PASS"
|
export MYSQL_PWD="$DB_PASS"
|
||||||
fi
|
fi
|
||||||
# ---------------------
|
# ---------------------
|
||||||
|
|
||||||
@@ -68,7 +73,10 @@ echo "=== Starting EPIC WEB CONTROL Update ==="
|
|||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
echo "--> Updating Emulator..."
|
echo "--> Updating Emulator..."
|
||||||
cd "$EMULATOR_DIR/Emulator/"
|
cd "$EMULATOR_DIR/Emulator/"
|
||||||
git stash --include-untracked || true && git checkout main && git pull
|
git stash --include-untracked || true
|
||||||
|
OLD_HEAD=$(git rev-parse HEAD)
|
||||||
|
git checkout main
|
||||||
|
git pull
|
||||||
|
|
||||||
# --- Automatic Safe Database Backup ---
|
# --- Automatic Safe Database Backup ---
|
||||||
echo "--> Creating automatic database backup before update..."
|
echo "--> Creating automatic database backup before update..."
|
||||||
@@ -86,23 +94,22 @@ else
|
|||||||
echo "--> SQL directory not found, skipping SQL import."
|
echo "--> SQL directory not found, skipping SQL import."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "--> Building Emulator with Maven..."
|
if [ "$(git rev-parse HEAD)" != "$OLD_HEAD" ]; then
|
||||||
mvn package
|
echo "--> New commits detected, building emulator..."
|
||||||
|
mvn package
|
||||||
|
|
||||||
# Automatically detect the newly built .jar file
|
JAR_FILE=$(find target -maxdepth 1 -name 'Habbo-*-jar-with-dependencies.jar' -printf '%T@ %p\n' 2>/dev/null | sort -rn | sed -n '1s/^[0-9.]* //p' | xargs basename)
|
||||||
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
|
if [ -z "$JAR_FILE" ]; then
|
||||||
echo "=== ❌ No jar file found with pattern: $JAR_PATTERN ==="
|
echo "=== ❌ No jar file found with pattern: target/Habbo-*-jar-with-dependencies.jar ==="
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "--> Found jar file: $JAR_FILE"
|
echo "--> Found jar file: $JAR_FILE"
|
||||||
echo "--> Updating emulator launch file..."
|
echo "--> Updating emulator launch file..."
|
||||||
cd target/
|
cd target/
|
||||||
|
|
||||||
cat << EOF > emulator
|
cat << EOF > emulator
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
file_name_emulator=emulator.log
|
file_name_emulator=emulator.log
|
||||||
current_time=\$(date "+%H%M_%d-%m-%Y")
|
current_time=\$(date "+%H%M_%d-%m-%Y")
|
||||||
@@ -110,7 +117,10 @@ file_name=\$file_name_emulator.\$current_time
|
|||||||
mv /var/log/emu/emulator.log /var/log/emu/\$file_name
|
mv /var/log/emu/emulator.log /var/log/emu/\$file_name
|
||||||
java -Dfile.encoding=UTF8 -Xmx2G -jar $JAR_FILE
|
java -Dfile.encoding=UTF8 -Xmx2G -jar $JAR_FILE
|
||||||
EOF
|
EOF
|
||||||
chmod +x emulator
|
chmod +x emulator
|
||||||
|
else
|
||||||
|
echo "--> Emulator already up to date, skipping build."
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
@@ -119,11 +129,17 @@ chmod +x emulator
|
|||||||
echo "--> Updating Nitro_Render_V3..."
|
echo "--> Updating Nitro_Render_V3..."
|
||||||
cd "$NITRO_RENDERER/"
|
cd "$NITRO_RENDERER/"
|
||||||
|
|
||||||
git stash --include-untracked || true && git checkout main && git pull
|
git stash --include-untracked || true
|
||||||
|
OLD_HEAD=$(git rev-parse HEAD)
|
||||||
|
git checkout main
|
||||||
|
git pull
|
||||||
|
|
||||||
echo "--> Running yarn install for Nitro_Render_V3..."
|
if [ "$(git rev-parse HEAD)" != "$OLD_HEAD" ]; then
|
||||||
clean_node_modules
|
echo "--> New commits detected, running yarn install for Nitro_Render_V3..."
|
||||||
yarn install
|
yarn install --frozen-lockfile || { echo "--> Retrying with clean node_modules..."; clean_node_modules && yarn install; }
|
||||||
|
else
|
||||||
|
echo "--> Nitro_Render_V3 already up to date, skipping."
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
@@ -132,14 +148,18 @@ yarn install
|
|||||||
echo "--> Updating Nitro-V3..."
|
echo "--> Updating Nitro-V3..."
|
||||||
cd "$NITRO_CLIENT"
|
cd "$NITRO_CLIENT"
|
||||||
|
|
||||||
git stash --include-untracked || true && git checkout main && git pull
|
git stash --include-untracked || true
|
||||||
|
OLD_HEAD=$(git rev-parse HEAD)
|
||||||
|
git checkout main
|
||||||
|
git pull
|
||||||
|
|
||||||
echo "--> Running yarn install for Nitro-V3..."
|
if [ "$(git rev-parse HEAD)" != "$OLD_HEAD" ]; then
|
||||||
clean_node_modules
|
echo "--> New commits detected, building Nitro-V3..."
|
||||||
yarn install
|
yarn install --frozen-lockfile || { echo "--> Retrying with clean node_modules..."; clean_node_modules && yarn install; }
|
||||||
|
yarn build
|
||||||
echo "--> Building Nitro-V3 with Vite 8 / Yarn..."
|
else
|
||||||
yarn build
|
echo "--> Nitro-V3 already up to date, skipping build."
|
||||||
|
fi
|
||||||
|
|
||||||
echo "--> Ensuring custom-themes/index.json exists..."
|
echo "--> Ensuring custom-themes/index.json exists..."
|
||||||
mkdir -p "$NITRO_CLIENT/dist/custom-themes"
|
mkdir -p "$NITRO_CLIENT/dist/custom-themes"
|
||||||
@@ -158,43 +178,17 @@ echo "--> Synchronizing configurations..."
|
|||||||
mkdir -p "$GAMEDATA_CONF_DIR"
|
mkdir -p "$GAMEDATA_CONF_DIR"
|
||||||
|
|
||||||
MERGE_SCRIPT="$(dirname "$0")/scripts/merge-config.cjs"
|
MERGE_SCRIPT="$(dirname "$0")/scripts/merge-config.cjs"
|
||||||
|
|
||||||
# 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
|
|
||||||
base=$(basename "$example_file")
|
|
||||||
target_name="${base%.example}"
|
|
||||||
case "$target_name" in
|
|
||||||
*.*) ;; # already has extension (e.g., .json, .json5)
|
|
||||||
*) target_name="$target_name.json" ;; # no extension -> add .json
|
|
||||||
esac
|
|
||||||
live_path="$NITRO_SRC_DIR/$target_name"
|
|
||||||
echo "--> Processing $base -> $target_name (live)..."
|
|
||||||
node "$MERGE_SCRIPT" "$example_file" "$live_path"
|
|
||||||
done
|
|
||||||
|
|
||||||
# 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
|
|
||||||
base=$(basename "$example_file")
|
|
||||||
target_name="${base%.example}"
|
|
||||||
case "$target_name" in
|
|
||||||
*.*) ;;
|
|
||||||
*) target_name="$target_name.json" ;;
|
|
||||||
esac
|
|
||||||
target_path="$GAMEDATA_CONF_DIR/$target_name"
|
|
||||||
echo "--> Processing $base -> $target_name..."
|
|
||||||
node "$MERGE_SCRIPT" "$example_file" "$target_path"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Phase 3: Sync merged configs to dist/configuration for the live client
|
|
||||||
NITRO_DIST_CONFIG_DIR="$NITRO_CLIENT/dist/configuration"
|
NITRO_DIST_CONFIG_DIR="$NITRO_CLIENT/dist/configuration"
|
||||||
if [ -d "$NITRO_DIST_CONFIG_DIR" ]; then
|
|
||||||
echo "--> Syncing merged configs to dist/configuration/..."
|
# Temporarily make config dirs writable if owned by www-data (restored in section 6)
|
||||||
for example_file in "$NITRO_SRC_DIR"/*.example; do
|
for dir in "$NITRO_SRC_DIR" "$GAMEDATA_CONF_DIR"; do
|
||||||
|
if [ -d "$dir" ] && [ ! -w "$dir" ] && command -v sudo &> /dev/null; then
|
||||||
|
sudo chown -R "$(whoami)":"$(whoami)" "$dir"
|
||||||
|
echo "--> [OK] Made $dir writable (will restore to www-data later)"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for example_file in "$NITRO_SRC_DIR"/*.example; do
|
||||||
[ -f "$example_file" ] || continue
|
[ -f "$example_file" ] || continue
|
||||||
base=$(basename "$example_file")
|
base=$(basename "$example_file")
|
||||||
target_name="${base%.example}"
|
target_name="${base%.example}"
|
||||||
@@ -202,12 +196,21 @@ if [ -d "$NITRO_DIST_CONFIG_DIR" ]; then
|
|||||||
*.*) ;;
|
*.*) ;;
|
||||||
*) target_name="$target_name.json" ;;
|
*) target_name="$target_name.json" ;;
|
||||||
esac
|
esac
|
||||||
if [ -f "$NITRO_SRC_DIR/$target_name" ]; then
|
|
||||||
|
# Phase 1: Merge to live config in Nitro public dir
|
||||||
|
echo "--> Merging $base -> $target_name (live)..."
|
||||||
|
node "$MERGE_SCRIPT" "$example_file" "$NITRO_SRC_DIR/$target_name"
|
||||||
|
|
||||||
|
# Phase 2: Merge to Gamedata/config for website
|
||||||
|
echo "--> Merging $base -> $target_name (gamedata)..."
|
||||||
|
node "$MERGE_SCRIPT" "$example_file" "$GAMEDATA_CONF_DIR/$target_name"
|
||||||
|
|
||||||
|
# Phase 3: Copy merged config to dist/configuration for live client
|
||||||
|
if [ -d "$NITRO_DIST_CONFIG_DIR" ]; then
|
||||||
cp "$NITRO_SRC_DIR/$target_name" "$NITRO_DIST_CONFIG_DIR/$target_name"
|
cp "$NITRO_SRC_DIR/$target_name" "$NITRO_DIST_CONFIG_DIR/$target_name"
|
||||||
echo "--> [OK] Synced $target_name to dist/configuration/"
|
echo "--> [OK] Synced $target_name to dist/configuration/"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
|
||||||
|
|
||||||
# Phase 4: Restore critical icon URLs in renderer-config and ui-config
|
# Phase 4: Restore critical icon URLs in renderer-config and ui-config
|
||||||
# (prevents git pull from overwriting URLs with example values)
|
# (prevents git pull from overwriting URLs with example values)
|
||||||
@@ -265,7 +268,7 @@ 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 {} \; 2>/dev/null || true
|
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)..."
|
||||||
|
|||||||
Reference in New Issue
Block a user