-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·67 lines (53 loc) · 1.5 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
set +e
: ${RTE_TABLE:=0}
function install_module() {
if [ $(lsmod |grep -c xt_RTPENGINE) -gt 0 ]; then
return
fi
echo "Installing kernel module..."
dkms autoinstall
depmod -a
insmod /lib/modules/$(uname -r)/updates/dkms/xt_RTPENGINE.ko
}
function install_iptables() {
echo "Installing IPTables hook..."
if [ $(iptables -L INPUT |grep RTPENGINE |grep -c id:${RTE_TABLE}) -eq 0 ]; then
iptables -I INPUT -p udp -j RTPENGINE --id ${RTE_TABLE}
fi
if [ $(ip6tables -L INPUT |grep RTPENGINE |grep -c id:${RTE_TABLE}) -eq 0 ]; then
ip6tables -I INPUT -p udp -j RTPENGINE --id ${RTE_TABLE}
fi
}
function remove_old_table() {
if [ $(cat /proc/rtpengine/list |grep -c "^${RTE_TABLE}$") -gt 0 ]; then
echo "Deleting old RTE table ${RTE_TABLE}..."
echo "del $RTE_TABLE" > /proc/rtpengine/control
fi
}
install_module
# Calculate interfaces
INTERFACES=""
EXTIPV4=$(netdiscover -field publicv4)
if [ ! -z "$EXTIPV4" ]; then
INTERFACES="$INTERFACES --interface=$EXTIPV4"
fi
EXTIPV6=$(netdiscover -field publicv6)
if [ ! -z "$EXTIPV6" ]; then
INTERFACES="$INTERFACES --interface=$EXTIPV6"
fi
# first arg is `-f` or `--some-option`
# or first arg is `something.conf`
if [ "${1#-}" != "$1" ] ; then
set -- rtpengine "$@"
fi
if [ "$1" == "rtpengine" ]; then
remove_old_table
install_iptables
shift
echo "Starting RTPEngine..."
exec rtpengine --table=$RTE_TABLE $INTERFACES $@
else
echo "Starting provided command..."
exec $@
fi