2022-12-03 17:23:19 +01:00
|
|
|
#!/command/with-contenv bash
|
2022-11-22 02:31:39 +01:00
|
|
|
# shellcheck shell=bash
|
2022-12-07 14:47:40 +01:00
|
|
|
# Start the go2rtc service
|
2022-11-02 12:36:09 +01:00
|
|
|
|
2022-12-07 14:47:40 +01:00
|
|
|
set -o errexit -o nounset -o pipefail
|
2022-11-02 12:36:09 +01:00
|
|
|
|
2023-02-19 20:11:12 +01:00
|
|
|
# Logs should be sent to stdout so that s6 can collect them
|
2023-01-18 14:53:53 +01:00
|
|
|
|
2023-01-19 00:23:40 +01:00
|
|
|
function get_ip_and_port_from_supervisor() {
|
|
|
|
local ip_address
|
|
|
|
# Example: 192.168.1.10/24
|
2023-01-24 14:26:16 +01:00
|
|
|
local ip_regex='^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/[0-9]{1,2}$'
|
2023-01-19 00:23:40 +01:00
|
|
|
if ip_address=$(
|
|
|
|
curl -fsSL \
|
|
|
|
-H "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
http://supervisor/network/interface/default/info |
|
|
|
|
jq --exit-status --raw-output '.data.ipv4.address[0]'
|
|
|
|
) && [[ "${ip_address}" =~ ${ip_regex} ]]; then
|
|
|
|
ip_address="${BASH_REMATCH[1]}"
|
2023-02-19 20:11:12 +01:00
|
|
|
echo "[INFO] Got IP address from supervisor: ${ip_address}"
|
2023-01-19 00:23:40 +01:00
|
|
|
else
|
2023-02-19 20:11:12 +01:00
|
|
|
echo "[WARN] Failed to get IP address from supervisor"
|
2023-01-19 00:23:40 +01:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
local webrtc_port
|
|
|
|
local port_regex='^([0-9]{1,5})$'
|
|
|
|
if webrtc_port=$(
|
|
|
|
curl -fsSL \
|
|
|
|
-H "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
http://supervisor/addons/self/info |
|
2023-01-24 14:26:16 +01:00
|
|
|
jq --exit-status --raw-output '.data.network["8555/tcp"]'
|
2023-01-19 00:23:40 +01:00
|
|
|
) && [[ "${webrtc_port}" =~ ${port_regex} ]]; then
|
|
|
|
webrtc_port="${BASH_REMATCH[1]}"
|
2023-02-19 20:11:12 +01:00
|
|
|
echo "[INFO] Got WebRTC port from supervisor: ${webrtc_port}"
|
2023-01-19 00:23:40 +01:00
|
|
|
else
|
2023-02-19 20:11:12 +01:00
|
|
|
echo "[WARN] Failed to get WebRTC port from supervisor"
|
2023-01-19 00:23:40 +01:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
export FRIGATE_GO2RTC_WEBRTC_CANDIDATE_INTERNAL="${ip_address}:${webrtc_port}"
|
|
|
|
}
|
|
|
|
|
2023-02-19 20:11:12 +01:00
|
|
|
if [[ ! -f "/dev/shm/go2rtc.yaml" ]]; then
|
|
|
|
echo "[INFO] Preparing go2rtc config..."
|
2023-01-19 00:23:40 +01:00
|
|
|
|
2023-02-19 20:11:12 +01:00
|
|
|
if [[ -n "${SUPERVISOR_TOKEN:-}" ]]; then
|
|
|
|
# Running as a Home Assistant add-on, infer the IP address and port
|
|
|
|
get_ip_and_port_from_supervisor
|
|
|
|
fi
|
2023-01-19 00:23:40 +01:00
|
|
|
|
2023-02-19 20:11:12 +01:00
|
|
|
python3 /usr/local/go2rtc/create_config.py
|
|
|
|
fi
|
2022-11-02 12:36:09 +01:00
|
|
|
|
2023-03-30 02:08:04 +02:00
|
|
|
readonly config_path="/config"
|
|
|
|
|
|
|
|
if [[ -x "${config_path}/go2rtc" ]]; then
|
|
|
|
readonly binary_path="${config_path}/go2rtc"
|
|
|
|
echo "[WARN] Using go2rtc binary from '${binary_path}' instead of the embedded one" >&2
|
|
|
|
else
|
|
|
|
readonly binary_path="/usr/local/go2rtc/bin/go2rtc"
|
|
|
|
fi
|
|
|
|
|
2023-02-19 20:11:12 +01:00
|
|
|
echo "[INFO] Starting go2rtc..."
|
2023-01-19 00:23:40 +01:00
|
|
|
|
2022-12-07 14:47:40 +01:00
|
|
|
# Replace the bash process with the go2rtc process, redirecting stderr to stdout
|
|
|
|
exec 2>&1
|
2023-03-30 02:08:04 +02:00
|
|
|
exec "${binary_path}" -config=/dev/shm/go2rtc.yaml
|