source: branches/2.2.2/mondo/src/restore-scripts/mondo/stabgrub-me @ 1315

Last change on this file since 1315 was 1315, checked in by bruno, 12 years ago

Log files are now consistent: mondoarchive.log for mondoarchive (containing also mindi.log) and mondorestore.log for mondorestore (copied from /tmp (ram) to /var/log (disk) at the end of the restore)
One include has been created for each bianry containing only that declaration ofr the moment, but which will be extended to include all local definitions (ps_* e.g.)
Doc updated accordingly
LOGFILE in restore process is now passed in the environment and not duplicated anymore
LogIt? is not redifined either
LOGFILE should be put in environment by mondoarchive for mindi's usage but that's a step left for later.

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