You've already forked Atomcms-edit
refactor: add update tracking, dir checks, and safer cleanup
This commit is contained in:
+28
-8
@@ -68,11 +68,16 @@ clean_node_modules() {
|
|||||||
|
|
||||||
echo "=== Starting EPIC WEB CONTROL Update ==="
|
echo "=== Starting EPIC WEB CONTROL Update ==="
|
||||||
|
|
||||||
|
HAD_UPDATES=false
|
||||||
|
NITRO_BUILT=false
|
||||||
|
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# 1. Update and Build Emulator
|
# 1. Update and Build Emulator
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
echo "--> Updating Emulator..."
|
echo "--> Updating Emulator..."
|
||||||
cd "$EMULATOR_DIR/Emulator/"
|
EMULATOR_REPO_DIR="$EMULATOR_DIR/Emulator"
|
||||||
|
[ -d "$EMULATOR_REPO_DIR" ] || { echo "=== ❌ Directory not found: $EMULATOR_REPO_DIR ==="; exit 1; }
|
||||||
|
cd "$EMULATOR_REPO_DIR"
|
||||||
git stash --include-untracked || true
|
git stash --include-untracked || true
|
||||||
OLD_HEAD=$(git rev-parse HEAD)
|
OLD_HEAD=$(git rev-parse HEAD)
|
||||||
git checkout main
|
git checkout main
|
||||||
@@ -96,6 +101,7 @@ fi
|
|||||||
|
|
||||||
if [ "$(git rev-parse HEAD)" != "$OLD_HEAD" ]; then
|
if [ "$(git rev-parse HEAD)" != "$OLD_HEAD" ]; then
|
||||||
echo "--> New commits detected, building emulator..."
|
echo "--> New commits detected, building emulator..."
|
||||||
|
HAD_UPDATES=true
|
||||||
mvn package
|
mvn package
|
||||||
|
|
||||||
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_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)
|
||||||
@@ -107,6 +113,7 @@ if [ "$(git rev-parse HEAD)" != "$OLD_HEAD" ]; then
|
|||||||
|
|
||||||
echo "--> Found jar file: $JAR_FILE"
|
echo "--> Found jar file: $JAR_FILE"
|
||||||
echo "--> Updating emulator launch file..."
|
echo "--> Updating emulator launch file..."
|
||||||
|
[ -d target ] || { echo "=== ❌ Build directory 'target' not found ==="; exit 1; }
|
||||||
cd target/
|
cd target/
|
||||||
|
|
||||||
cat << EOF > emulator
|
cat << EOF > emulator
|
||||||
@@ -127,7 +134,8 @@ fi
|
|||||||
# 2. Update Nitro_Render_V3
|
# 2. Update Nitro_Render_V3
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
echo "--> Updating Nitro_Render_V3..."
|
echo "--> Updating Nitro_Render_V3..."
|
||||||
cd "$NITRO_RENDERER/"
|
[ -d "$NITRO_RENDERER" ] || { echo "=== ❌ Directory not found: $NITRO_RENDERER ==="; exit 1; }
|
||||||
|
cd "$NITRO_RENDERER"
|
||||||
|
|
||||||
git stash --include-untracked || true
|
git stash --include-untracked || true
|
||||||
OLD_HEAD=$(git rev-parse HEAD)
|
OLD_HEAD=$(git rev-parse HEAD)
|
||||||
@@ -136,6 +144,7 @@ git pull
|
|||||||
|
|
||||||
if [ "$(git rev-parse HEAD)" != "$OLD_HEAD" ]; then
|
if [ "$(git rev-parse HEAD)" != "$OLD_HEAD" ]; then
|
||||||
echo "--> New commits detected, running yarn install for Nitro_Render_V3..."
|
echo "--> New commits detected, running yarn install for Nitro_Render_V3..."
|
||||||
|
HAD_UPDATES=true
|
||||||
yarn install --frozen-lockfile || { echo "--> Retrying with clean node_modules..."; clean_node_modules && yarn install; }
|
yarn install --frozen-lockfile || { echo "--> Retrying with clean node_modules..."; clean_node_modules && yarn install; }
|
||||||
else
|
else
|
||||||
echo "--> Nitro_Render_V3 already up to date, skipping."
|
echo "--> Nitro_Render_V3 already up to date, skipping."
|
||||||
@@ -146,6 +155,7 @@ fi
|
|||||||
# 3. Update and Build Nitro-V3
|
# 3. Update and Build Nitro-V3
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
echo "--> Updating Nitro-V3..."
|
echo "--> Updating Nitro-V3..."
|
||||||
|
[ -d "$NITRO_CLIENT" ] || { echo "=== ❌ Directory not found: $NITRO_CLIENT ==="; exit 1; }
|
||||||
cd "$NITRO_CLIENT"
|
cd "$NITRO_CLIENT"
|
||||||
|
|
||||||
git stash --include-untracked || true
|
git stash --include-untracked || true
|
||||||
@@ -155,6 +165,8 @@ git pull
|
|||||||
|
|
||||||
if [ "$(git rev-parse HEAD)" != "$OLD_HEAD" ]; then
|
if [ "$(git rev-parse HEAD)" != "$OLD_HEAD" ]; then
|
||||||
echo "--> New commits detected, building Nitro-V3..."
|
echo "--> New commits detected, building Nitro-V3..."
|
||||||
|
HAD_UPDATES=true
|
||||||
|
NITRO_BUILT=true
|
||||||
yarn install --frozen-lockfile || { echo "--> Retrying with clean node_modules..."; clean_node_modules && yarn install; }
|
yarn install --frozen-lockfile || { echo "--> Retrying with clean node_modules..."; clean_node_modules && yarn install; }
|
||||||
yarn build
|
yarn build
|
||||||
else
|
else
|
||||||
@@ -273,16 +285,20 @@ find "$EMULATOR_DIR" -name "*.log" -mtime +14 -exec rm -f {} \; 2>/dev/null || t
|
|||||||
# 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
|
||||||
ls -t "$BACKUP_DIR"/*.sql 2>/dev/null | tail -n +6 | xargs -r rm -f || true
|
find "$BACKUP_DIR" -maxdepth 1 -name '*.sql' -printf '%T@ %p\n' 2>/dev/null | sort -rn | tail -n +6 | sed 's/^[0-9.]* //' | xargs -r rm -f || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 3. Clean Yarn cache to save SSD space
|
# 3. Clean Yarn cache to save SSD space (only if yarn was used)
|
||||||
|
if [ "$HAD_UPDATES" = true ]; then
|
||||||
echo "--> Cleaning Yarn cache..."
|
echo "--> Cleaning Yarn cache..."
|
||||||
yarn cache clean 2>/dev/null || true
|
yarn cache clean 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
# 4. Remove old .jar files, keeping only the newest one
|
# 4. Remove old .jar files, keeping only the newest one (only if emulator was rebuilt)
|
||||||
|
if [ "$HAD_UPDATES" = true ]; then
|
||||||
echo "--> Cleaning up old emulator .jar files (keeping the latest)..."
|
echo "--> Cleaning up old emulator .jar files (keeping the latest)..."
|
||||||
ls -t "$EMULATOR_DIR/Emulator/target"/Habbo-*-jar-with-dependencies.jar 2>/dev/null | tail -n +2 | xargs -r rm -f || true
|
find "$EMULATOR_DIR/Emulator/target" -maxdepth 1 -name 'Habbo-*-jar-with-dependencies.jar' -printf '%T@ %p\n' 2>/dev/null | sort -rn | tail -n +2 | sed 's/^[0-9.]* //' | xargs -r rm -f || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
@@ -302,9 +318,9 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
# 7. Restart the Service
|
# 7. Restart the Service (only if updates were applied)
|
||||||
# ----------------------------------------
|
# ----------------------------------------
|
||||||
if systemctl cat "$EMULATOR_SERVICE" &>/dev/null; then
|
if [ "$HAD_UPDATES" = true ] && systemctl cat "$EMULATOR_SERVICE" &>/dev/null; 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"
|
sudo systemctl restart "$EMULATOR_SERVICE"
|
||||||
@@ -326,12 +342,16 @@ echo "--> Running extra validation..."
|
|||||||
ERRORS=0
|
ERRORS=0
|
||||||
|
|
||||||
# Check build output exists
|
# Check build output exists
|
||||||
|
if [ "$NITRO_BUILT" = true ]; then
|
||||||
if [ -d "$NITRO_CLIENT/dist/assets" ]; then
|
if [ -d "$NITRO_CLIENT/dist/assets" ]; then
|
||||||
echo "--> [OK] Nitro-V3 build assets found"
|
echo "--> [OK] Nitro-V3 build assets found"
|
||||||
else
|
else
|
||||||
echo "--> [FAIL] Nitro-V3 build assets missing!"
|
echo "--> [FAIL] Nitro-V3 build assets missing!"
|
||||||
ERRORS=$((ERRORS + 1))
|
ERRORS=$((ERRORS + 1))
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo "--> [SKIP] Nitro-V3 was not rebuilt (no new commits), skipping build check"
|
||||||
|
fi
|
||||||
|
|
||||||
# Check permissions on key files
|
# Check permissions on key files
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user