source: MondoRescue/trunk/mondo/mondo/restore-scripts/mondo/stabgrub-me@ 588

Last change on this file since 588 was 588, checked in by bcornec, 18 years ago

merge -r 560:587 $SVN_M/branches/stable

  • Property svn:keywords set to Id
  • Property svn:unix-mode set to 755
File size: 4.8 KB
Line 
1#!/bin/sh
2#
3# stabgrub-me
4#
5# 04/08/2003
6# - cleaned up backup func a bit
7#
8#
9#
10# forked from stablilo-me on 2002/11/20
11#
12#####################################################################
13
14
15LOGFILE=/tmp/mondo-restore.log
16
17QuitIfNotFound() {
18 if [ ! -f "$1" ] ; then
19 LogIt "(stabgrub-me) Where's $1? I cannot continue." 1
20 exit 1
21 fi
22}
23
24
25
26
27
28LocateOldFstab() {
29 old_fstab=""
30 old_grubconf=""
31 if [ -f "/mnt/RESTORING/etc/fstab" ] ; then
32 LogIt "No need for fstab search." 2
33# fstab_list=/mnt/RESTORING/etc/fstab
34 old_fstab=/mnt/RESTORING/etc/fstab
35 old_grubconf=/mnt/RESTORING/etc/grub.conf
36 return 0
37 elif [ -f "/mnt/cdrom/archives/CUCKOO" ] ; then
38 LogIt "Because I'm cuckoo, I'll stop searching." 2
39 return 1
40 else
41 LogIt "Looking for fstab. Please wait." 2
42 fstab_list=`find /mnt/RESTORING -name fstab 2> /dev/null`
43 fi
44 where_they_live=""
45 for curr_fstab in $fstab_list ; do
46 curr_dir=`echo $curr_fstab | gawk '{i=index($0,"/fstab");print substr($0,0,i-1);}'`
47 resA=$?
48 curr_inetd=`find $curr_dir -name inetd.conf | grep -v "linuxconf"`
49 resB=$?
50 if [ "$resA" -eq "0" ] ; then
51 if [ "$where_they_live" != "" ] ; then
52 LogIt "Two directories found! One is $where_they_live, the other $curr_dir" 1
53 LogIt "I don't know which to choose. I'll abort the search." 1
54 return 1
55 fi
56 where_they_live=$curr_dir
57 fi
58 done
59 if [ "$where_they_live" = "" ] ; then
60 LogIt "Cannot find any folder which holds fstab _and_ inetd.conf" 1
61 return 1
62 fi
63 old_grubconf=$where_they_live/grub.conf
64 old_fstab=$where_they_live/fstab
65 LogIt "GRUB and fstab found." 2
66 return 0
67}
68
69
70BEFORE=stabgrub-me.PRE
71
72MakeBackups() {
73 local i
74 LogIt "Backing up original files before modifying them..." 2
75 for i in $old_grubconf $old_fstab ; do
76 LogIt "Backing up $i"
77 [ -e "$i" ] && [ ! -e "$i.$BEFORE" ] && cp -f $i $i.$BEFORE
78 done
79}
80
81
82RestoreBackups() {
83 LogIt "Restoring original versions of modified files..." 2
84 cp -f $old_grubconf /tmp/grub.conf.ugly
85 cp -f $old_fstab /tmp/fstab.ugly
86 for i in $old_grubconf $old_fstab ; do
87 LogIt "Restoring $i"
88 [ -f "$i.$BEFORE" ] && cp -f $i.$BEFORE $i
89 done
90}
91
92
93# --------------------------------- main -------------------------------
94
95if [ "$#" -ne "1" ] ; then
96 LogIt "stabgrub-me </dev/bootdrive>"
97 exit 1
98fi
99
100bootdrive=$1
101
102LogIt "stabgrub-me '$1' --- starting"
103LocateOldFstab
104old_mountlist=/tmp/mountlist.original
105new_mountlist=/tmp/mountlist.txt
106QuitIfNotFound $old_mountlist
107QuitIfNotFound $new_mountlist
108QuitIfNotFound $old_fstab
109QuitIfNotFound $old_grubconf
110LogIt "OK so far: I've found all the files I need." 2
111new_fstab=/mnt/RESTORING/etc/fstab.NEW
112new_grubconf=/mnt/RESTORING/etc/grub.conf.NEW
113# change back to /tmp if /mnt/RESTORING/etc be problematic
114
115MakeBackups
116
117LogIt "old_mountlist = $old_mountlist"
118LogIt "new_mountlist = $new_mountlist"
119LogIt "old_fstab = $old_fstab"
120LogIt "new_fstab = $new_fstab"
121LogIt "where_they_live = $where_they_live"
122
123LogIt "Calling hack-fstab $old_mountlist $old_fstab $new_mountlist $new_fstab"
124
125outval=0
126hack-fstab $old_mountlist $old_fstab $new_mountlist $new_fstab
127res=$?
128if [ "$res" -ne "0" ] ; then
129 LogIt "Warning - hack-fstab failed"
130 outval=$(($outval+$res))
131else
132 LogIt "Back from hack-fstab OK" 1
133fi
134
135if [ "$outval" -ne "0" ] ; then
136 LogIt "Fstab and/or grub modifications failed" 3
137 RestoreBackups
138else
139 LogIt "Modifications succeeded." 2
140 LogIt "Copying $new_fstab over $old_fstab" 2
141 cp -f $new_fstab $old_fstab
142 cp -f $new_fstab /tmp/fstab
143 outval=$(($outval+$?))
144 LogIt "Copying over $old_grubconf" 2
145 if [ -f "$new_grubconf" ] ; then
146 cp -f $new_grubconf $old_grubconf
147 outval=$(($outval+$?))
148 fi
149 if [ "$outval" -ne "0" ] ; then
150 LogIt "Modifications (copying) failed. Restoring from backups." 3
151 RestoreBackups
152 else
153 LogIt "Fstab modified ok." 2
154 fi
155 cd /mnt/RESTORING
156# cd $where_they_live
157# cd ..
158 LogIt "Running grub..." 2
159 LogIt "grub-MR $bootdrive $new_mountlist"
160 grub-MR $bootdrive $new_mountlist >> $LOGFILE 2>> $LOGFILE
161 grub_res=$?
162 if [ "$grub_res" -ne "0" ] ; then
163 LogIt "grub-install failed. Running grub-MR..."
164 chroot /mnt/RESTORING grub-install '(hd0)' >> $LOGFILE 2>> $LOGFILE
165 grub_res=$?
166 fi
167 if [ "$grub_res" -ne "0" ] ; then
168 LogIt "GRUB failed." 3
169 else
170 LogIt "GRUB ran ok." 2
171 fi
172fi
173
174if [ "$outval" -ne "0" ] ; then
175 LogIt "Error(s) occurred during grub/fstab processing. "
176 LogIt "Restoring originals. "
177 RestoreBackups
178elif [ "$grub_res" -ne "0" ] ; then
179 LogIt "Fstab was modified OK but grub failed to run. "
180 outval=$(($outval+1))
181else
182 LogIt "/etc/fstab was modified ok. GRUB ran ok. "
183fi
184LogIt "stabgrub-me --- leaving"
185echo -en "\n\n\n"
186exit $outval
Note: See TracBrowser for help on using the repository browser.