source: MondoRescue/branches/3.2/mondo/src/restore-scripts/mondo/hack-fstab@ 3510

Last change on this file since 3510 was 2087, checked in by Bruno Cornec, 15 years ago
  • Adds ext4 support
  • 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 2087 2008-12-14 14:50:37Z 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 original_fstab_line=`grep " $mountpoint " $old_fstab | grep -v "#" | tr -s ' ' ' '`
24 if [ "$format" = "ext2" ] || [ "$format" = "ext3" ] || [ "$format" = "ext4" ]; then
25 if [ "`echo "$original_fstab_line" | grep "LABEL="`" != "" ] ; then
26 device="LABEL=$label"
27 fi
28 if [ "`echo "$original_fstab_line" | grep "UUID="`" != "" ] ; then
29 device="UUID=$label"
30 fi
31 fi
32
33 echo -e -n "$device $mountpoint $format "
34
35 if [ "$original_fstab_line" != "" ] ; then
36 echo "$original_fstab_line" | cut -d' ' -f4- | tr -s ' ' ' '
37 else
38 echo -e "defaults 0 0"
39 fi
40}
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.