-
Notifications
You must be signed in to change notification settings - Fork 42
/
entrypoint.sh
executable file
·47 lines (41 loc) · 1.74 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
#!/bin/bash
set -e
PATH=/usr/local/bin:$PATH
case $CLOUD in
gcp)
LOCAL_IP=$(curl -s -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip)
PUBLIC_IP=$(curl -s -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip)
;;
aws)
LOCAL_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
PUBLIC_IP=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)
;;
scaleway)
LOCAL_IP=$(curl -s --local-port 1-1024 http://169.254.42.42/conf | grep PRIVATE_IP | cut -d = -f 2)
PUBLIC_IP=$(curl -s --local-port 1-1024 http://169.254.42.42/conf | grep PUBLIC_IP_ADDRESS | cut -d = -f 2)
;;
digitalocean)
LOCAL_IP=$(curl -s http://169.254.169.254/metadata/v1/interfaces/private/0/ipv4/address)
PUBLIC_IP=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
;;
azure)
LOCAL_IP=$(curl -H Metadata:true "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/privateIpAddress?api-version=2017-08-01&format=text")
PUBLIC_IP=$(curl -H Metadata:true "http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-08-01&format=text")
;;
*)
;;
esac
if [ -n "$PUBLIC_IP" ]; then
MY_IP="$LOCAL_IP"!"$PUBLIC_IP"
elif [ -n "$LOCAL_IP" ]; then
MY_IP="$LOCAL_IP"
else
MY_IP=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'`
fi
sed -i -e "s/interface=MY_IP/interface=$MY_IP/g" /etc/rtpengine.conf
sed -i -e "s/MY_IP/$LOCAL_IP/g" /etc/rtpengine.conf
if [ "$1" = 'rtpengine' ]; then
shift
exec rtpengine --config-file /etc/rtpengine.conf "$@"
fi
exec "$@"