* luci/libs/uci: register luci_hosts in ucitrack, fix dependencies for luci_ethers...
[project/luci.git] / contrib / package / luci-addons / dist / etc / init.d / luci_hosts
1 #!/bin/sh /etc/rc.common
2 START=60
3
4 apply_host() {
5 local cfg="$1"
6
7 config_get hostname "$cfg" hostname
8 config_get ipaddr "$cfg" ipaddr
9
10 [ -n "$hostname" -a -n "$ipaddr" ] || return 0
11
12 echo "$ipaddr $hostname" >> /var/etc/hosts
13 }
14
15 start() {
16 if [ ! -L /etc/hosts ]; then
17 test -f /etc/hosts && mv /etc/hosts /etc/hosts.local
18 ln -s /var/etc/hosts /etc/hosts
19 fi
20
21 test -d /var/etc || mkdir -p /var/etc
22 test -f /etc/hosts.local && cat /etc/hosts.local >> /var/etc/hosts
23
24 config_load luci_hosts
25 config_foreach apply_host host
26
27 return 0
28 }
29
30 stop() {
31 test -f /var/etc/hosts && rm -f /var/etc/hosts
32
33 return 0
34 }