1 | #!/bin/sh |
---|
2 | |
---|
3 | |
---|
4 | LogIt() { |
---|
5 | echo "$1" >> /tmp/mondo-restore.log |
---|
6 | } |
---|
7 | |
---|
8 | |
---|
9 | |
---|
10 | GetDevFromLine() { |
---|
11 | echo "$1" | cut -d'=' -f2 | sed s/' '// |
---|
12 | } |
---|
13 | |
---|
14 | |
---|
15 | GetOldFstabMountpoint() { |
---|
16 | local res |
---|
17 | res=`cat $old_fstab | tr -s '\t' ' ' | grep "$1" | cut -d' ' -f2` |
---|
18 | # echo "old_fstab = $old_fstab" >> /dev/stderr |
---|
19 | if [ "$res" = "" ] ; then |
---|
20 | # echo "OK, resB" >> /dev/stderr |
---|
21 | res=`cat $old_mountlist | tr -s '\t' ' ' | grep " $1 " | cut -d' ' -f1` |
---|
22 | fi |
---|
23 | echo "$res" |
---|
24 | } |
---|
25 | |
---|
26 | |
---|
27 | GetNewFstabMountpoint() { |
---|
28 | for i in fd0 fd0u1722 fd0h1440 fd0H1440 cdrom cdrw cdrom2 ; do |
---|
29 | if [ "$1" = "/dev/$i" ] ; then |
---|
30 | echo "/dev/$i" |
---|
31 | return |
---|
32 | fi |
---|
33 | done |
---|
34 | old_mountpoint=`GetOldFstabMountpoint $1` |
---|
35 | # echo "old_mountpoint = $old_mountpoint" >> /dev/stderr |
---|
36 | new_mountpoint=`cat $new_mountlist | tr -s '\t' ' ' | grep " $old_mountpoint" | cut -d' ' -f1` |
---|
37 | if [ "$new_mountpoint" = "" ] ; then |
---|
38 | mtpt=`cat $new_mountlist | tr -s '\t' ' ' | grep " $old_mountpoint " | cut -d' ' -f2` |
---|
39 | dev=`cat $new_mountlist | tr -s '\t' ' ' | grep " $mtpt " | cut -d' ' -f1` |
---|
40 | # echo "NEW_MP (A) = $dev" >> /dev/stderr |
---|
41 | # else |
---|
42 | # echo "NEW_MP (B) = $new_mountpoint" >> /dev/stderr |
---|
43 | fi |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | |
---|
48 | ProcessBigHack() { |
---|
49 | local incoming dev newdev col2 col1_new |
---|
50 | incoming="$1" |
---|
51 | # echo "incoming = $1" >> /dev/stderr |
---|
52 | dev=`GetDevFromLine "$incoming"` |
---|
53 | # GetOldFstabMountpoint $dev |
---|
54 | newdev=`GetNewFstabMountpoint $dev` |
---|
55 | if [ ! "$newdev" ] ; then |
---|
56 | col2=`grep "$dev " $old_mountlist | cut -d' ' -f2` |
---|
57 | col1_new=`grep " $col2 " $new_mountlist | cut -d' ' -f1` |
---|
58 | newdev="$col1_new" |
---|
59 | if [ ! "$newdev" ] ; then |
---|
60 | newdev=$dev |
---|
61 | fi |
---|
62 | fi |
---|
63 | # old_fstab_line=`grep "$dev" $new_fstab` |
---|
64 | [ "$2" = "other" ] || echo -e -n "\t" |
---|
65 | echo -e "$2=$newdev" |
---|
66 | echo "$newdev" >> $bootlistfile |
---|
67 | } |
---|
68 | |
---|
69 | ProcessOther() { |
---|
70 | ProcessBigHack "$1" "other" |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | ProcessRoot() { |
---|
75 | ProcessBigHack "$1" "root" |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | ProcessLilo() { |
---|
81 | local incoming bonks blanklines |
---|
82 | read incoming |
---|
83 | bonks=0 |
---|
84 | blanklines=0 |
---|
85 | while [ "$blanklines" -lt "5" ] ; do |
---|
86 | if [ "$incoming" = "" ] ; then |
---|
87 | blanklines=$(($blanklines+1)) |
---|
88 | read incoming |
---|
89 | continue |
---|
90 | fi |
---|
91 | blanklines=0 |
---|
92 | if [ "`echo "$incoming" | grep "#"`" != "" ] ; then |
---|
93 | echo "$incoming" |
---|
94 | elif [ "`echo "$incoming" | grep "other.*="`" != "" ] ; then |
---|
95 | ProcessOther "$incoming" |
---|
96 | bonks=$(($bonks+1)) |
---|
97 | elif [ "`echo "$incoming" | grep "root.*="`" != "" ] ; then |
---|
98 | ProcessRoot "$incoming" |
---|
99 | bonks=$(($bonks+1)) |
---|
100 | elif [ "`echo "$incoming" | grep "image.*="`" != "" ] ; then |
---|
101 | bonks=$(($bonks+1)) |
---|
102 | echo "$incoming" |
---|
103 | else |
---|
104 | if [ "$bonks" -gt "0" ] && [ "`echo "$incoming" | grep "image"`" = "" ] ; then |
---|
105 | echo -e -n "\t" |
---|
106 | fi |
---|
107 | echo "$incoming" |
---|
108 | fi |
---|
109 | read incoming |
---|
110 | done |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | # ------------------ main ------------------ |
---|
115 | |
---|
116 | LogIt "hack-lilo --- starting" |
---|
117 | |
---|
118 | bootlistfile=/tmp/partitions-to-make-bootable.txt |
---|
119 | > $bootlistfile |
---|
120 | |
---|
121 | if [ "$#" -ne "6" ] ; then |
---|
122 | LogIt "hack-lilo <old mountlist> <old fstab> <old lilo> <new mountlist> <new fstab> <new lilo>" 1 |
---|
123 | LogIt "NB: the new lilo file is outgoing; all others are incoming." 1 |
---|
124 | exit 1 |
---|
125 | fi |
---|
126 | |
---|
127 | old_mountlist=$1 |
---|
128 | old_fstab=$2 |
---|
129 | old_lilo=$3 |
---|
130 | new_mountlist=$4 |
---|
131 | new_fstab=$5 |
---|
132 | outfile=$6 |
---|
133 | |
---|
134 | > $outfile |
---|
135 | ProcessLilo < $old_lilo >> $outfile |
---|
136 | chmod 600 $outfile |
---|
137 | sort -u $bootlistfile -o $bootlistfile |
---|
138 | |
---|
139 | #------ disabled 12/10/01 (doesn't do anything anyway *g*) |
---|
140 | #make-me-bootable $bootlistfile > /tmp/make-me-bootable.log 2> /tmp/make-me-bootable.log |
---|
141 | |
---|
142 | LogIt "hack-lilo --- leaving" |
---|
143 | exit 0 |
---|