From f4b4d6d0d6fe55ef531a670df1c131ee8fae91e8 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Mon, 26 Aug 2013 19:58:26 +0200 Subject: [PATCH] initrd.scripts: improve findnfsmount(), simplify code and branches --- defaults/initrd.scripts | 56 +++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 344ba40..7724b73 100755 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -404,18 +404,18 @@ mount_sysfs() { findnfsmount() { if [ -z "${IP}" ]; then # IP is not set, return straight away - return 0 + return 1 fi if ! busybox udhcpc -n -T 15 -q; then bad_msg "udhcpc returned error, skipping nfs setup..." - return 0 + return 1 fi local options= [ -e /rootpath ] && NFSROOT=$(cat /rootpath) - if [ "${NFSROOT}" = "" ]; then + if [ -z "${NFSROOT}" ]; then # Obtain NFSIP # TODO: this is bogus, because dmesg is a circular buffer... # TODO: provide dmesg as symlink (see gen_initramfs.sh) @@ -443,40 +443,42 @@ findnfsmount() { done # Setup NFSROOT - if [ "${NFSIP}" != "" ] && [ "$NFSPATH" != "" ]; then + if [ -n "${NFSIP}" ] && [ -n "$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=<...>" + return 1 fi fi - if [ "${NFSROOT}" != "" ]; then - NFSOPTIONS=${NFSROOT#*,} - NFSROOT=${NFSROOT%%,*} - if [ "${NFSOPTIONS}" = "${NFSROOT}" ]; then - NFSOPTIONS="${DEFAULT_NFSOPTIONS}" - else - NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}" - fi + # expecting a valid NFSROOT here, or the code should have returned + NFSOPTIONS=${NFSROOT#*,} + NFSROOT=${NFSROOT%%,*} + if [ "${NFSOPTIONS}" = "${NFSROOT}" ]; then + NFSOPTIONS="${DEFAULT_NFSOPTIONS}" + else + NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}" + fi - local path= + 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 + 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 + good_msg "NFS options: ${NFSOPTIONS}" + mount -t nfs -o ${NFSOPTIONS} "${NFSROOT}" "${path}" + if [ "${?}" = "0" ]; then + REAL_ROOT="/dev/nfs" + return 0 + else + bad_msg "NFS Mounting failed. Is the path corrent ?" + return 1 fi }