#!/bin/bash
#%stage: block
#%modules: nfs
#%programs: /sbin/mount.nfs
#%if: "$rootfstype" = "nfs"
#
##### Network FileSystem
##
## This is where NFS gets mounted.
## If no root= option was given, the root device will be taken from the DHCP-server.
##
## Command line parameters
## -----------------------
##
## root=<server>:/<folder>	the nfs root path
##
## OR
## 
## root=/dev/nfs nfsroot=[<server>:]/<folder>

# Prefer NFS root setting via DHCP the fallback provided in config/*.
# So at first, consider the command line (that's why we check for "$cmd_root"
# being empty here. Then consider the DHCP setting. And finally consider the
# fallback via config/*.

nfs_server=
nfs_path=
# get_nfs_config [<server>:/]<path> [<server>]
# fills in the nfs_server and nfs_path variables from the options given
get_nfs_config()
{
    local url=$1 address=$2

    case "$url" in
    iscsi:*)
        ;;
    *:*)
        if test -z "$nfs_server"; then
            nfs_server=${url%:*}
        fi
        if test -z "$nfs_path"; then
            nfs_path=${url#*:}
        fi
        ;;
    *)
        if test -z "$nfs_server"; then
            nfs_server=$address;
        fi
        if test -z "$nfs_path"; then
            nfs_path=$url
        fi
    esac
}

get_nfs_config "$rootdev"
get_nfs_config "$ROOTPATH" "${DHCPSIADDR:-$DHCPSNAME}"

# load the nfs module before using it
load_modules

if test -z "$nfs_server" -o -z "$nfs_path"; then
    echo "no local root= or nfsroot= kernel option given and no root server set by the dhcp server."
    echo "exiting to /bin/sh"
    cd /
    PATH=$PATH PS1='$ ' /bin/sh -i
else
    rootdev=$nfs_server:$nfs_path
fi

rootfsmod=
if [ -n "$rootflags" ] ; then
    rootflags="${rootflags},nolock"
else
    rootflags="nolock"
fi
# tell boot.rootfsck to skip warning
ROOTFS_FSCK=0
export ROOTFS_FSCK

unset nfs_server nfs_path get_nfs_config
