-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentrypoint.sh
executable file
·49 lines (36 loc) · 1003 Bytes
/
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
#!/bin/bash
# This file is used as an entrypoint for the docker container
set -e
if [ -z "$MAPPING_PREFIX" ]; then
echo "Environment variable MAPPING_PREFIX not set"
exit 1
fi
if [ -z "$MAP_STATIC" ]; then
echo "Environment variable MAP_STATIC not set"
exit 1
fi
cfile=/tmp/map646.config
echo "mapping-prefix $MAPPING_PREFIX" > $cfile
#OIFS=IFS
#for entry in $(echo "$MAP_STATIC" | tr -d ";" "$\n"); do
while IFS=';' read -a entry; do
IPv4=$(echo $entry | cut -d= -f1)
IPv6=$(echo $entry | cut -d= -f2)
if [ -z "$IPv4" -o -z "$IPv6" ]; then
echo "Error on $entry of MAP_STATIC: must be in the form IPv4=IPv6"
exit 1
fi
echo "map-static $IPv4 $IPv6" >> $cfile
done <<< "$MAP_STATIC"
echo Generated config file:
cat $cfile
echo Will run map646
./map646 -c $cfile &
map_process=$!
sleep 2
ip -6 route add $MAPPING_PREFIX/96 dev tun646 || true
while IFS=';' read -a entry; do
IPv4=$(echo $entry | cut -d= -f1)
ip route add $IPv4 dev tun646 || true
done <<< "$MAP_STATIC"
wait $!