74 lines
2.6 KiB
Bash
74 lines
2.6 KiB
Bash
#!/bin/bash
|
||
|
||
mkdir -p /root/.baresip
|
||
|
||
echo "[*] Starte baresip für mehrere Accounts mit TTS-Unterstützung..."
|
||
|
||
i=0
|
||
for account in $(jq -c '.accounts[]' /data/options.json); do
|
||
SIP_USER=$(echo $account | jq -r '.sip_user')
|
||
SIP_PASS=$(echo $account | jq -r '.sip_password')
|
||
SIP_HOST=$(echo $account | jq -r '.sip_host')
|
||
MQTT_HOST=$(echo $account | jq -r '.mqtt_host')
|
||
MQTT_TOPIC=$(echo $account | jq -r '.mqtt_topic')
|
||
MQTT_PAYLOAD=$(echo $account | jq -r '.mqtt_payload')
|
||
PIN_REQUIRED=$(echo $account | jq -r '.pin_required')
|
||
PIN_CODE=$(echo $account | jq -r '.pin_code')
|
||
TTS_PROMPT_ENABLED=$(echo $account | jq -r '.tts_pin_prompt_enabled')
|
||
TTS_PROMPT_TEXT=$(echo $account | jq -r '.tts_pin_prompt_text')
|
||
TTS_SUCCESS_ENABLED=$(echo $account | jq -r '.tts_success_enabled')
|
||
TTS_SUCCESS_TEXT=$(echo $account | jq -r '.tts_success_text')
|
||
TTS_FAILURE_ENABLED=$(echo $account | jq -r '.tts_failure_enabled')
|
||
TTS_FAILURE_TEXT=$(echo $account | jq -r '.tts_failure_text')
|
||
|
||
mkdir -p /root/.baresip$i
|
||
cat /baresip.conf.j2 | sed "s|{{ sip_user }}|$SIP_USER|g" | sed "s|{{ sip_password }}|$SIP_PASS|g" | sed "s|{{ sip_host }}|$SIP_HOST|g" > /root/.baresip$i/config
|
||
|
||
(
|
||
HOME=/root/.baresip$i baresip | while read -r line; do
|
||
echo "[$SIP_USER] $line"
|
||
|
||
if echo "$line" | grep -q "incoming call from"; then
|
||
echo "[*][$SIP_USER] Eingehender Anruf erkannt."
|
||
|
||
if [ "$PIN_REQUIRED" = "true" ]; then
|
||
if [ "$TTS_PROMPT_ENABLED" = "true" ]; then
|
||
espeak "$TTS_PROMPT_TEXT"
|
||
fi
|
||
|
||
dtmf=""
|
||
timeout=10
|
||
end=$((SECONDS + timeout))
|
||
while [ $SECONDS -lt $end ]; do
|
||
read -t 1 -r input
|
||
dtmf="$input"
|
||
if [ "$dtmf" = "$PIN_CODE" ]; then
|
||
echo "[*][$SIP_USER] PIN korrekt!"
|
||
mosquitto_pub -h "$MQTT_HOST" -t "$MQTT_TOPIC" -m "$MQTT_PAYLOAD"
|
||
if [ "$TTS_SUCCESS_ENABLED" = "true" ]; then
|
||
espeak "$TTS_SUCCESS_TEXT"
|
||
fi
|
||
break
|
||
fi
|
||
done
|
||
|
||
if [ "$dtmf" != "$PIN_CODE" ]; then
|
||
echo "[*][$SIP_USER] Falsche PIN eingegeben."
|
||
if [ "$TTS_FAILURE_ENABLED" = "true" ]; then
|
||
espeak "$TTS_FAILURE_TEXT"
|
||
fi
|
||
fi
|
||
else
|
||
echo "[*][$SIP_USER] Kein PIN nötig – sende MQTT"
|
||
mosquitto_pub -h "$MQTT_HOST" -t "$MQTT_TOPIC" -m "$MQTT_PAYLOAD"
|
||
if [ "$TTS_SUCCESS_ENABLED" = "true" ]; then
|
||
espeak "$TTS_SUCCESS_TEXT"
|
||
fi
|
||
fi
|
||
fi
|
||
done
|
||
) &
|
||
i=$((i+1))
|
||
done
|
||
|
||
wait |