Files
voicebot/asterisk/entrypoint.sh
2026-07-18 01:25:01 +03:30

42 lines
1.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
set -e
TEMPLATES_DIR="/etc/asterisk-templates"
CONFIG_DIR="/etc/asterisk"
echo "[entrypoint] generating asterisk configuration..."
# کپی فایل‌های ثابت
cp "$TEMPLATES_DIR/agi.conf" "$CONFIG_DIR/agi.conf"
cp "$TEMPLATES_DIR/modules.conf" "$CONFIG_DIR/modules.conf"
# تولید extensions.conf
envsubst '${TEST_USER_EXTEN}' \
< "$TEMPLATES_DIR/extensions.conf.template" \
> "$CONFIG_DIR/extensions.conf"
# تولید pjsip.conf پایه (بدون ترانک)
envsubst '${TEST_USER_EXTEN} ${TEST_USER_PASSWORD}' \
< "$TEMPLATES_DIR/pjsip-base.conf.template" \
> "$CONFIG_DIR/pjsip.conf"
# تابع افزودن ترانک
add_trunk() {
TRUNK_NAME=$1 TRUNK_HOST=$2 TRUNK_USERNAME=$3 TRUNK_PASSWORD=$4 \
envsubst '${TRUNK_NAME} ${TRUNK_HOST} ${TRUNK_USERNAME} ${TRUNK_PASSWORD}' \
< "$TEMPLATES_DIR/pjsip-trunk.conf.template" \
>> "$CONFIG_DIR/pjsip.conf"
}
# اضافه کردن ترانک ۱
add_trunk "$TRUNK1_NAME" "$TRUNK1_HOST" "$TRUNK1_USERNAME" "$TRUNK1_PASSWORD"
# اضافه کردن ترانک ۲ (اگر وجود داشت)
if [ -n "$TRUNK2_HOST" ]; then
echo "[entrypoint] adding second trunk..."
add_trunk "$TRUNK2_NAME" "$TRUNK2_HOST" "$TRUNK2_USERNAME" "$TRUNK2_PASSWORD"
fi
echo "[entrypoint] configuration generated"
exec asterisk -f -vvv