[arch-projects] [RFC] Refactor hooks/net, remove last sed cmd usage.
I just sent this as RFC since I not tested this change using this hook, instead I tested the same logic on recently changed hooks/archiso_pxe_nbd and works fine. The code looks much simple now.
* 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 <vmlinuz386@yahoo.com.ar> --- 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 -- 1.7.7.3
This feature was present in archiso_pxe_nbd for a long time. it avoids to configure more than one device (if present) by ipconfig with the same parameters. Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> --- hooks/net | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/hooks/net b/hooks/net index b964d13..ea19230 100644 --- a/hooks/net +++ b/hooks/net @@ -1,7 +1,7 @@ # vim: set ft=sh: run_hook () { - local line defaultrootpath defaultserver + local line i net_mac bootif_mac bootif_dev defaultrootpath defaultserver # These variables will be parsed from /tmp/net-*.conf generated by ipconfig local DEVICE local IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1 @@ -14,6 +14,20 @@ run_hook () fi if [ -n "${ip}" ]; then + if [ -n "${BOOTIF}" ]; then + bootif_mac=${BOOTIF#01-} + bootif_mac=${bootif_mac//-/:} + for i in /sys/class/net/*/address; do + read net_mac < ${i} + if [ "${bootif_mac}" == "${net_mac}" ]; then + bootif_dev=${i#/sys/class/net/} + bootif_dev=${bootif_dev%/address} + break + fi + done + ip="${ip}::${bootif_dev}" + fi + # setup network and save some values ipconfig "ip=${ip}" -- 1.7.7.3
participants (1)
-
Gerardo Exequiel Pozzi