2021-11-30 18:20:42 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Variables
|
|
|
|
if [ -z "$NC_DOMAIN" ]; then
|
|
|
|
echo "You need to provide the NC_DOMAIN."
|
|
|
|
exit 1
|
2023-06-24 23:54:12 +08:00
|
|
|
elif [ -z "$TALK_PORT" ]; then
|
|
|
|
echo "You need to provide the TALK_PORT."
|
|
|
|
exit 1
|
2021-11-30 18:20:42 +08:00
|
|
|
elif [ -z "$TURN_SECRET" ]; then
|
|
|
|
echo "You need to provide the TURN_SECRET."
|
|
|
|
exit 1
|
|
|
|
elif [ -z "$SIGNALING_SECRET" ]; then
|
2022-08-24 03:45:48 +08:00
|
|
|
echo "You need to provide the SIGNALING_SECRET."
|
2021-11-30 18:20:42 +08:00
|
|
|
exit 1
|
2023-06-06 15:22:33 +08:00
|
|
|
elif [ -z "$INTERNAL_SECRET" ]; then
|
|
|
|
echo "You need to provide the INTERNAL_SECRET."
|
|
|
|
exit 1
|
2021-11-30 18:20:42 +08:00
|
|
|
fi
|
|
|
|
|
2022-10-13 20:04:59 +08:00
|
|
|
set -x
|
2023-11-08 22:29:00 +08:00
|
|
|
IPv4_ADDRESS_TALK_RELAY="$(hostname -i | grep -oP '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -1)"
|
2024-06-10 16:38:59 +08:00
|
|
|
# shellcheck disable=SC2153
|
2024-06-07 21:17:27 +08:00
|
|
|
IPv4_ADDRESS_TALK="$(dig "$TALK_HOST" IN A +short +search | grep '^[0-9.]\+$' | sort | head -n1)"
|
2024-06-10 16:38:59 +08:00
|
|
|
# shellcheck disable=SC2153
|
2024-06-07 21:17:27 +08:00
|
|
|
IPv6_ADDRESS_TALK="$(dig "$TALK_HOST" AAAA +short +search | grep '^[0-9a-f:]\+$' | sort | head -n1)"
|
2022-10-13 20:04:59 +08:00
|
|
|
set +x
|
|
|
|
|
2023-11-08 22:17:03 +08:00
|
|
|
if [ -n "$IPv4_ADDRESS_TALK" ] && [ "$IPv4_ADDRESS_TALK_RELAY" = "$IPv4_ADDRESS_TALK" ]; then
|
|
|
|
IPv4_ADDRESS_TALK=""
|
|
|
|
fi
|
|
|
|
|
2022-10-13 20:04:59 +08:00
|
|
|
# Turn
|
2023-08-10 03:51:10 +08:00
|
|
|
cat << TURN_CONF > "/conf/eturnal.yml"
|
2023-06-24 23:54:12 +08:00
|
|
|
eturnal:
|
|
|
|
listen:
|
|
|
|
- ip: "::"
|
|
|
|
port: $TALK_PORT
|
|
|
|
transport: udp
|
|
|
|
- ip: "::"
|
|
|
|
port: $TALK_PORT
|
|
|
|
transport: tcp
|
|
|
|
log_dir: stdout
|
|
|
|
log_level: warning
|
|
|
|
secret: "$TURN_SECRET"
|
2023-11-08 22:17:03 +08:00
|
|
|
relay_ipv4_addr: "$IPv4_ADDRESS_TALK_RELAY"
|
2023-08-22 05:25:57 +08:00
|
|
|
relay_ipv6_addr: "$IPv6_ADDRESS_TALK"
|
2023-09-28 02:26:51 +08:00
|
|
|
blacklist_peers:
|
2023-06-24 23:54:12 +08:00
|
|
|
- recommended
|
2023-09-28 03:28:44 +08:00
|
|
|
whitelist_peers:
|
2023-06-24 23:54:12 +08:00
|
|
|
- 127.0.0.1
|
|
|
|
- ::1
|
2023-11-08 22:17:03 +08:00
|
|
|
- "$IPv4_ADDRESS_TALK_RELAY"
|
2023-06-24 23:54:12 +08:00
|
|
|
- "$IPv4_ADDRESS_TALK"
|
|
|
|
- "$IPv6_ADDRESS_TALK"
|
2021-11-30 18:20:42 +08:00
|
|
|
TURN_CONF
|
|
|
|
|
2023-06-24 23:54:12 +08:00
|
|
|
# Remove empty lines so that the config is not invalid
|
2023-08-10 15:16:43 +08:00
|
|
|
sed -i '/""/d' /conf/eturnal.yml
|
2023-06-24 23:54:12 +08:00
|
|
|
|
2024-04-04 17:03:02 +08:00
|
|
|
if [ -z "$TALK_MAX_STREAM_BITRATE" ]; then
|
|
|
|
TALK_MAX_STREAM_BITRATE=1048576
|
|
|
|
fi
|
|
|
|
|
2024-04-11 20:06:58 +08:00
|
|
|
if [ -z "$TALK_MAX_SCREEN_BITRATE" ]; then
|
|
|
|
TALK_MAX_SCREEN_BITRATE=2097152
|
|
|
|
fi
|
|
|
|
|
2021-11-30 18:20:42 +08:00
|
|
|
# Signling
|
2023-06-27 00:11:00 +08:00
|
|
|
cat << SIGNALING_CONF > "/conf/signaling.conf"
|
2021-11-30 18:20:42 +08:00
|
|
|
[http]
|
|
|
|
listen = 0.0.0.0:8081
|
2022-03-18 20:09:08 +08:00
|
|
|
|
2021-11-30 18:20:42 +08:00
|
|
|
[app]
|
|
|
|
debug = false
|
2022-03-18 20:09:08 +08:00
|
|
|
|
2021-11-30 18:20:42 +08:00
|
|
|
[sessions]
|
|
|
|
hashkey = $(openssl rand -hex 16)
|
|
|
|
blockkey = $(openssl rand -hex 16)
|
2022-03-18 20:09:08 +08:00
|
|
|
|
2021-11-30 18:20:42 +08:00
|
|
|
[clients]
|
2023-06-06 15:22:33 +08:00
|
|
|
internalsecret = ${INTERNAL_SECRET}
|
2022-03-18 20:09:08 +08:00
|
|
|
|
2021-11-30 18:20:42 +08:00
|
|
|
[backend]
|
2022-03-18 20:09:08 +08:00
|
|
|
backends = backend-1
|
2021-11-30 18:20:42 +08:00
|
|
|
allowall = false
|
|
|
|
timeout = 10
|
|
|
|
connectionsperhost = 8
|
2022-03-18 20:09:08 +08:00
|
|
|
|
|
|
|
[backend-1]
|
|
|
|
url = https://${NC_DOMAIN}
|
|
|
|
secret = ${SIGNALING_SECRET}
|
2024-04-04 17:03:02 +08:00
|
|
|
maxstreambitrate = ${TALK_MAX_STREAM_BITRATE}
|
2024-04-11 20:06:58 +08:00
|
|
|
maxscreenbitrate = ${TALK_MAX_SCREEN_BITRATE}
|
2022-03-18 20:09:08 +08:00
|
|
|
|
2021-11-30 18:20:42 +08:00
|
|
|
[nats]
|
|
|
|
url = nats://127.0.0.1:4222
|
2022-03-18 20:09:08 +08:00
|
|
|
|
2021-11-30 18:20:42 +08:00
|
|
|
[mcu]
|
|
|
|
type = janus
|
|
|
|
url = ws://127.0.0.1:8188
|
2024-04-04 17:03:02 +08:00
|
|
|
maxstreambitrate = ${TALK_MAX_STREAM_BITRATE}
|
2024-04-11 20:06:58 +08:00
|
|
|
maxscreenbitrate = ${TALK_MAX_SCREEN_BITRATE}
|
2021-11-30 18:20:42 +08:00
|
|
|
SIGNALING_CONF
|
|
|
|
|
|
|
|
exec "$@"
|