From 868a903683513d45903462f9f2364090003a67ed Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 27 Jul 2026 02:56:40 +0000 Subject: [PATCH] Fix sms-inbound crashing on every "update" re-run Root cause of the "line 9: from: unbound variable" crash: SMS_FORWARD_URL stores Anveo's own template placeholders literally ($[from]$, $[to]$, $[message]$ -- text Anveo substitutes on its end, not ours). Written into settings.env double-quoted, that landed in the file as SMS_FORWARD_URL="...?from=$[from]$&...". Harmless to write, but the update path `source`s this same file on every re-run, and bash reads $[from] as legacy arithmetic expansion ($[...] == $((...))) even inside double quotes -- a bare name in it means "look up variable from", which is unset, and setup.sh runs under `set -uo pipefail`, so nounset kills the whole installer before it gets anywhere near the AMI-diagnostics code from the last two commits. Fix: single-quote every value in the written settings.env. A source'd single-quoted assignment never re-expands its contents, so this is safe regardless of what SMS_FORWARD_URL (or anything else in that file) holds. This only fixes future writes -- the box that hit this already has a broken settings.env on disk from before this fix existed, and "update" mode sources that file before it gets a chance to rewrite it, so it will crash the same way one more time even after pulling this. Choosing "full install" instead on the next run skips the source entirely and regenerates the file correctly quoted. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01JDyKC6Kdg7tofmYSmRtgww --- services/sms-inbound.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/services/sms-inbound.sh b/services/sms-inbound.sh index 54680b6..903f276 100644 --- a/services/sms-inbound.sh +++ b/services/sms-inbound.sh @@ -786,16 +786,27 @@ install_sms-inbound() { local FORWARD_URL="https://${RELAY_DOMAIN:-}/sms/${RELAY_TOKEN}?from=\$[from]\$&to=\$[to]\$&message=\$[message]\$" # ── Persist settings ────────────────────────────────────────────────────── + # Single-quoted values: this file gets `source`d again on the next + # "update" run, and SMS_FORWARD_URL's value contains Anveo's own + # template placeholders ($[from]$, $[to]$, $[message]$ - literal text + # Anveo substitutes on its end). Double-quoting would leave those + # sitting unescaped in the sourced file, and bash reads "$[from]" as + # legacy arithmetic expansion ($[...] == $((...))) - a bare variable + # name inside it under `set -u` (see setup.sh) is "from: unbound + # variable", killing the whole installer. Single quotes make the + # sourced value a literal string, no re-expansion, regardless of what + # it contains. Confirmed live: this crashed "update" mode outright on + # the very next run after a fresh install wrote this file. cat > "$SMS_SETTINGS" << ENV # Written by services/sms-inbound.sh — re-run that to change any of this. -SMS_RELAY_PORT="${RELAY_PORT}" -SMS_RELAY_TOKEN="${RELAY_TOKEN}" -SMS_RELAY_DOMAIN="${RELAY_DOMAIN}" -SMS_AMI_SECRET="${AMI_SECRET}" -SMS_DOMAIN="${SMS_DOMAIN}" +SMS_RELAY_PORT='${RELAY_PORT}' +SMS_RELAY_TOKEN='${RELAY_TOKEN}' +SMS_RELAY_DOMAIN='${RELAY_DOMAIN}' +SMS_AMI_SECRET='${AMI_SECRET}' +SMS_DOMAIN='${SMS_DOMAIN}' # The exact string to paste into the DID provider's "forward SMS to URL" box. # Secret: anyone holding it can trigger a delivery into your Asterisk. -SMS_FORWARD_URL="${FORWARD_URL}" +SMS_FORWARD_URL='${FORWARD_URL}' ENV chmod 600 "$SMS_SETTINGS"