source: MondoRescue/branches/stable/mondo/src/restore-scripts/mondo/stabraw-me@ 1341

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