Changeset 2880 in MondoRescue


Ignore:
Timestamp:
Oct 5, 2011, 11:54:20 AM (13 years ago)
Author:
Bruno Cornec
Message:
  • Fix bugs in the kernel detection routine of mindi (some echo were done without capturing their output, confusing the return). This should also help the Xen detection issue
  • Change the logging function to be nearer from 2.2.10, and start using some
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi/mindi

    r2876 r2880  
    5353    # If set to "no", the kernel is not a Xen kernel
    5454    # If "yes", mindi will modify isolinux.cfg for the Xen kernel.
     55xenkernelpath=""
     56xenkernelname=""
    5557 
    5658MY_FSTAB=/etc/fstab
     
    138140}
    139141
    140 LogIt() {
    141     if [ -e /dev/stderr ] ; then
    142         echo -e "$1" >> /dev/stderr
    143     elif [ -e /usr/bin/logger ] ; then
    144         /usr/bin/logger -s $1
    145     fi
     142LogOnly() {
    146143    echo -e "$1" >> $LOGFILE
    147144    if [ _"$2" != _"" ]; then
     
    149146    fi
    150147    rm -f "$2"
     148}
     149
     150# Function to log on screen only
     151LogScreen() {
     152    if [ -e /dev/stderr ] ; then
     153        echo -e "$1" >> /dev/stderr
     154    elif [ -e /usr/bin/logger ] ; then
     155        /usr/bin/logger -s $1
     156    fi
     157}
     158
     159# Function to log in log file only
     160LogFile() {
     161
     162    echo -e "$1" >> $LOGFILE
     163    if [ _"$2" != _"" ]; then
     164        grep -Ev "tar: Removing \`/\'" "$2" >> $LOGFILE
     165    fi
     166    rm -f "$2"
     167}
     168
     169# Function to log in both screen and logfile
     170LogAll() {
     171    LogScreen "$1"
     172    LogFile "$1" "$2"
     173}
     174
     175# Preserved for compatibility
     176LogIt() {
     177    LogAll "$1" "$2"
    151178}
    152179
     
    460487    [ ! -e "$MBOOTC32" ] && MBOOTC32=`find / -name mboot.c32 | grep -x "/.*/mboot.c32"`
    461488    [ ! -e "$MBOOTC32" ] && Die "Please install mboot.c32 first. If your syslinux RPM doesn't include mboot.c32, you may download an isolinux RPM from Mondo's website - go to http://www.mondorescue.com and click on 'Download'"
    462     echo "Found mboot.c32 at $MBOOTC32" >> $LOGFILE
    463     LogIt "  Found mboot.c32 at $MBOOTC32"
     489    LogFile "Found mboot.c32 at $MBOOTC32"
    464490}
    465491
     
    22612287
    22622288
     2289# WARNING: This function should just echo the final result !!!
     2290#
    22632291TryToFindKernelPath() {
    2264     local fname incoming res fkern_ver we_want_version possible_kernels noof_kernels kernelpath kdate duff_kernels
     2292    local fname fkern_ver we_want_version possible_kernels noof_kernels possible_xenkernels noof_xenkernels kp kdate duff_kernels output root
    22652293
    22662294    we_want_version=$KERVERRUN
    22672295    possible_kernels=""
    22682296    duff_kernels=""
     2297    output=""
    22692298   
    22702299    if [ "$ARCH" = "ia64" ] ; then
     
    22772306        # It's a Xen kernel
    22782307        KERNEL_IS_XEN="yes"
    2279         LogIt "It's a Xen kernel..."
     2308        LogFile "It's a Xen kernel..."
    22802309    fi
    22812310
     
    22932322            # Used by ia64
    22942323            if [ "`gzip -cd $fname | strings 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
    2295                 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
     2324                LogFile "Have you recompiled your kernel \"$fname\" w/o rebooting? Naughty but I'll allow it..."
    22962325                duff_kernels="$fname $duff_kernels"
    22972326            else
     
    23012330        else
    23022331            if [ "`strings $fname 2> /dev/null | grep -F "$kdate"`" = "" ] ; then
    2303                 LogIt "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
     2332                LogFile "Have you recompiled your kernel \"$fname\" w/o rebooting?\n Naughty but I'll allow it..."
    23042333                duff_kernels="$fname $duff_kernels"
    23052334            else
     
    23132342    fi
    23142343    if [ ! "$possible_kernels" ] ; then
    2315         LogIt "No kernel matches exactly. Are there any duff kernels?"
     2344        LogFile "No kernel matches exactly. Are there any duff kernels?"
    23162345        possible_kernels="$duff_kernels"
    23172346        if [ ! "$possible_kernels" ] ; then
    2318             LogIt "Sorry, no duff kernels either"
     2347            LogFile "Sorry, no duff kernels either"
    23192348        else
    2320             LogIt "I bet you're running Debian or Gentoo, aren't you?"
    2321             LogIt "Your kernel doesn't have a sane builddate. Oh well..."
     2349            LogFile "I bet you're running Debian or Gentoo, aren't you?"
     2350            LogFile "Your kernel doesn't have a sane builddate. Oh well..."
    23222351        fi
    23232352    fi
     
    23302359    noof_kernels=`CountItemsIn "$possible_kernels"`
    23312360    if [ "$noof_kernels" -eq "0" ] ; then
    2332         LogIt "Could not find your kernel."
     2361        LogFile "Could not find your kernel."
    23332362        if [ -e "/boot/vmlinuz" ] ; then
    2334             LogIt "Using /boot/vmlinuz as a last resort."
     2363            LogFile "Using /boot/vmlinuz as a last resort."
    23352364            output=/boot/vmlinuz
    23362365        else
     
    23382367        fi
    23392368    elif [ "$noof_kernels" -eq "1" ] ; then
    2340         kernelpath=`echo "$possible_kernels" | sed s/' '//`
    2341         echo "Your kernel is $kernelpath (v$KERVERRUN)" >> $LOGFILE
    2342         output="$kernelpath"
     2369        kp=`echo "$possible_kernels" | sed s/' '//`
     2370        LogFile "Your kernel is $kp (v$KERVERRUN)"
     2371        output="$kp"
    23432372    else
    23442373        for i in $possible_kernels ; do
    2345             if echo $i | grep "$KERVERRUN" ; then
    2346                 LogIt "OK, I used my initiative and found that "
    2347                 LogIt "$i is probably your kernel. "
     2374            if [ "`echo $i | grep "$KERVERRUN"`" ]; then
     2375                LogFile "OK, I used my initiative and found that "
     2376                LogFile "$i is probably your kernel. "
    23482377                output="$i"
    23492378                break
     
    23512380        done
    23522381        if [ ! -n "$output" ]; then
    2353             if echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null ; then
     2382            if [ "`echo " $possible_kernels " | grep -F "/boot/vmlinuz " &> /dev/null`" ]; then
    23542383                output=/boot/vmlinuz
    2355                 echo "Schlomo, this one's for you." >> $LOGFILE
     2384                LogFile "Schlomo, this one's for you."
    23562385            else
    2357                 LogIt "Two or more possible kernels found. You may specify any one of them and the "
    2358                 LogIt "boot disks will still work, probably. If one does not work, try another."
    2359                 LogIt "$possible_kernels"
    2360                 echo ""
     2386                LogFile "Two or more possible kernels found. You may specify any one of them and the "
     2387                LogFile "boot disks will still work, probably. If one does not work, try another."
     2388                LogFile "$possible_kernels"
     2389                output=""
    23612390            fi
    23622391        fi
     
    23672396        elif [ "$noof_xenkernels" -eq "1" ]; then
    23682397            xenkernelpath=`echo "$possible_xenkernels" | sed s/' '//`
    2369             echo "Your Xen kernel is $xenkernelpath (v$KERVERRUN)" >> $LOGFILE
     2398            LogFile "Your Xen kernel is $xenkernelpath (v$KERVERRUN)"
    23702399        else
    23712400            for i in $possible_xenkernels ; do
    2372                 if echo $i | grep "$KERVERRUN" ; then
    2373                     LogIt "OK, I used my initiative and found that "
    2374                     LogIt "$i is probably your Xen kernel. "
     2401                if [ "`echo $i | grep "$KERVERRUN"`" ]; then
     2402                    LogFile "OK, I used my initiative and found that "
     2403                    LogFile "$i is probably your Xen kernel. "
    23752404                    xenkernelpath="$i"
    23762405                    break
     
    23812410                if [ ! -n "$new_possible_xenkernels" ]; then
    23822411                    xenkernelpath=`echo $new_possible_xenkernels | tr -s ' ' '\n' | head -1`
    2383                     LogIt "Using $xenkernelpath"
     2412                    LogFile "Using $xenkernelpath"
    23842413                else
    2385                     LogIt "Two or more possible Xen kernels found. You may specify any one of them and the "
    2386                     LogIt "boot disks will still work, probably. If one does not work, try another."
    2387                     LogIt "$possible_xenkernels"
    2388                     echo ""
     2414                    LogFile "Two or more possible Xen kernels found. You may specify any one of them and the "
     2415                    LogFile "boot disks will still work, probably. If one does not work, try another."
     2416                    LogFile "$possible_xenkernels"
     2417                    output=""
    23892418                    xenkernelpath=`echo $possible_xenkernels | tr -s ' ' '\n' | head -1`
    2390                     LogIt "Using $xenkernelpath"
     2419                    LogFile "Using $xenkernelpath"
    23912420                fi
    23922421            fi
     
    23972426        fi
    23982427    fi
     2428    LogAll "TryToFindKernelPath found $output"
    23992429    echo "$output"
    24002430}
     
    28952925if [ "$#" -ne "0" ] ; then
    28962926    if [ "$1" = "--findkernel" ] ; then
    2897         res=`TryToFindKernelPath`
     2927        resk=`TryToFindKernelPath`
    28982928        # Avoids logfile content for mondo
    28992929        export MONDO_SHARE=""
    2900         if [ "$res" = "" ] ; then
     2930        if [ "$resk" = "" ] ; then
    29012931            if [ $KERNEL_IS_XEN = "yes" ]; then
    29022932                echo "$xenkernelpath"
    2903                 LogIt "xenkernelpath = $xenkernelpath"
     2933                LogOnly "xenkernelpath = $xenkernelpath"
    29042934                MindiExit 0
    29052935            else
     
    29072937            fi
    29082938        else
    2909             echo "$res"
     2939            echo "$resk"
     2940            LogOnly "kernelpath = $resk"
    29102941            MindiExit 0
    29112942        fi
Note: See TracChangeset for help on using the changeset viewer.