#!/bin/bash # Zomboid World Reset Script # Triggered by systemd path unit when discord bot requests reset set -e LOGFILE="{{ podman_home }}/.local/share/volumes/zomboid/logs/world-reset.log" TRIGGER_FILE="{{ podman_home }}/.local/share/volumes/gregtime/data/zomboid-reset.trigger" SERVER_NAME="{{ zomboid_server_name }}" SAVES_PATH="{{ podman_home }}/.local/share/volumes/zomboid/data/Saves/Multiplayer/${SERVER_NAME}" DB_PATH="{{ podman_home }}/.local/share/volumes/zomboid/data/db/${SERVER_NAME}.db" log() { local msg="[$(date '+%Y-%m-%d %H:%M:%S')] $1" echo "$msg" # stdout is already captured by the journal; the file is a convenience. # Never let it be fatal -- an unwritable log used to abort the whole wipe # on the very first line, under set -e. echo "$msg" >> "$LOGFILE" 2>/dev/null || true } # Ensure XDG_RUNTIME_DIR is set for systemctl --user export XDG_RUNTIME_DIR="/run/user/$(id -u)" log "World reset triggered" # Read requester info from trigger file if available # Note: Must use podman unshare because file is owned by container's UID (232071) if podman unshare test -f "$TRIGGER_FILE"; then REQUESTER=$(podman unshare cat "$TRIGGER_FILE") log "Requested by: $REQUESTER" podman unshare rm -f "$TRIGGER_FILE" fi # Snapshot the current settings before touching anything. They are not modified # by the wipe, but they are the one thing here with no other copy: Greg's edits # were lost once already because the only record of them was a file the server # had since overwritten. # Every step here is best-effort: a wipe must never fail because a backup could # not be written. An unwritable log aborted this whole script once already. SNAP_DIR="{{ podman_home }}/.local/share/volumes/zomboid/config-backup/$(date '+%Y-%m-%d_%H-%M-%S')" if ! mkdir -p "$SNAP_DIR" 2>/dev/null; then log "WARNING: could not create $SNAP_DIR; skipping settings snapshot" SNAP_DIR="" fi if [[ -n "$SNAP_DIR" ]]; then for f in SandboxVars spawnregions spawnpoints; do src="{{ podman_home }}/.local/share/volumes/zomboid/data/Server/${SERVER_NAME}_${f}.lua" podman unshare cp "$src" "$SNAP_DIR/${f}.lua" 2>/dev/null || true done log "Settings snapshotted to ${SNAP_DIR##*/}" # Keep the last 10 snapshots. ls -1dt "{{ podman_home }}/.local/share/volumes/zomboid/config-backup"/*/ 2>/dev/null \ | tail -n +11 | xargs -r rm -rf || true fi # Stop server log "Stopping zomboid service..." systemctl --user stop zomboid.service || true sleep 5 # Delete world (using podman unshare to work within user namespace) log "Deleting world saves at: $SAVES_PATH" if [[ -d "$SAVES_PATH" ]]; then podman unshare rm -rf "$SAVES_PATH" log "World saves deleted" else log "No world saves found at $SAVES_PATH" fi # Delete player database log "Deleting player database at: $DB_PATH" if [[ -f "$DB_PATH" ]]; then podman unshare rm -f "$DB_PATH" log "Player database deleted" else log "No database found at $DB_PATH" fi # Settings are deliberately NOT touched here. A wipe resets the world and the # players; Server/_{SandboxVars,spawnregions,spawnpoints}.lua carry over # as-is, so hand-tuned settings survive it. # # The risk that buys: PZ writes the running world's settings back over those # files, so if a world is ever created with defaults the file inherits them and # every later wipe regenerates from them -- which is how a Sophie world became an # Apocalypse one. Nothing here corrects that automatically any more, so the # snapshot above is the way back: config-backup/ holds the settings as they were # before each wipe, and config-template/ holds what this repo deploys -- since # 2026-08-31 a snapshot of Greg's live tuning, not the pristine Sophie preset. # Start server log "Starting zomboid service..." systemctl --user start zomboid.service log "World reset complete - new world will generate on first connection"