Files
WCX/scripts/scheduled_update_wcx.sh
2026-07-18 11:00:20 +02:00

54 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Run the WCX update at most once every 48 hours.
#
# The systemd timer invokes this script every night. The timestamp file is
# updated only after a successful WCX update.
#
set -Eeuo pipefail
ROOT_DIR="/storage/disk1/WCX"
UPDATE_SCRIPT="${ROOT_DIR}/scripts/update_wcx.sh"
STAMP_FILE="${ROOT_DIR}/database/last_scheduled_update"
MINIMUM_INTERVAL_SECONDS=$((47 * 60 * 60))
log() {
printf '[%s] %s\n' \
"$(date '+%Y-%m-%d %H:%M:%S')" \
"$*"
}
if [[ ! -x "${UPDATE_SCRIPT}" ]]; then
log "ERROR: Update script is missing or not executable: ${UPDATE_SCRIPT}" >&2
exit 1
fi
if [[ -f "${STAMP_FILE}" ]]; then
current_time=$(date +%s)
previous_time=$(stat -c %Y "${STAMP_FILE}")
elapsed_seconds=$((current_time - previous_time))
if (( elapsed_seconds < MINIMUM_INTERVAL_SECONDS )); then
elapsed_hours=$((elapsed_seconds / 3600))
log "Skipping update; previous successful scheduled run was ${elapsed_hours} hours ago."
exit 0
fi
fi
log "Starting scheduled WCX update."
"${UPDATE_SCRIPT}"
touch "${STAMP_FILE}"
log "Scheduled WCX update completed successfully."