-
Notifications
You must be signed in to change notification settings - Fork 156
/
setup.sh
executable file
·59 lines (54 loc) · 1.33 KB
/
setup.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
#!/bin/bash
[ -z "$SHARED_SECRET" ] && echo "SHARED_SECRET not set" && exit 1;
[ -z "$ZONE" ] && echo "ZONE not set" && exit 1;
[ -z "$RECORD_TTL" ] && echo "RECORD_TTL not set" && exit 1;
if ! grep 'zone "'$ZONE'"' /etc/bind/named.conf > /dev/null
then
echo "creating zone...";
cat >> /etc/bind/named.conf <<EOF
zone "$ZONE" {
type master;
file "$ZONE.zone";
allow-query { any; };
allow-transfer { none; };
allow-update { localhost; };
};
EOF
fi
if [ ! -f /var/cache/bind/$ZONE.zone ]
then
echo "creating zone file..."
cat > /var/cache/bind/$ZONE.zone <<EOF
\$ORIGIN .
\$TTL 86400 ; 1 day
$ZONE IN SOA localhost. root.localhost. (
74 ; serial
3600 ; refresh (1 hour)
900 ; retry (15 minutes)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
NS localhost.
\$ORIGIN ${ZONE}.
\$TTL ${RECORD_TTL}
EOF
fi
# If /var/cache/bind is a volume, permissions are probably not ok
chown root:bind /var/cache/bind
chown bind:bind /var/cache/bind/*
chmod 770 /var/cache/bind
chmod 644 /var/cache/bind/*
if [ ! -f /etc/dyndns.json ]
then
echo "creating REST api config..."
cat > /etc/dyndns.json <<EOF
{
"SharedSecret": "${SHARED_SECRET}",
"Server": "localhost",
"Zone": "${ZONE}.",
"Domain": "${ZONE}",
"NsupdateBinary": "/usr/bin/nsupdate",
"RecordTTL": ${RECORD_TTL}
}
EOF
fi