#!/usr/bin/env bash # offboard-project.sh — revoke keys, disable collectors, and delete a project from error_reporting. # # Usage: # offboard-project.sh # # Example: # ./scripts/offboard-project.sh wdmi-store # # Environment: # DATABASE_URL If set and mysql client available, applies SQL directly. # Otherwise prints SQL to stdout. set -euo pipefail _die() { echo "error: $*" >&2; exit 1; } [[ $# -eq 1 ]] || _die "Usage: offboard-project.sh " SLUG="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" [[ "${SLUG}" =~ ^[a-z0-9][a-z0-9-]{0,62}[a-z0-9]$ ]] \ || _die "slug must be 2-64 lowercase alphanumeric/hyphens: ${SLUG}" SQL="$(cat </dev/null 2>&1; then echo "DATABASE_URL is set. Applying SQL..." DB_URL="${DATABASE_URL#mysql://}" DB_USER="${DB_URL%%:*}" DB_REST="${DB_URL#*:}" DB_PASS="${DB_REST%%@*}" DB_REST="${DB_REST#*@}" DB_HOST="${DB_REST%%:*}" DB_REST="${DB_REST#*:}" DB_PORT="${DB_REST%%/*}" DB_NAME="${DB_REST#*/}" echo "${SQL}" | mysql -h"${DB_HOST}" -P"${DB_PORT}" -u"${DB_USER}" -p"${DB_PASS}" "${DB_NAME}" echo "Applied successfully." fi