#!/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 # 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 # Restore the intended world settings before the server regenerates. # # Without this the wipe silently changes the game. PZ writes the running world's # settings back over Server/_SandboxVars.lua, so by the time we delete the # save that file already describes the world we are throwing away -- and if that # world had defaults, the replacement inherits them. Restoring from the canonical # copy is what makes a wipe reset the world and keep the settings. CONFIG_TEMPLATE="{{ podman_home }}/.local/share/volumes/zomboid/config-template" SERVER_DIR="{{ podman_home }}/.local/share/volumes/zomboid/data/Server" for f in SandboxVars spawnregions spawnpoints; do if [[ -f "${CONFIG_TEMPLATE}/${f}.lua" ]]; then podman unshare cp "${CONFIG_TEMPLATE}/${f}.lua" "${SERVER_DIR}/${SERVER_NAME}_${f}.lua" log "Restored ${SERVER_NAME}_${f}.lua from canonical config" else log "WARNING: no canonical ${f}.lua; the new world will inherit whatever the server last wrote" fi done # Start server log "Starting zomboid service..." systemctl --user start zomboid.service log "World reset complete - new world will generate on first connection"