source: MondoRescue/trunk/mondo/mondo/restore-scripts/mondo/stabraw-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: 3.6 KB
Line 
1#!/bin/sh
2#
3# stabraw-me
4#
5# forked from stablilo-me on 2002/11/21
6#
7#####################################################################
8
9
10LOGFILE=/tmp/mondo-restore.log
11
12QuitIfNotFound() {
13 if [ ! -f "$1" ] ; then
14 LogIt "(stabraw-me) Where's $1? I cannot continue." 1
15 exit 1
16 fi
17}
18
19
20
21
22
23LocateOldFstab() {
24 old_fstab=""
25 if [ -f "/mnt/RESTORING/etc/fstab" ] ; then
26 LogIt "No need for fstab search." 2
27 old_fstab=/mnt/RESTORING/etc/fstab
28 return 0
29 elif [ -f "/mnt/cdrom/archives/CUCKOO" ] ; then
30 LogIt "Because I'm cuckoo, I'll stop searching." 2
31 return 1
32 else
33 LogIt "Looking for fstab. Please wait." 2
34 fstab_list=`find /mnt/RESTORING -name fstab 2> /dev/null`
35 fi
36 where_they_live=""
37 for curr_fstab in $fstab_list ; do
38 curr_dir=`echo $curr_fstab | gawk '{i=index($0,"/fstab");print substr($0,0,i-1);}'`
39 resA=$?
40 curr_inetd=`find $curr_dir -name inetd.conf | grep -v "linuxconf"`
41 resB=$?
42 if [ "$resA" -eq "0" ] ; then
43 if [ "$where_they_live" != "" ] ; then
44 LogIt "Two directories found! One is $where_they_live, the other $curr_dir" 1
45 LogIt "I don't know which to choose. I'll abort the search." 1
46 return 1
47 fi
48 where_they_live=$curr_dir
49 fi
50 done
51 if [ "$where_they_live" = "" ] ; then
52 LogIt "Cannot find any folder which holds fstab _and_ inetd.conf" 1
53 return 1
54 fi
55 old_fstab=$where_they_live/fstab
56 LogIt "fstab found." 2
57 return 0
58}
59
60
61
62MakeBackups() {
63 LogIt "Backing up original files before modifying them..." 2
64 for i in $old_fstab ; do
65 LogIt "Backing up $i"
66 [ -e "$i" ] && [ ! -e "$i.prehack" ] && cp -f $i $i.prehack
67 done
68}
69
70
71RestoreBackups() {
72 LogIt "Restoring original versions of modified files..." 2
73 cp -f $old_fstab /tmp/fstab.ugly
74 for i in $old_fstab ; do
75 LogIt "Restoring $i"
76 [ -f "$i.prehack" ] && cp $i.prehack $i -f
77 done
78}
79
80
81# --------------------------------- main -------------------------------
82
83if [ "$#" -ne "1" ] ; then
84 LogIt "stabraw-me </dev/bootdrive>"
85 exit 1
86fi
87
88bootdrive=$1
89
90LogIt "stabraw-me --- starting"
91LocateOldFstab
92old_mountlist=/tmp/mountlist.original
93new_mountlist=/tmp/mountlist.txt
94QuitIfNotFound $old_mountlist
95QuitIfNotFound $new_mountlist
96QuitIfNotFound $old_fstab
97LogIt "OK so far: I've found all the files I need." 2
98
99MakeBackups
100
101new_fstab=/tmp/fstab.new
102[ ! -e "$new_fstab" ] && new_fstab=/tmp/fstab
103
104LogIt "Modifying fstab..." 2
105outval=0
106hack-fstab $old_mountlist $old_fstab $new_mountlist $new_fstab
107res=$?
108if [ "$res" -ne "0" ] ; then
109 echo "Warning - hack-fstab failed"
110 outval=$(($outval+$res))
111fi
112
113if [ "$outval" -ne "0" ] ; then
114 LogIt "Fstab modifications failed" 3
115 RestoreBackups
116else
117 LogIt "Modifications succeeded." 2
118 LogIt "Copying over $old_fstab" 2
119 cp -f $new_fstab $old_fstab
120 outval=$(($outval+$?))
121 if [ "$outval" -ne "0" ] ; then
122 LogIt "Modifications (copying) failed. Restoring from backups." 3
123 RestoreBackups
124 else
125 LogIt "Fstab modified ok." 2
126 fi
127 cd $where_they_live
128 cd ..
129 raw-MR $bootdrive
130 mbr_res=$?
131 if [ "$mbr_res" -ne "0" ] ; then
132 LogIt "MBR failed to be installed." 3
133 else
134 LogIt "MBR installed ok." 2
135 fi
136fi
137
138if [ "$outval" -ne "0" ] ; then
139 LogIt "Error(s) occurred during mbr/fstab processing. "
140 LogIt "Restoring originals. "
141 RestoreBackups
142elif [ "$mbr_res" -ne "0" ] ; then
143 LogIt "Fstab was modified OK but mbr failed to be installed. "
144 outval=$(($outval+1))
145else
146 LogIt "/etc/fstab was modified ok; mbr was installed ok, too. "
147fi
148LogIt "stabraw-me --- leaving"
149echo -en "\n\n\n"
150exit $outval
151
152
153
154
155
Note: See TracBrowser for help on using the repository browser.