From a6dc50d51bb8e7efac1fa6f00a2fe2f535f2b9b3 Mon Sep 17 00:00:00 2001 From: Simon Boulay Date: Sat, 13 Feb 2010 01:51:18 +0100 Subject: Provide better nfsroot/rootserver/rootpath parsing --- hooks/net | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'hooks') diff --git a/hooks/net b/hooks/net index 9b97e39..86535bb 100644 --- a/hooks/net +++ b/hooks/net @@ -1,7 +1,7 @@ # vim: set ft=sh: run_hook () { - local line i address rootserver rootpath + local line i address netmask gateway dns0 dns1 rootserver rootpath defaultrootpath defaultserver : > /ip_opts @@ -47,20 +47,33 @@ run_hook () # calculate nfs_server, nfs_path and nfs_option for later nfs mount if [ "${root}" = "/dev/nfs" -o "${nfsroot}" != "" ]; then - # default rootpath - if [ "${rootpath}" = "" ]; then - rootpath="/tftpboot/${address}" + # parse rootpath if defined by dhcp server + if [ -n "${rootpath}" ]; then + line="${rootpath}" + nfs_server="${line%%:*}" + [ "${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}" + fi fi - # parse nfsroot - line="${nfsroot}" - nfs_server="${line%%:*}" - [ "${nfs_server}" = "${line}" ] && nfs_server="${rootserver}" - line="${line#*:}" - nfs_path="${line%%,*}" - line="${line#"${nfs_path}"}" - [ "${nfs_path}" = "" ] && nfs_path="${rootpath}" - nfs_option="${line#","}" + # parse nfsroot if present (overrides rootpath) + if [ -n "${nfsroot}" ]; then + line="${nfsroot}" + nfs_server="${line%%:*}" + [ -z "${nfs_server}" ] && nfs_server="${defaultserver}" + line="${line#*:}" + nfs_path="${line%%,*}" + line="${line#"${nfs_path}"}" + [ -z "${nfs_path}" ] && nfs_path="${defaultrootpath}" + nfs_option="${line#","}" + fi # ensure root and filesystem type are set proper for nfs boot root="/dev/nfs" -- cgit v1.2.3-24-g4f1b