From c800d3a3322d24701eee0ad6e9643c13598738e5 Mon Sep 17 00:00:00 2001 From: Michelle Date: Thu, 26 Mar 2026 13:06:49 +0100 Subject: [PATCH] fix: enhance TURN server configuration handling in bbb-install.sh --- bbb-install.sh | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/bbb-install.sh b/bbb-install.sh index b51f19a..7ac4218 100644 --- a/bbb-install.sh +++ b/bbb-install.sh @@ -1811,17 +1811,47 @@ fi } configure_coturn() { + # Path for the TURN/STUN servers XML + TURN_XML=/etc/bigbluebutton/turn-stun-servers.xml - if [ -z "$COTURN" ]; then - # the user didn't pass '-c', so use the local TURN server's host - COTURN_HOST=$HOST - TURN_XML=/usr/share/bbb-web/WEB-INF/classes/spring/turn-stun-servers.xml - elif [[ "$COTURN" ]]; then - # the user passed '-c' with 'host:secret' - TURN_XML=/etc/bigbluebutton/turn-stun-servers.xml - fi + # If user explicitly supplied COTURN (format host[:secret]) we honor and overwrite. + if [ -n "$COTURN" ]; then + case "$COTURN" in + *:*) + COTURN_HOST="${COTURN%%:*}" + COTURN_SECRET="${COTURN#*:}" + ;; + *) + COTURN_HOST="$COTURN" + ;; + esac + else + # No explicit COTURN: use local host value + COTURN_HOST="$HOST" + + # If file exists, check whether it points to a different TURN host. + if [ -f "$TURN_XML" ]; then + # Extract all turn:/turns: entries and normalize to hostnames only + existing_hosts=$(grep -Eo 'turns?:[^:]+(:[0-9]+)?' "$TURN_XML" 2>/dev/null | \ + sed -E 's/^turns?:([^:]+).*$/\1/' | sort -u) + + for h in $existing_hosts; do + [ -z "$h" ] && continue + + # Treat unexpanded template placeholder '$HOST' as matching current host + if [ "$h" = "\$HOST" ] || [ "$h" = "$COTURN_HOST" ]; then + continue + fi - cat < $TURN_XML + say "Warning: existing TURN host ($h) in $TURN_XML does not match current host ($COTURN_HOST). Leaving $TURN_XML unchanged." + return 0 + done + fi + fi + + # At this point: either user provided COTURN (we should write), or file doesn't exist + # or existing file contains only our host — (re)write the XML. + cat < "$TURN_XML"