source: MondoRescue/trunk/mondo/mondo/restore-scripts/mondo/hack-lilo@ 1

Last change on this file since 1 was 1, checked in by bcornec, 19 years ago

Initial import from latest mondo-2.04_cvs_20050503/mindi-1.04_cvs_20050503 on http://www.mondorescue.org

File size: 3.4 KB
Line 
1#!/bin/sh
2
3
4LogIt() {
5 echo "$1" >> /tmp/mondo-restore.log
6}
7
8
9
10GetDevFromLine() {
11 echo "$1" | cut -d'=' -f2 | sed s/' '//
12}
13
14
15GetOldFstabMountpoint() {
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
27GetNewFstabMountpoint() {
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
48ProcessBigHack() {
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=`cat $old_mountlist | grep "$dev " | cut -d' ' -f2`
57 col1_new=`cat $new_mountlist | grep " $col2 " | cut -d' ' -f1`
58 newdev="$col1_new"
59 if [ ! "$newdev" ] ; then
60 newdev=$dev
61 fi
62 fi
63# old_fstab_line=`cat $new_fstab | grep "$dev"`
64 [ "$2" = "other" ] || echo -e -n "\t"
65 echo -e "$2=$newdev"
66 echo "$newdev" >> $bootlistfile
67}
68
69ProcessOther() {
70 ProcessBigHack "$1" "other"
71}
72
73
74ProcessRoot() {
75 ProcessBigHack "$1" "root"
76}
77
78
79
80ProcessLilo() {
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
116LogIt "hack-lilo --- starting"
117
118bootlistfile=/tmp/partitions-to-make-bootable.txt
119> $bootlistfile
120
121if [ "$#" -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
125fi
126
127old_mountlist=$1
128old_fstab=$2
129old_lilo=$3
130new_mountlist=$4
131new_fstab=$5
132outfile=$6
133
134> $outfile
135ProcessLilo < $old_lilo >> $outfile
136chmod 600 $outfile
137cat $bootlistfile | sort | uniq > $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
142LogIt "hack-lilo --- leaving"
143exit 0
Note: See TracBrowser for help on using the repository browser.