#!/usr/bin/env bash
# Idempotent installer for the Sitesmith daily-spend alert cron.
set -euo pipefail

CRON=/etc/cron.d/sitesmith-spend-alert

# Idempotent write: only writes if content differs.
NEW="17 * * * * root /root/whp/scripts/sitesmith-spend-alert.sh >/dev/null 2>&1
"
if [ -f "$CRON" ] && printf '%s' "$NEW" | diff - "$CRON" >/dev/null 2>&1; then
    echo "sitesmith-spend-alert cron already current"
    exit 0
fi

printf '%s' "$NEW" > "$CRON"
chmod 0644 "$CRON"
echo "sitesmith-spend-alert cron installed/updated at $CRON"
