summaryrefslogtreecommitdiffhomepage
path: root/contrib/package/luci-addons/dist/etc
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2008-09-06 17:20:27 +0000
committerJo-Philipp Wich <jow@openwrt.org>2008-09-06 17:20:27 +0000
commitbe767cb726d23a4e2daa27f8b4ecde161c15c0ed (patch)
treef0fcc4de920a3c0718765e31b1734e9c61f7a11f /contrib/package/luci-addons/dist/etc
parenta849e84bfbdb6e09ade2aea31be0eb28bd3c67b4 (diff)
* luci/contrib/addons: add luci_hosts infrastructure
Diffstat (limited to 'contrib/package/luci-addons/dist/etc')
-rw-r--r--contrib/package/luci-addons/dist/etc/config/luci_hosts3
-rw-r--r--contrib/package/luci-addons/dist/etc/init.d/luci_hosts30
2 files changed, 33 insertions, 0 deletions
diff --git a/contrib/package/luci-addons/dist/etc/config/luci_hosts b/contrib/package/luci-addons/dist/etc/config/luci_hosts
new file mode 100644
index 0000000000..6221df72d7
--- /dev/null
+++ b/contrib/package/luci-addons/dist/etc/config/luci_hosts
@@ -0,0 +1,3 @@
+config 'host'
+ option 'ipaddr' '10.11.12.13'
+ option 'hostname' 'sample-host'
diff --git a/contrib/package/luci-addons/dist/etc/init.d/luci_hosts b/contrib/package/luci-addons/dist/etc/init.d/luci_hosts
new file mode 100644
index 0000000000..42ccff4712
--- /dev/null
+++ b/contrib/package/luci-addons/dist/etc/init.d/luci_hosts
@@ -0,0 +1,30 @@
+#!/bin/sh /etc/rc.common
+START=60
+
+apply_host() {
+ local cfg="$1"
+
+ config_get hostname "$cfg" hostname
+ config_get ipaddr "$cfg" ipaddr
+
+ [ -n "$hostname" -a -n "$ipaddr" ] || return 0
+
+ echo "$ipaddr $hostname" >> /var/etc/hosts
+}
+
+start() {
+ if [ ! -L /etc/hosts ]; then
+ test -f /etc/hosts && mv /etc/hosts /etc/hosts.local
+ ln -s /var/etc/hosts /etc/hosts
+ fi
+
+ test -d /var/etc || mkdir -p /var/etc
+ test -f /etc/hosts.local && cat /etc/hosts.local >> /var/etc/hosts
+
+ config_load luci_hosts
+ config_foreach apply_host host
+}
+
+stop() {
+ test -f /var/etc/hosts && rm -f /var/etc/hosts
+}