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