| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | # convert: |
| 3 | |
| 4 | # dhcptype=5 |
| 5 | # serverid=172.16.42.102 |
| 6 | # lease=97200 |
| 7 | # interface=eth0 |
| 8 | # ip=172.16.42.177 |
| 9 | # subnet=255.255.255.0 |
| 10 | # mask=24 |
| 11 | # broadcast=172.16.22.255 |
| 12 | # router=172.16.42.98 |
| 13 | # dns=10.34.32.125 10.32.63.5 10.34.255.7 10.11.255.27 |
| 14 | # domain=lab.example.com example.com |
| 15 | # ntpsrv=10.34.32.125 10.34.255.7 |
| 16 | |
| 17 | # into: |
| 18 | |
| 19 | #let cfg=cfg+1 |
| 20 | #if[$cfg]=...; ip[$cfg]=...; ipmask[$cfg]=.../...; gw[$cfg]=...; net[$cfg]=... dns[$cfg]=... |
| 21 | |
| 22 | #exec >/dev/null |
| 23 | #exec >"$0.out" # debug |
| 24 | exec 2>&1 |
| 25 | |
| 26 | testscip-shell system . . test. "$interface" || exit 1 |
| 27 | testscip-shell system . . test. "$ip" || exit 1 |
| 28 | |
| 29 | # some servers do not return subnet option. |
| 30 | # guess it for standard private networks. |
| 31 | if ! testscip-shell system . . test. "$mask"; then |
| 32 | case "$ip" in |
| 33 | 10.*) |
| 34 | echoscip-shell system . . echo. "mask assumed 8 for ip=$ip" |
| 35 | mask=8;; |
| 36 | #172.16-31.x.x |
| 37 | 172.1[6789].*) |
| 38 | echoscip-shell system . . echo. "mask assumed 12 for ip=$ip" |
| 39 | mask=12;; |
| 40 | 172.2[0123456789].*) |
| 41 | echoscip-shell system . . echo. "mask assumed 12 for ip=$ip" |
| 42 | mask=12;; |
| 43 | 172.3[01].*) |
| 44 | echoscip-shell system . . echo. "mask assumed 12 for ip=$ip" |
| 45 | mask=12;; |
| 46 | 192.168.*) |
| 47 | echoscip-shell system . . echo. "mask assumed 16 for ip=$ip" |
| 48 | mask=16;; |
| 49 | esac |
| 50 | fi |
| 51 | |
| 52 | # some servers do not return router option. |
| 53 | # assume DHCP server is the router. |
| 54 | if ! testscip-shell system . . test. "$router"; then |
| 55 | if testscip-shell system . . test. "$serverid"; then |
| 56 | router="$serverid" |
| 57 | echoscip-shell system . . echo. "No 'router' from the server, assuming 'serverid' is the router: $serverid" |
| 58 | fi |
| 59 | fi |
| 60 | |
| 61 | { |
| 62 | echoscip-shell system . . echo. "let cfg=cfg+1" |
| 63 | testscip-shell system . . test. "$interface" && echoscip-shell system . . echo. "if[\$cfg]='$interface'" |
| 64 | testscip-shell system . . test. "$ip" && echoscip-shell system . . echo. "ip[\$cfg]='$ip'" |
| 65 | testscip-shell system . . test. "$ip" && testscip-shell system . . test. "$mask" \ |
| 66 | && echoscip-shell system . . echo. "ipmask[\$cfg]='$ip/$mask'" |
| 67 | testscip-shell system . . test. "$router" && echoscip-shell system . . echo. "gw[\$cfg]='$router'" |
| 68 | testscip-shell system . . test. "$dns" && echoscip-shell system . . echo. "dns[\$cfg]='$dns'" |
| 69 | # TODO: I never saw a dhcp server which correctly announces |
| 70 | # which subnet(s) is/are available thru advertised router |
| 71 | # Assume 0/0 |
| 72 | echoscip-shell system . . echo. "net[\$cfg]='0/0'" |
| 73 | } >"$1" |