forked from drachtio/drachtio-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·96 lines (84 loc) · 3.16 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
set -e
MYARGS=()
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)
if [ -z "$IMDSv2" ]; then
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)
else
LOCAL_IP=$(TOKEN=`curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/local-ipv4)
PUBLIC_IP=$(TOKEN=`curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-ipv4)
fi
;;
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)
;;
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)
;;
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 [ "$1" = 'drachtio' ]; then
shift
while (( "$#" )); do
case $1 in
--cloud-deployment)
MYARGS+=("--contact")
MYARGS+=("sip:${LOCAL_IP}:${DRACHTIO_SIP_PORT:-5060};transport=udp,tcp")
if [ -n "$PUBLIC_IP" ]; then
if [[ "$CLOUD" == "digitalocean" ]]; then
MYARGS+=("--contact")
MYARGS+=("sip:${PUBLIC_IP}:${DRACHTIO_SIP_PORT:-5060};transport=udp,tcp")
else
MYARGS+=("--external-ip")
MYARGS+=("${PUBLIC_IP}")
fi
fi
;;
--)
shift
break
;;
*)
MYARGS+=($1)
;;
esac
shift
done
if [[ -n "$PUBLIC_IP" && -n "$WSS_PORT" ]]; then
MYARGS+=("--contact")
MYARGS+=("sips:${LOCAL_IP}:$WSS_PORT;transport=wss")
if [[ "$CLOUD" == "digitalocean" ]]; then
MYARGS+=("--contact")
MYARGS+=("sip:${PUBLIC_IP}:$WSS_PORT;transport=udp,tcp")
else
MYARGS+=("--external-ip")
MYARGS+=("${PUBLIC_IP}")
fi
fi
if [[ -n "$PUBLIC_IP" && -n "$TLS_PORT" ]]; then
MYARGS+=("--contact")
MYARGS+=("sips:${LOCAL_IP}:$TLS_PORT;transport=tls")
if [[ "$CLOUD" == "digitalocean" ]]; then
MYARGS+=("--contact")
MYARGS+=("sip:${PUBLIC_IP}:$TLS_PORT;transport=tls")
else
MYARGS+=("--external-ip")
MYARGS+=("${PUBLIC_IP}")
fi
fi
exec drachtio "${MYARGS[@]}"
fi
exec "$@"