convert2ipconf 968 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. # convert:
  3. # dhcptype=5
  4. # serverid=172.16.42.102
  5. # lease=97200
  6. # interface=eth0
  7. # ip=172.16.42.177
  8. # subnet=255.255.255.0
  9. # mask=24
  10. # broadcast=172.16.22.255
  11. # router=172.16.42.98
  12. # dns=10.34.32.125 10.32.63.5 10.34.255.7 10.11.255.27
  13. # domain=lab.example.com example.com
  14. # ntpsrv=10.34.32.125 10.34.255.7
  15. # into:
  16. #let cfg=cfg+1
  17. #if[$cfg]=...; ip[$cfg]=...; ipmask[$cfg]=.../...; gw[$cfg]=...; net[$cfg]=... dns[$cfg]=...
  18. exec >/dev/null
  19. #exec >"$0.out" # debug
  20. exec 2>&1
  21. test "$interface" || exit 1
  22. test "$ip" || exit 1
  23. {
  24. echo "let cfg=cfg+1"
  25. test "$interface" && echo "if[\$cfg]='$interface'"
  26. test "$ip" && echo "ip[\$cfg]='$ip'"
  27. test "$ip" && test "$mask" \
  28. && echo "ipmask[\$cfg]='$ip/$mask'"
  29. test "$router" && echo "gw[\$cfg]='$router'"
  30. test "$dns" && echo "dns[\$cfg]='$dns'"
  31. # TODO: I never saw a dhcp server which correctly announces
  32. # which subnet(s) is/are available thru advertised router
  33. # Assume 0/0
  34. echo "net[\$cfg]='0/0'"
  35. } >"$1"