source: MondoRescue/branches/stable/mondo/src/restore-scripts/mondo/hack-fstab @ 1548

Last change on this file since 1548 was 1548, checked in by Bruno Cornec, 13 years ago
  • Add the possibiilty to edit in interactive mode mtab and device.map for grub
  • Remove blkid cache files after restore to avoid problems in cloning mode
  • 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
  • Exclude_path should be 4*MAX_STR_LEN everywhere. Fixed now.
  • Increasing that value will allow to having larger exclude paths.
  • Should solve bug #137 (and maybe #3 as well)
  • Adds support for fedora 7

(merge -r 1533:1547 $SVN_M/branches/2.2.5)

  • Property svn:keywords set to Id
  • Property svn:unix-mode set to 755
File size: 3.8 KB
Line 
1#!/bin/sh
2#
3# $Id: hack-fstab 1548 2007-07-23 23:39:36Z bruno $
4#
5# Recreate /etc/fstab from first mountlist analysis
6# and then complement wirh old fstab content.
7
8LogIt() {
9    echo "$1" >> /dev/stderr
10}
11
12
13AddFancyParams() {
14    local incoming device mountpoint format size original_fstab_line label uuid
15
16    incoming=`echo "$1" | tr -s '\t' ' '`
17    [ "$incoming" = "" ] && return
18    device=`echo "$incoming"     | cut -d' ' -f1`
19    mountpoint=`echo "$incoming" | cut -d' ' -f2`
20    format=`echo "$incoming"     | cut -d' ' -f3`
21    size=`echo "$incoming"       | cut -d' ' -f4`
22    label=`echo "$incoming"       | cut -d' ' -f5`
23    uuid=`echo "$incoming"       | cut -d' ' -f6`
24    original_fstab_line=`grep " $mountpoint " $old_fstab | grep -v "#" | tr -s ' ' ' '`
25    if [ "$format" = "ext2" ] || [ "$format" = "ext3" ] ; then
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
32    fi
33
34    echo -e -n "$device $mountpoint $format "
35
36    if [ "$original_fstab_line" != "" ] ; then
37        echo "$original_fstab_line" | cut -d' ' -f4- | tr -s ' ' ' '
38    else
39        echo -e "defaults 0 0"
40    fi
41}
42
43
44ProcessFstab() {
45    local incoming dev mountlist_entry blanklines new_i
46
47    read incoming
48    blanklines=0
49    while [ "$blanklines" -lt "5" ] ; do
50        if [ "$incoming" = "" ] ; then
51            blanklines=$(($blanklines+1))
52            read incoming
53            continue
54        fi
55        incoming=`echo "$incoming" | tr -s '\t' ' '`
56        if [ "`echo "$incoming" | grep -vE "LABEL=|UUID="`" ] ; then
57            dev=`echo "$incoming" | cut -d' ' -f1`
58            mountlist_entry=`grep "$dev " $old_mountlist`
59            if [ "$mountlist_entry" = "" ] ; then
60                echo "$incoming"
61            fi
62        fi
63        read incoming
64    done
65}
66
67
68HackIncomingIfLABELused() {
69    local incoming col1 col2 col_rest orig out result
70
71    # Keep LABEL or UUID if originally there in fstab
72    result=""
73    incoming=`echo "$1" | tr -s '\t' ' '`
74    col1=`echo "$incoming" | cut -d' ' -f1`
75    col2=`echo "$incoming" | cut -d' ' -f2`
76    col_rest=`echo "$incoming" | cut -d' ' -f3- | tr -s ' ' ' '`
77    orig="`grep " $col2 " $old_fstab | cut -d' ' -f1`"
78    if [ "`echo "$orig" | grep -E "LABEL=|UUID="`" != "" ] ; then
79        echo "orig = $orig" >> /dev/stderr
80        echo -e "$orig $col2 $col_rest" | tr -s ' ' ' '
81    fi
82}
83
84
85#HackIncomingIfLABELused "LABEL=/ / ext2 defaults 0,0,0"
86#exit 0
87
88
89
90ProcessMountlist() {
91    local incoming outstr res spc
92
93    read incoming
94    while [ "$incoming" != "" ] ; do
95        incoming=`echo "$incoming" | tr -s '\t' ' '`
96        res=`HackIncomingIfLABELused "$incoming"`
97        if [ ! "$res" ] ; then
98            outstr=`AddFancyParams "$incoming"`
99        else
100            outstr=`AddFancyParams "$res"`
101        fi
102        spc="`echo "$outstr" | tr -s '\t' ' '`"
103        if [ "$spc" != "" ] && [ "$spc" != " " ] && [ "`echo "$spc" | grep "raid raid"`" = "" ] ; then
104            echo "$spc"
105        fi
106        read incoming
107    done
108}
109
110# ----------------- main ---------------
111
112LogIt "hack-fstab --- starting"
113
114if [ "$#" -ne "4" ] ; then
115    LogIt "hack-fstab <old mountlist> <old fstab> <new mountlist> <new fstab>" 1
116    LogIt "NB: the new fstab file is outgoing; all other files are incoming." 1
117    exit 1
118fi
119
120LogIt "hack-fstab '$1' '$2' '$3' '$4'"
121
122old_mountlist=$1
123old_fstab=$2
124new_mountlist=$3
125outfile=$4
126
127> $outfile
128LogIt "Processing mountlist"
129ProcessMountlist < $new_mountlist >> $outfile
130LogIt "Processing fstab"
131ProcessFstab < $old_fstab >> $outfile
132if [ ! -e "$outfile.old" ] ; then
133    LogIt "Moving $outfile to $outfile.old" 1
134    mv $outfile $outfile.old
135else
136    LogIt "$outfile.old exists already - assuming it _is_ the old one & using it" 1
137fi
138cat $outfile.old | tr -s ' ' ' ' \
139| gawk '{printf "%-15s %-18s %-10s ",$1,$2,$3; for(i=4;i<=NF;i++) {printf "%s ",$i;};print "";};' \
140| sort -u > $outfile
141
142LogIt "Finished writing to outfile ($outfile)"
143LogIt "hack-fstab --- leaving"
144exit 0
Note: See TracBrowser for help on using the repository browser.