Here's a new hotplug script I created in hotplug.d/iface/01-hosts that I'd like to propose for addition to the standard hotplug scripts.
The result of that script after a reboot of my router is:
root at gw:~# cat /etc/hosts
127.0.0.1 localhost.
10.75.22.254 lan
33.1.73.242 wan1
167.9.10.202 wan0
The idea is to populate a local host entry for each interface and it's
address so that configuration files which want a hostname can get one
before any DDNS is updated with new addresses, etc.
Signed-off-by: Brian J. Murrell <[EMAIL PROTECTED]>
--- /dev/null 2008-04-20 11:31:37.000000000 -0400
+++ package/base-files/files/etc/hotplug.d/iface/01-hosts 2008-06-06
13:00:18.000000000 -0400
@@ -0,0 +1,36 @@
+config_load network
+config_get ifname "$INTERFACE" ifname
+
+config_load /var/state/network
+
+# standard hosts file already has a loopback/localhost entry
+[ "$INTERFACE" = loopback ] && exit 0
+
+# need to wait for others to be done
+n=0
+while [ -f /tmp/edit_hosts -a $n -lt 5 ]; do
+ sleep 1
+ let n=n+1
+done
+
+[ -f /tmp/edit_hosts ] && {
+ logger "Unable to update /etc/hosts due to lock file /tmp/edit_hosts
being present for more than 5 seconds"
+ exit 0
+}
+
+# tell others we are working
+echo $$ > /tmp/edit_hosts
+
+[ ifup = "$ACTION" ] && {
+ config_get addr "$INTERFACE" ipaddr
+
+ [ -n "$addr" ] && \
+ sed -i -e "/^.* $INTERFACE$/d" -e "\$a$addr $INTERFACE"
/etc/hosts
+}
+
+[ ifdown = "$ACTION" ] && {
+ sed -i -e "/^.* $INTERFACE$/d" /etc/hosts
+}
+
+rm -f /tmp/edit_hosts
+
signature.asc
Description: This is a digitally signed message part
_______________________________________________ openwrt-devel mailing list [email protected] http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
