@@ -1811,17 +1811,47 @@ fi
18111811}
18121812
18131813configure_coturn () {
1814+ # Path for the TURN/STUN servers XML
1815+ TURN_XML=/etc/bigbluebutton/turn-stun-servers.xml
18141816
1815- if [ -z " $COTURN " ]; then
1816- # the user didn't pass '-c', so use the local TURN server's host
1817- COTURN_HOST=$HOST
1818- TURN_XML=/usr/share/bbb-web/WEB-INF/classes/spring/turn-stun-servers.xml
1819- elif [[ " $COTURN " ]]; then
1820- # the user passed '-c' with 'host:secret'
1821- TURN_XML=/etc/bigbluebutton/turn-stun-servers.xml
1822- fi
1817+ # If user explicitly supplied COTURN (format host[:secret]) we honor and overwrite.
1818+ if [ -n " $COTURN " ]; then
1819+ case " $COTURN " in
1820+ * :* )
1821+ COTURN_HOST=" ${COTURN%%:* } "
1822+ COTURN_SECRET=" ${COTURN#*: } "
1823+ ;;
1824+ * )
1825+ COTURN_HOST=" $COTURN "
1826+ ;;
1827+ esac
1828+ else
1829+ # No explicit COTURN: use local host value
1830+ COTURN_HOST=" $HOST "
1831+
1832+ # If file exists, check whether it points to a different TURN host.
1833+ if [ -f " $TURN_XML " ]; then
1834+ # Extract all turn:/turns: entries and normalize to hostnames only
1835+ existing_hosts=$( grep -Eo ' turns?:[^:]+(:[0-9]+)?' " $TURN_XML " 2> /dev/null | \
1836+ sed -E ' s/^turns?:([^:]+).*$/\1/' | sort -u)
1837+
1838+ for h in $existing_hosts ; do
1839+ [ -z " $h " ] && continue
1840+
1841+ # Treat unexpanded template placeholder '$HOST' as matching current host
1842+ if [ " $h " = " \$ HOST" ] || [ " $h " = " $COTURN_HOST " ]; then
1843+ continue
1844+ fi
18231845
1824- cat << HERE > $TURN_XML
1846+ say " Warning: existing TURN host ($h ) in $TURN_XML does not match current host ($COTURN_HOST ). Leaving $TURN_XML unchanged."
1847+ return 0
1848+ done
1849+ fi
1850+ fi
1851+
1852+ # At this point: either user provided COTURN (we should write), or file doesn't exist
1853+ # or existing file contains only our host — (re)write the XML.
1854+ cat << HERE > "$TURN_XML "
18251855<?xml version="1.0" encoding="UTF-8"?>
18261856<beans xmlns="http://www.springframework.org/schema/beans"
18271857 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
0 commit comments