From a0b548a079931653d7b3a49b80062e324239873e Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Wed, 5 Sep 2012 09:11:29 +0200 Subject: [PATCH 1/1] Fix return code handling of config_testcd() + slightly refactor code The usage of a variable inside a *sub*shell ("RC=$?") breaks checking for this variable later in the code ("if $RC -ne 0 ..."), so testcd didn't do what we expect it to do. While at it slightly refactor the code to match the look'n'feel of grml-autoconfig. --- autoconfig.functions | 58 ++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/autoconfig.functions b/autoconfig.functions index 2a3dd66..9488f55 100755 --- a/autoconfig.functions +++ b/autoconfig.functions @@ -690,40 +690,44 @@ config_fix_passwd(){ # {{{ CD Checker config_testcd(){ if checkbootparam 'testcd' ; then - einfo "Checking CD data integrity as requested by '${WHITE}testcd${NORMAL}' boot option." + einfo "Checking CD data integrity as requested by '${WHITE}testcd${NORMAL}' boot option." + eindent - ERROR=0 - FOUND_FILE=0 + local ERROR=true + local FOUND_FILE=false + local logfile='/tmp/md5sum.log' - rm -f /tmp/md5sum.log - for md5 in $(find "${LIVECD_PATH}" -name md5sums) ; do - einfo "Checking files against $md5, this may take a while..." + rm -f "$logfile" - FOUND_FILE=1 - ( cd $(dirname "$md5") && md5sum -c $(basename "$md5") ; RC=$?) |& tee -a /tmp/md5sum.log + for md5 in $(find "${LIVECD_PATH}" -name md5sums) ; do + einfo "Checking files against $md5, this may take a while..." - if [ $RC -ne 0 ] ; then - ERROR=1 - fi - done + FOUND_FILE=true + OLD_PWD=$(pwd) + cd $(dirname "$md5") + md5sum -c $(basename "$md5") |& tee -a "${logfile}" + if [ $pipestatus[1] -eq 0 ] ; then + ERROR=false + fi + cd "${OLD_PWD}" + done - if [ $FOUND_FILE -eq 0 ] ; then - echo "${RED} *** Error: Could not find md5sum file. ***" - return - fi + if ! $FOUND_FILE ; then + eerror 'Error: Could not find md5sum file' ; eend 1 + return + fi - if [ "$ERROR" -eq 0 ]; then - einfo "Everything looks OK" ; eend 0 - else - eerror 'Checksum failed for theses files:' ; eend 1 - egrep -v '(^md5sum:|OK$)' /tmp/md5sum.log - eerror 'Data on the grml medium is possibly incomplete/damaged or...' - eerror '... RAM of your computer is broken.' ; eend 1 - einfon "Hit return to continue, or press the reset button to quit." - read a - fi + if ! $ERROR ; then + einfo "Everything looks OK" ; eend 0 + else + eerror 'Checksum failed for theses files:' ; eend 1 + egrep -v '(^md5sum:|OK$)' "${logfile}" + eerror 'Data on the medium is possibly incomplete/damaged or RAM of your system is broken.' ; eend 1 + einfon "Hit return to continue, or press the power button to shut down system." + read a + fi - eend 0 + eoutdent fi } # }}} -- 2.1.4