Ignore:
Timestamp:
Jul 24, 2007, 12:42:18 AM (17 years ago)
Author:
Bruno Cornec
Message:

Fix what seems to appear a huge number of bugs in hack-fstab (illustration of 1 LOC = 1 bug :-)
Especially improve LABEL and UUID support.
Should fix #185

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mondo/src/restore-scripts/mondo/hack-fstab

    r567 r1546  
    11#!/bin/sh
    22#
     3# $Id$
    34#
    4 #
    5 #
    6 #
    7 # 2003/08/04
    8 # - added some logging
    9 #
    10 # mid-2002 --- created
    11 ################################################
    12 
     5# Recreate /etc/fstab from first mountlist analysis
     6# and then complement wirh old fstab content.
    137
    148LogIt() {
     
    1711
    1812
     13AddFancyParams() {
     14    local incoming device mountpoint format size original_fstab_line label uuid
    1915
    20 
    21 AddFancyParams() {
    22     local incoming device mountpoint format size original_fstab_line
    23 #    echo "AddFancyParams '$1'" >> /dev/stderr
    2416    incoming=`echo "$1" | tr -s '\t' ' '`
    2517    [ "$incoming" = "" ] && return
    2618    device=`echo "$incoming"     | cut -d' ' -f1`
    27     [ "`echo "$device" | grep "/dev/"`" = "" ] && return
    2819    mountpoint=`echo "$incoming" | cut -d' ' -f2`
    2920    format=`echo "$incoming"     | cut -d' ' -f3`
    3021    size=`echo "$incoming"       | cut -d' ' -f4`
    31 #    echo "'$device' '$mountpoint' '$format' '$size'" > /dev/stderr
     22    label=`echo "$incoming"       | cut -d' ' -f5`
     23    uuid=`echo "$incoming"       | cut -d' ' -f6`
    3224    original_fstab_line=`grep " $mountpoint " $old_fstab | grep -v "#" | tr -s ' ' ' '`
    33 #    echo "original_fstab_line = $original_fstab_line" >> /dev/stderr
    34     if [ "`grep "LABEL=" $old_fstab`" != "" ] ; then
    3525    if [ "$format" = "ext2" ] || [ "$format" = "ext3" ] ; then
    36         device="LABEL=$mountpoint"
    37     fi
     26        if [ "`echo "$original_fstab_line" | grep "LABEL="`" != "" ] ; then
     27            device="LABEL=$label"
     28        fi
     29        if [ "`echo "$original_fstab_line" | grep "UUID="`" != "" ] ; then
     30            device="UUID=$uuid"
     31        fi
    3832    fi
    39 
    40 #    LogIt "my_res = $my_res"
    4133
    4234    echo -e -n "$device $mountpoint $format "
    4335
    4436    if [ "$original_fstab_line" != "" ] ; then
    45 #   echo $original_fstab_line | gawk '{i=index($0,$4); print substr($0,i);}'
    46     echo "$original_fstab_line" | cut -d' ' -f4-19 | tr -s ' ' ' '
     37        echo "$original_fstab_line" | cut -d' ' -f4- | tr -s ' ' ' '
    4738    else
    48     echo -e "defaults 0 0"
     39        echo -e "defaults 0 0"
    4940    fi
    5041}
     
    5445ProcessFstab() {
    5546    local incoming dev mountlist_entry blanklines new_i
     47
    5648    read incoming
    5749    blanklines=0
    5850    while [ "$blanklines" -lt "5" ] ; do
    59     if [ "$incoming" = "" ] ; then
    60         blanklines=$(($blanklines+1))
    61         read incoming
    62         continue
    63     fi
    64     incoming=`echo "$incoming" | tr -s '\t' ' '`
    65 #   new_i=`HackIncomingIfLABELused "$incoming"`
    66 #   if [ ! "$new_i" ] ; then
    67     if [ "`echo "$incoming" | grep -v "LABEL="`" ] ; then
    68         dev=`echo "$incoming" | cut -d' ' -f1`
    69 #       echo "OK, $dev isn't a label" >> /dev/stderr
    70         mountlist_entry=`grep "$dev " $old_mountlist`
    71 #       echo "MLE($dev) = '$mountlist_entry'" >> /dev/stderr
    72         if [ "$mountlist_entry" = "" ] ; then
    73 #       echo "(PF) '$incoming'" >> /dev/stderr
    74         echo "$incoming"
    75         fi
    76 #   else
    77 #       echo "Skipping '$incoming'" >> /dev/stderr
    78     fi
    79     read incoming
     51        if [ "$incoming" = "" ] ; then
     52            blanklines=$(($blanklines+1))
     53            read incoming
     54            continue
     55        fi
     56        incoming=`echo "$incoming" | tr -s '\t' ' '`
     57        if [ "`echo "$incoming" | grep -vE "LABEL=|UUID="`" ] ; then
     58            dev=`echo "$incoming" | cut -d' ' -f1`
     59            mountlist_entry=`grep "$dev " $old_mountlist`
     60            if [ "$mountlist_entry" = "" ] ; then
     61                echo "$incoming"
     62            fi
     63        fi
     64        read incoming
    8065    done
    8166}
     
    8469HackIncomingIfLABELused() {
    8570    local incoming col1 col2 col_rest orig out result
     71
     72    # Keep LABEL or UUID if originally there in fstab
    8673    result=""
    8774    incoming=`echo "$1" | tr -s '\t' ' '`
    88     col1=`echo "$incoming" | cut -f1`
    89     col2=`echo "$incoming" | cut -f2`
    90     col_rest=`echo "$incoming" | cut -f3-19 | tr -s ' ' ' '`
    91     orig="`grep " $col2 " $old_fstab | cut -f1`"
    92     if [ "`echo "$orig" | grep "LABEL="`" != "" ] ; then
    93     echo "orig = $orig" >> /dev/stderr
    94     echo -e "$orig $col2 $col_rest | tr -s ' ' ' '"
     75    col1=`echo "$incoming" | cut -d' ' -f1`
     76    col2=`echo "$incoming" | cut -d' ' -f2`
     77    col_rest=`echo "$incoming" | cut -d' ' -f3- | tr -s ' ' ' '`
     78    orig="`grep " $col2 " $old_fstab | cut -d' ' -f1`"
     79    if [ "`echo "$orig" | grep -E "LABEL=|UUID="`" != "" ] ; then
     80        echo "orig = $orig" >> /dev/stderr
     81        echo -e "$orig $col2 $col_rest" | tr -s ' ' ' '
    9582    fi
    9683}
     
    10491ProcessMountlist() {
    10592    local incoming outstr res spc
     93
    10694    read incoming
    10795    while [ "$incoming" != "" ] ; do
    108     incoming=`echo "$incoming" | tr -s '\t' ' '`
    109 #   echo "(PM) incoming = '$incoming'" >> /dev/stderr
    110     res=`HackIncomingIfLABELused "$incoming"`
    111     if [ ! "$res" ] ; then
    112         outstr=`AddFancyParams "$incoming"`
    113     else
    114         outstr=`AddFancyParams "$res"`
    115     fi
    116     spc="`echo "$outstr" | tr -s '\t' ' '`"
    117     if [ "$spc" != "" ] && [ "$spc" != " " ] && [ "`echo "$spc" | grep "raid raid"`" = "" ] ; then
    118         echo "$spc"
    119 #       echo "(PM) outgoing = '$outstr'" >> /dev/stderr
    120     fi
    121     read incoming
     96        incoming=`echo "$incoming" | tr -s '\t' ' '`
     97        res=`HackIncomingIfLABELused "$incoming"`
     98        if [ ! "$res" ] ; then
     99            outstr=`AddFancyParams "$incoming"`
     100        else
     101            outstr=`AddFancyParams "$res"`
     102        fi
     103        spc="`echo "$outstr" | tr -s '\t' ' '`"
     104        if [ "$spc" != "" ] && [ "$spc" != " " ] && [ "`echo "$spc" | grep "raid raid"`" = "" ] ; then
     105            echo "$spc"
     106        fi
     107        read incoming
    122108    done
    123109}
Note: See TracChangeset for help on using the changeset viewer.