initrd.scripts: refactor findnfsmount(), improve readability

master
Fabio Erculiani 12 years ago
parent 3790c6345a
commit 7a7e01c47e

@ -402,75 +402,80 @@ mount_sysfs() {
} }
findnfsmount() { findnfsmount() {
if [ "${IP}" != '' ] || busybox udhcpc -n -T 15 -q if [ -z "${IP}" ]; then
then # IP is not set, return straight away
[ -e /rootpath ] && NFSROOT=$(cat /rootpath) return 0
fi
if [ "${NFSROOT}" = '' ] if ! busybox udhcpc -n -T 15 -q; then
then bad_msg "udhcpc returned error, skipping nfs setup..."
# Obtain NFSIP return 0
OPTIONS=$(busybox dmesg | grep rootserver | sed -e "s/,/ /g") fi
for OPTION in $OPTIONS
do
if [ $(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1) = 'rootserver' ]
then
NFSIP=$(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2)
fi
done
# Obtain NFSPATH
OPTIONS=$(busybox dmesg | grep rootpath | sed -e "s/,/ /g")
for OPTION in $OPTIONS
do
if [ $(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1) = 'rootpath' ]
then
NFSPATH=$(echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2)
fi
done
# Setup NFSROOT local options=
if [ "${NFSIP}" != '' ] && [ "$NFSPATH" != '' ]
then
NFSROOT="${NFSIP}:${NFSPATH}"
else
bad_msg "The DHCP Server did not send a valid root-path."
bad_msg "Please check your DHCP setup, or provide a nfsroot=<...> parameter."
fi
fi
if [ "${NFSROOT}" != '' ] [ -e /rootpath ] && NFSROOT=$(cat /rootpath)
then if [ "${NFSROOT}" = "" ]; then
NFSOPTIONS=${NFSROOT#*,} # Obtain NFSIP
NFSROOT=${NFSROOT%%,*} # TODO: this is bogus, because dmesg is a circular buffer...
if [ "${NFSOPTIONS}" = "${NFSROOT}" ] # TODO: provide dmesg as symlink (see gen_initramfs.sh)
then options=$(busybox dmesg | grep rootserver | sed -e "s/,/ /g")
NFSOPTIONS=$DEFAULT_NFSOPTIONS
else local opt= optn=
NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}"
for opt in ${options}; do
optn=$(echo $opt | sed -e "s/=/ /g" | cut -d " " -f 1)
if [ "${optn}" = "rootserver" ]; then
NFSIP=$(echo $opt | sed -e "s/=/ /g" | cut -d " " -f 2)
fi fi
done
if is_livecd # Obtain NFSPATH
then # TODO: this is bogus, because dmesg is a circular buffer...
good_msg "Attempting to mount NFS CD image on ${NFSROOT} with options ${NFSOPTIONS}" # TODO: provide dmesg as symlink (see gen_initramfs.sh)
mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${CDROOT_PATH} options=$(busybox dmesg | grep rootpath | sed -e "s/,/ /g")
if [ "$?" = '0' ]
then for opt in ${options}; do
REAL_ROOT="/dev/nfs" optn=$(echo $opt | sed -e "s/=/ /g" | cut -d " " -f 1)
else if [ "${optn}" = "rootpath" ]; then
bad_msg "NFS Mounting failed. Is the path corrent ?" NFSPATH=$(echo $opt | sed -e "s/=/ /g" | cut -d " " -f 2)
fi
else
good_msg "Attempting to mount NFS root on ${NFSROOT} with options ${NFSOPTIONS}"
mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${NEW_ROOT}
if [ "$?" = '0' ]
then
REAL_ROOT="/dev/nfs"
else
bad_msg "NFS Mounting failed. Is the path correct ?"
fi
# FIXME: Need to start portmap and the other rpc daemons in
# order to remount rw.
fi fi
done
# Setup NFSROOT
if [ "${NFSIP}" != "" ] && [ "$NFSPATH" != "" ]; then
NFSROOT="${NFSIP}:${NFSPATH}"
else
bad_msg "The DHCP Server did not send a valid root-path."
bad_msg "Please check your DHCP setup, or set nfsroot=<...>"
fi
fi
if [ "${NFSROOT}" != "" ]; then
NFSOPTIONS=${NFSROOT#*,}
NFSROOT=${NFSROOT%%,*}
if [ "${NFSOPTIONS}" = "${NFSROOT}" ]; then
NFSOPTIONS="${DEFAULT_NFSOPTIONS}"
else
NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}"
fi
local path=
# override path if on livecd
if is_livecd; then
path="${CDROOT_PATH}"
good_msg "Attempting to mount NFS CD image on ${NFSROOT}."
else
path="${NEW_ROOT}"
good_msg "Attempting to mount NFS root on ${NFSROOT}."
fi
good_msg "NFS options: ${NFSOPTIONS}"
mount -t nfs -o ${NFSOPTIONS} "${NFSROOT}" "${path}"
if [ "${?}" = "0" ]; then
REAL_ROOT="/dev/nfs"
else
bad_msg "NFS Mounting failed. Is the path corrent ?"
fi fi
fi fi
} }

Loading…
Cancel
Save