#!/usr/bin/env bash # ping-charles.sh — SMS Charles via T-Mobile email-to-SMS gateway. # Usage: ping-charles.sh "short message" [severity] # Relay: curl SMTP (Cloudron mail submission). Config: /home/reachableceo/.coordinate/secrets/ping-charles.env (0600) # PING_SMTP_HOST=mail.knownelement.com:587 # PING_SMTP_USER=... # PING_SMTP_PASS=... # PING_FROM=... # Until wired, messages queue in ~/.coordinate/outbox/ping-queue.txt (flushed on first successful send). set -euo pipefail DEST="8182807059@tmomail.net" CONF="$HOME/.coordinate/secrets/ping-charles.env" QUEUE="$HOME/.coordinate/outbox/ping-queue.txt" MSG="${1:?usage: ping-charles.sh \"message\" [severity]}" SEV="${2:-info}" STAMP="$(date '+%m-%d %H:%M')" LINE="[$SEV $STAMP MOPAC] $MSG" # Relay cascade (Charles 2026-08-29: local postfix relay presumed; failing # that, authenticated Cloudron submission if configured; else queue). FROM_ADDR="mopac@ultix-streaming.local" if [ -f "$CONF" ]; then set -a; . "$CONF"; set +a; fi send_one() { printf 'From: %s\nTo: %s\nSubject: MOPAC %s\nContent-Type: text/plain; charset=UTF-8\n\n%s\n' \ "$FROM_ADDR" "$DEST" "$SEV" "$1" \ | curl -sS --max-time 15 --url "smtp://localhost:25" \ --mail-from "$FROM_ADDR" --mail-rcpt "$DEST" -T - 2>/dev/null && return 0 if [ -n "${PING_SMTP_HOST:-}" ] && [ "${PING_SMTP_USER:-}" != "fill-me@knownelement.com" ]; then printf 'From: %s\nTo: %s\nSubject: MOPAC %s\nContent-Type: text/plain; charset=UTF-8\n\n%s\n' \ "$PING_FROM" "$DEST" "$SEV" "$1" \ | curl -sS --max-time 30 --ssl-reqd --url "smtp://$PING_SMTP_HOST" \ --mail-from "$PING_FROM" --mail-rcpt "$DEST" \ -u "$PING_SMTP_USER:$PING_SMTP_PASS" \ -T - 2>/dev/null && return 0 fi return 1 } if [ -f "$QUEUE" ] && [ -s "$QUEUE" ]; then while IFS= read -r queued; do send_one "$queued" && sed -i '1d' "$QUEUE" || break done < /dev/null fi if send_one "$LINE"; then echo "sms sent: $LINE" >&2 exit 0 else mkdir -p "$(dirname "$QUEUE")"; echo "$LINE" >> "$QUEUE" echo "sms send FAILED, queued: $LINE" >&2 exit 1 fi