-
Notifications
You must be signed in to change notification settings - Fork 5
/
cbridge-starter.sh
executable file
·48 lines (44 loc) · 1.31 KB
/
cbridge-starter.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
#!/bin/sh
# Starter script for use with systemctl service cbridge.service or launchd net.chaosnet.cbridge
#
# This is ridiculous.
# I would have expected After=network.online ns-lookup.target to take care of this,
# but without it, any DNS name parsing might fail with "temporary errors" causing config parsing to fail,
# and cbridge will not start.
# Maybe cd before starting cbridge
if [ $# -gt 0 ]; then
cd $1
fi
# Check that DNS services are up
i=0
while ! /usr/bin/host -t a router.chaosnet.net > /dev/null; do
# /sbin/ip -o addr show dev eth0 | grep 'inet ';
i=$((i+1));
sleep 2;
done
if [ $i -gt 0 ]; then
echo "Waited $i rounds for DNS to come up";
fi
# Now wait for the Chaosnet DNS server to be available.
# This is needed for TLS cert checking.
i=0
srv=""
if grep -q -E '^tls ' cbridge.conf; then
# See if some special server is configured
if grep -q -E '^dns .*server ' cbridge.conf; then
srv=`grep ^dns cbridge.conf | sed -e 's/dns .*server //' | sed -e 's/ .*//'`
fi
if [ "X$srv" = "X" ]; then
# Default DNS server
srv=dns.chaosnet.net
fi
while ! /usr/bin/host -t a -c ch router.chaosnet.net $srv > /dev/null; do
i=$((i+1));
sleep 2;
done
if [ $i -gt 0 ]; then
echo "Waited $i rounds for Chaosnet DNS to come up";
fi
fi
./cbridge-starter-services.sh &
exec ./cbridge