summaryrefslogtreecommitdiff
path: root/examples/var_service/dhcp_if/convert2ipconf
diff options
context:
space:
mode:
authorDenys Vlasenko2009-11-06 04:04:19 +0100
committerDenys Vlasenko2009-11-06 04:04:19 +0100
commit6cf7f01256c39677a0a5561ebca60e8def9d6d7e (patch)
tree9751616a6653806d6703da369616d74e38f8b785 /examples/var_service/dhcp_if/convert2ipconf
parent85bb843f47342b19c4f0814331c1f4c78b0011ad (diff)
downloadbusybox-6cf7f01256c39677a0a5561ebca60e8def9d6d7e.zip
busybox-6cf7f01256c39677a0a5561ebca60e8def9d6d7e.tar.gz
adding example runit-style service directory
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'examples/var_service/dhcp_if/convert2ipconf')
-rwxr-xr-xexamples/var_service/dhcp_if/convert2ipconf53
1 files changed, 53 insertions, 0 deletions
diff --git a/examples/var_service/dhcp_if/convert2ipconf b/examples/var_service/dhcp_if/convert2ipconf
new file mode 100755
index 0000000..cee0854
--- /dev/null
+++ b/examples/var_service/dhcp_if/convert2ipconf
@@ -0,0 +1,53 @@
+#!/bin/sh
+# convert:
+
+# dhcptype=5
+# serverid=172.16.42.102
+# lease=97200
+# interface=eth0
+# ip=172.16.42.177
+# subnet=255.255.255.0
+# mask=24
+# broadcast=172.16.22.255
+# router=172.16.42.98
+# dns=10.34.32.125 10.32.63.5 10.34.255.7 10.11.255.27
+# domain=lab.example.com example.com
+# ntpsrv=10.34.32.125 10.34.255.7
+
+# into:
+
+#let cfg=cfg+1
+#if[$cfg]=...; ip[$cfg]=...; ipmask[$cfg]=.../...; gw[$cfg]=...; net[$cfg]=... dns[$cfg]=...
+
+exec >"$0.out" 2>&1
+
+test "$interface" || exit 1
+test -f "$1" || exit 1
+
+# Unsafe, and does not handle values with spaces:
+#. "./$1" || exit 1
+# Safe(r) parsing:
+sq="'"
+while read line; do
+ #echo "line: $line"
+ # Skip empty lines and lines with single quotes
+ test "${line##*$sq*}" || continue
+ var="${line%%=*}"
+ val="${line#*=}"
+ #echo "var:$var val:'$val'"
+ eval "$var='$val'"
+done <"$1"
+
+{
+echo "let cfg=cfg+1"
+test "$interface" && echo "if[\$cfg]='$interface'"
+test "$ip" && echo "ip[\$cfg]='$ip'"
+test "$ip" && test "$mask" \
+ && echo "ipmask[\$cfg]='$ip/$mask'"
+test "$router" && echo "gw[\$cfg]='$router'"
+test "$dns" && echo "dns[\$cfg]='$dns'"
+# TODO: I never saw a dhcp server which correctly announces
+# which subnet(s) is/are available thru advertised router
+# Assume 0/0
+echo "net[\$cfg]='0/0'"
+} >"$2"