From b7691e6c1b24e4c65838f40f75a24fab9b6d3b69 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 21 Aug 2026 21:55:15 +0000 Subject: [PATCH] asterisk.sh: offer to fix Caddy when DOMAIN_NAME is set but unwired, in update mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "update" mode never re-asks the domain/networking/Caddy questions, on the assumption there's already Caddy/Authelia config in place to leave alone. That assumption breaks for an install where a domain was set at some point (DOMAIN_NAME in .env) but Caddy never actually got a site block for it — declined at install time, DNS wasn't ready yet, or Caddy was reinstalled/reset separately since. Previously the only way back was a full reinstall, which re-generates a dedicated coturn container with new TURN credentials (every already-configured phone needs its QR re-scanned) — a lot of blast radius just to add one missing Caddy block, and enough that reaching for it risks the extensions/voicemail data a "fresh" reinstall can also wipe if the wrong prompt is answered. "update" mode now detects this specific gap (domain set, no matching Caddyfile block) and offers to run _asterisk_configure_caddy_public() right there — the same function "fresh" installs use, but it only ever touches the Caddyfile and .env's WEB_ADMIN_AUTH_DISABLED line, never coturn/extensions/anything else "update" already promises not to touch. Verified in isolation: offers and calls the fix when the domain is set with no matching Caddyfile block, stays silent when a block already exists. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01SpKTLpwAgZNooTacWeQLuc --- services/asterisk.sh | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/services/asterisk.sh b/services/asterisk.sh index 6bbec0c..1aed406 100644 --- a/services/asterisk.sh +++ b/services/asterisk.sh @@ -2241,8 +2241,46 @@ install_asterisk() { local _EXISTING_DOMAIN _EXISTING_PORT _EXISTING_DOMAIN="$(grep -E '^DOMAIN_NAME=' .env | cut -d= -f2-)" _EXISTING_PORT="$(grep -E '^WEB_ADMIN_PORT=' .env | cut -d= -f2-)" + + # A domain was set at some point (DOMAIN_NAME in .env) but + # Caddy never ended up with a site block for it — declined + # at install time, DNS wasn't ready yet, or Caddy itself was + # reinstalled/reset since. "update" never re-asks the + # domain/networking/firewall questions (see this branch's + # own comment above), but leaving a configured-but-unwired + # domain broken forever with no way back short of a full + # reinstall (which rotates coturn/TURN credentials — see the + # "fresh" branch's own warning below) defeats the point of + # "update" being the safe, no-side-effects path. + # _asterisk_configure_caddy_public() only ever touches the + # Caddyfile and .env's WEB_ADMIN_AUTH_DISABLED line — never + # coturn, extensions, or anything a full reinstall would put + # at risk — so it's safe to offer here even though nothing + # else in "update" touches Caddy. + local _CADDY_JUST_CONFIGURED=false + if [[ -n "$_EXISTING_DOMAIN" ]] && [[ -d "$DOCKER_DIR/caddy" ]] \ + && ! grep -q "^${_EXISTING_DOMAIN}" "$DOCKER_DIR/caddy/Caddyfile" 2>/dev/null; then + echo "" + log_warning "DOMAIN_NAME (${_EXISTING_DOMAIN}) is set, but Caddy has no site" + log_warning "block for it — nothing is actually serving that domain." + local _FIX_CADDY="" + prompt_yn " Configure Caddy for ${_EXISTING_DOMAIN} now? (y/n):" "y" _FIX_CADDY + if [[ "$_FIX_CADDY" =~ ^[Yy]$ ]]; then + local _CURRENT_PUBLIC_IP="" + _CURRENT_PUBLIC_IP="$(curl -fsS --max-time 2 http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address 2>/dev/null || true)" + [[ -z "$_CURRENT_PUBLIC_IP" ]] && _CURRENT_PUBLIC_IP="$(curl -fsS --max-time 3 https://ifconfig.me 2>/dev/null || true)" + [[ -z "$_CURRENT_PUBLIC_IP" ]] && _CURRENT_PUBLIC_IP="$(hostname -I 2>/dev/null | awk '{print $1}')" + _asterisk_configure_caddy_public "$_EXISTING_DOMAIN" "${_EXISTING_PORT:-8081}" "$_CURRENT_PUBLIC_IP" + _CADDY_JUST_CONFIGURED=true + fi + fi + echo "" - log_success "Existing .env, firewall rules, and Caddy/Authelia config were left untouched." + if [[ "$_CADDY_JUST_CONFIGURED" == true ]]; then + log_success "Existing .env and firewall rules were left untouched; Caddy was just configured above." + else + log_success "Existing .env, firewall rules, and Caddy/Authelia config were left untouched." + fi if [[ -n "$_EXISTING_DOMAIN" ]]; then echo " Web admin: https://${_EXISTING_DOMAIN}/" else