root/luci/trunk/modules/admin-core/root/etc/init.d/luci_hosts @ 4174

Revision 4174, 0.7 KB (checked in by jow, 4 years ago)

modules/admin-core: add autogeneartion notice to /var/etc/hosts, /var/etc/ethers

  • Property svn:executable set to *
Line 
1#!/bin/sh /etc/rc.common
2START=59
3
4apply_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
15start() {
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    echo "# This file is autogenerated, use /etc/hosts.local instead" > /var/etc/hosts
22
23    test -d /var/etc || mkdir -p /var/etc
24    test -f /etc/hosts.local && cat /etc/hosts.local >> /var/etc/hosts
25
26    config_load luci_hosts
27    config_foreach apply_host host
28
29    return 0
30}
31
32stop() {
33    test -f /var/etc/hosts && rm -f /var/etc/hosts
34
35    return 0
36}
Note: See TracBrowser for help on using the browser.