77 lines
2.1 KiB
Bash
Executable File
77 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Hytale Server Update Script
|
|
# Runs the updater, extracts new files, and restarts the server
|
|
#
|
|
|
|
set -e
|
|
|
|
HYTALE_DIR="/opt/hytale"
|
|
LOG_FILE="/var/log/hytale-update.log"
|
|
|
|
log() {
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
cd "$HYTALE_DIR"
|
|
|
|
log "Starting update check..."
|
|
|
|
# Run the updater to check for and download updates
|
|
# The updater downloads files like "2026.01.17-abcdef.zip"
|
|
DOWNLOADER_OUTPUT=$(./hytale-downloader-linux-amd64 2>&1 | tee -a "$LOG_FILE")
|
|
|
|
# Check if the downloader itself needs an update
|
|
if echo "$DOWNLOADER_OUTPUT" | grep -q "A new version of hytale-downloader is available"; then
|
|
log "Downloading new version of hytale-downloader..."
|
|
curl -sL -o hytale-downloader.zip "https://downloader.hytale.com/hytale-downloader.zip"
|
|
unzip -o hytale-downloader.zip -d "$HYTALE_DIR"
|
|
chmod +x "$HYTALE_DIR/hytale-downloader-linux-amd64"
|
|
rm -f hytale-downloader.zip
|
|
log "Downloader updated successfully."
|
|
fi
|
|
|
|
# Find the newest zip file (pattern: YYYY.MM.DD-*.zip)
|
|
NEWEST_ZIP=$(ls -t [0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]-*.zip 2>/dev/null | head -n1)
|
|
|
|
if [ -z "$NEWEST_ZIP" ]; then
|
|
log "No update zip found. Nothing to do."
|
|
exit 0
|
|
fi
|
|
|
|
# Check if this update was already applied
|
|
APPLIED_MARKER=".applied_updates"
|
|
if grep -Fxq "$NEWEST_ZIP" "$APPLIED_MARKER" 2>/dev/null; then
|
|
log "Update $NEWEST_ZIP was already applied. Skipping."
|
|
exit 0
|
|
fi
|
|
|
|
log "New update found: $NEWEST_ZIP"
|
|
|
|
# Stop the server
|
|
log "Stopping Hytale server..."
|
|
systemctl stop hytale.service || true
|
|
|
|
# Wait for server to fully stop
|
|
sleep 5
|
|
|
|
# Extract the update directly to /opt/hytale
|
|
log "Extracting $NEWEST_ZIP to $HYTALE_DIR..."
|
|
unzip -o "$NEWEST_ZIP" -d "$HYTALE_DIR"
|
|
|
|
# Fix file ownership (since this script runs as root)
|
|
chown -R mars3142:mars3142 "$HYTALE_DIR"
|
|
|
|
# Mark this update as applied
|
|
echo "$NEWEST_ZIP" >> "$APPLIED_MARKER"
|
|
|
|
# Start the server again
|
|
log "Starting Hytale server..."
|
|
systemctl start hytale.service
|
|
|
|
# Cleanup: keep only the 3 newest zip files
|
|
log "Cleaning up old zip files..."
|
|
ls -t [0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]-*.zip 2>/dev/null | tail -n +4 | xargs -r rm -f
|
|
|
|
log "Update complete!"
|