-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
run.sh
executable file
·78 lines (67 loc) · 2.16 KB
/
run.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
#!/usr/bin/with-contenv bashio
set -e
CONFIG="/etc/dhcpd.conf"
LEASES="/data/dhcpd.lease"
bashio::log.info "Creating DHCP configuration..."
# Create main config
DEFAULT_LEASE=$(bashio::config 'default_lease')
DNS=$(bashio::config 'dns|join(", ")')
DOMAIN=$(bashio::config 'domain')
MAX_LEASE=$(bashio::config 'max_lease')
{
echo "option domain-name \"${DOMAIN}\";"
echo "option domain-name-servers ${DNS};";
echo "default-lease-time ${DEFAULT_LEASE};"
echo "max-lease-time ${MAX_LEASE};"
echo "authoritative;"
} > "${CONFIG}"
# Create NTP Server List
if [ "$(bashio::config 'ntp')" ]
then
NTP=$(bashio::config 'ntp|join(", ")')
{
echo "option ntp-servers ${NTP};";
} >> "${CONFIG}"
fi
# Create networks
for network in $(bashio::config 'networks|keys'); do
BROADCAST=$(bashio::config "networks[${network}].broadcast")
GATEWAY=$(bashio::config "networks[${network}].gateway")
INTERFACE=$(bashio::config "networks[${network}].interface")
NETMASK=$(bashio::config "networks[${network}].netmask")
RANGE_END=$(bashio::config "networks[${network}].range_end")
RANGE_START=$(bashio::config "networks[${network}].range_start")
SUBNET=$(bashio::config "networks[${network}].subnet")
{
echo "subnet ${SUBNET} netmask ${NETMASK} {"
echo " interface ${INTERFACE};"
echo " range ${RANGE_START} ${RANGE_END};"
echo " option routers ${GATEWAY};"
echo " option broadcast-address ${BROADCAST};"
echo "}"
} >> "${CONFIG}"
done
# Create hosts
for host in $(bashio::config 'hosts|keys'); do
IP=$(bashio::config "hosts[${host}].ip")
MAC=$(bashio::config "hosts[${host}].mac")
NAME=$(bashio::config "hosts[${host}].name")
{
echo "host ${NAME} {"
echo " hardware ethernet ${MAC};"
echo " fixed-address ${IP};"
echo " option host-name \"${NAME}\";"
echo "}"
} >> "${CONFIG}"
done
# Create database
if ! bashio::fs.file_exists "${LEASES}"; then
touch "${LEASES}"
fi
# Start DHCP server
bashio::log.info "Starting DHCP server..."
exec /usr/sbin/dhcpd \
-4 -f -d --no-pid \
-lf "${LEASES}" \
-cf "${CONFIG}" \
< /dev/null