[1] | 1 | #!/bin/sh
|
---|
| 2 | #
|
---|
| 3 | #
|
---|
| 4 | #
|
---|
| 5 | #
|
---|
| 6 | #
|
---|
| 7 | # 2003/08/04
|
---|
| 8 | # - added some logging
|
---|
| 9 | #
|
---|
| 10 | # mid-2002 --- created
|
---|
| 11 | ################################################
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | LogIt() {
|
---|
| 15 | echo "$1" >> /dev/stderr
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | AddFancyParams() {
|
---|
| 22 | local incoming device mountpoint format size original_fstab_line
|
---|
| 23 | # echo "AddFancyParams '$1'" >> /dev/stderr
|
---|
| 24 | incoming=`echo "$1" | tr -s '\t' ' '`
|
---|
| 25 | [ "$incoming" = "" ] && return
|
---|
| 26 | device=`echo "$incoming" | cut -d' ' -f1`
|
---|
| 27 | [ "`echo "$device" | grep "/dev/"`" = "" ] && return
|
---|
| 28 | mountpoint=`echo "$incoming" | cut -d' ' -f2`
|
---|
| 29 | format=`echo "$incoming" | cut -d' ' -f3`
|
---|
| 30 | size=`echo "$incoming" | cut -d' ' -f4`
|
---|
| 31 | # echo "'$device' '$mountpoint' '$format' '$size'" > /dev/stderr
|
---|
[273] | 32 | original_fstab_line=`grep " $mountpoint " $old_fstab | grep -v "#" | tr -s ' ' ' '`
|
---|
[1] | 33 | # echo "original_fstab_line = $original_fstab_line" >> /dev/stderr
|
---|
[273] | 34 | if [ "`grep "LABEL=" $old_fstab`" != "" ] ; then
|
---|
[1] | 35 | if [ "$format" = "ext2" ] || [ "$format" = "ext3" ] ; then
|
---|
| 36 | device="LABEL=$mountpoint"
|
---|
| 37 | fi
|
---|
| 38 | fi
|
---|
| 39 |
|
---|
| 40 | # LogIt "my_res = $my_res"
|
---|
| 41 |
|
---|
| 42 | echo -e -n "$device $mountpoint $format "
|
---|
| 43 |
|
---|
| 44 | 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 ' ' ' '
|
---|
| 47 | else
|
---|
| 48 | echo -e "defaults 0 0"
|
---|
| 49 | fi
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | ProcessFstab() {
|
---|
| 55 | local incoming dev mountlist_entry blanklines new_i
|
---|
| 56 | read incoming
|
---|
| 57 | blanklines=0
|
---|
| 58 | 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
|
---|
| 80 | done
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | HackIncomingIfLABELused() {
|
---|
| 85 | local incoming col1 col2 col_rest orig out result
|
---|
| 86 | result=""
|
---|
| 87 | 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 ' ' ' '`
|
---|
[273] | 91 | orig="`grep " $col2 " $old_fstab | cut -f1`"
|
---|
[1] | 92 | if [ "`echo "$orig" | grep "LABEL="`" != "" ] ; then
|
---|
| 93 | echo "orig = $orig" >> /dev/stderr
|
---|
| 94 | echo -e "$orig $col2 $col_rest | tr -s ' ' ' '"
|
---|
| 95 | fi
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | #HackIncomingIfLABELused "LABEL=/ / ext2 defaults 0,0,0"
|
---|
| 100 | #exit 0
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 | ProcessMountlist() {
|
---|
| 105 | local incoming outstr res spc
|
---|
| 106 | read incoming
|
---|
| 107 | 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
|
---|
| 122 | done
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | # ----------------- main ---------------
|
---|
| 126 |
|
---|
| 127 | LogIt "hack-fstab --- starting"
|
---|
| 128 |
|
---|
| 129 | if [ "$#" -ne "4" ] ; then
|
---|
| 130 | LogIt "hack-fstab <old mountlist> <old fstab> <new mountlist> <new fstab>" 1
|
---|
| 131 | LogIt "NB: the new fstab file is outgoing; all other files are incoming." 1
|
---|
| 132 | exit 1
|
---|
| 133 | fi
|
---|
| 134 |
|
---|
| 135 | LogIt "hack-fstab '$1' '$2' '$3' '$4'"
|
---|
| 136 |
|
---|
| 137 | old_mountlist=$1
|
---|
| 138 | old_fstab=$2
|
---|
| 139 | new_mountlist=$3
|
---|
| 140 | outfile=$4
|
---|
| 141 |
|
---|
| 142 | > $outfile
|
---|
| 143 | LogIt "Processing mountlist"
|
---|
| 144 | ProcessMountlist < $new_mountlist >> $outfile
|
---|
| 145 | LogIt "Processing fstab"
|
---|
| 146 | ProcessFstab < $old_fstab >> $outfile
|
---|
| 147 | if [ ! -e "$outfile.old" ] ; then
|
---|
| 148 | LogIt "Moving $outfile to $outfile.old" 1
|
---|
| 149 | mv $outfile $outfile.old
|
---|
| 150 | else
|
---|
| 151 | LogIt "$outfile.old exists already - assuming it _is_ the old one & using it" 1
|
---|
| 152 | fi
|
---|
| 153 | cat $outfile.old | tr -s ' ' ' ' \
|
---|
| 154 | | gawk '{printf "%-15s %-18s %-10s ",$1,$2,$3; for(i=4;i<=NF;i++) {printf "%s ",$i;};print "";};' \
|
---|
| 155 | | sort -u > $outfile
|
---|
| 156 |
|
---|
| 157 | LogIt "Finished writing to outfile ($outfile)"
|
---|
| 158 | LogIt "hack-fstab --- leaving"
|
---|
| 159 | exit 0
|
---|