From 1021e6ef1a21dc9b5cbbc238fd2e94db8789ea0d Mon Sep 17 00:00:00 2001 From: Gerardo Exequiel Pozzi Date: Tue, 15 Nov 2011 22:14:51 -0300 Subject: hooks/net: Refactor and remove sed cmd usage. * ipconfig cmd writes a file in /tmp that is ready for direct evaluation. We can use this instead of parsing the output, to do this some variable renames are needed. * Add /tmp as part of "base" layout since this can be used by others hooks/cmds. Signed-off-by: Gerardo Exequiel Pozzi --- hooks/net | 64 ++++++++++++++++-------------------------------------------- install/base | 2 +- 2 files changed, 18 insertions(+), 48 deletions(-) diff --git a/hooks/net b/hooks/net index 24c08f8..b964d13 100644 --- a/hooks/net +++ b/hooks/net @@ -1,9 +1,13 @@ # vim: set ft=sh: run_hook () { - local line i address netmask gateway dns0 dns1 rootserver rootpath defaultrootpath defaultserver - - : > /ip_opts + local line defaultrootpath defaultserver + # These variables will be parsed from /tmp/net-*.conf generated by ipconfig + local DEVICE + local IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1 + local HOSTNAME DNSDOMAIN NISDOMAIN ROOTSERVER ROOTPATH + local filename + # /tmp/net-*.conf if [ -z "${ip}" -a -n "${nfsaddrs}" ]; then ip="${nfsaddrs}" @@ -11,63 +15,29 @@ run_hook () if [ -n "${ip}" ]; then # setup network and save some values - ipconfig "ip=${ip}" | while read line; do - # echo ":: ${line}" - if [ "${line#"IP-Config:"}" != "${line}" ]; then - continue - fi - line="$(echo ${line} | sed -e 's/ :/:/g;s/: /=/g')" - for i in ${line}; do - case "${i}" in - address=*) - echo "${i}" >> /ip_opts - ;; - netmask=*) - echo "${i}" >> /ip_opts - ;; - gateway=*) - echo "${i}" >> /ip_opts - ;; - dns0=*) - echo "${i}" >> /ip_opts - ;; - dns1=*) - echo "${i}" >> /ip_opts - ;; - rootserver=*) - echo "${i}" >> /ip_opts - ;; - rootpath=*) - echo "${i}" >> /ip_opts - ;; - esac - done - done - - . /ip_opts + ipconfig "ip=${ip}" - echo "IP-Config: ${address}/${netmask}" - echo "IP-Config: gw: ${gateway} dns0: ${dns0} dns1: ${dns1}" + . /tmp/net-*.conf # calculate nfs_server, nfs_path and nfs_option for later nfs mount if [ "${root}" = "/dev/nfs" -o "${nfsroot}" != "" ]; then - # parse rootpath if defined by dhcp server - if [ -n "${rootpath}" ]; then - line="${rootpath}" + # parse ROOTPATH if defined by dhcp server + if [ -n "${ROOTPATH}" ]; then + line="${ROOTPATH}" nfs_server="${line%%:*}" - [ "${nfs_server}" = "${line}" ] && nfs_server="${rootserver}" + [ "${nfs_server}" = "${line}" ] && nfs_server="${ROOTSERVER}" defaultserver="${nfs_server}" line="${line#*:}" nfs_path="${line}" defaultrootpath="${nfs_path}" else - # define a default rootpath - if [ "${rootpath}" = "" ]; then - defaultrootpath="/tftpboot/${address}" + # define a default ROOTPATH + if [ "${ROOTPATH}" = "" ]; then + defaultrootpath="/tftpboot/${IPV4ADDR}" fi fi - # parse nfsroot if present (overrides rootpath) + # parse nfsroot if present (overrides ROOTPATH) if [ -n "${nfsroot}" ]; then line="${nfsroot}" nfs_server="${line%%:*}" diff --git a/install/base b/install/base index 0726fa2..db9752e 100644 --- a/install/base +++ b/install/base @@ -1,7 +1,7 @@ #!/bin/bash build() { - for dir in new_root proc sys dev run usr/{bin,sbin}; do + for dir in new_root proc sys dev run tmp usr/{bin,sbin}; do add_dir "/$dir" done -- cgit v1.2.3-24-g4f1b