1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # stabraw-me
|
---|
4 | #
|
---|
5 | # forked from stablilo-me on 2002/11/21
|
---|
6 | #
|
---|
7 | #####################################################################
|
---|
8 |
|
---|
9 |
|
---|
10 | LOGFILE=/tmp/mondo-restore.log
|
---|
11 |
|
---|
12 | QuitIfNotFound() {
|
---|
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 |
|
---|
23 | LocateOldFstab() {
|
---|
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 |
|
---|
62 | MakeBackups() {
|
---|
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 |
|
---|
71 | RestoreBackups() {
|
---|
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 |
|
---|
83 | if [ "$#" -ne "1" ] ; then
|
---|
84 | LogIt "stabraw-me </dev/bootdrive>"
|
---|
85 | exit 1
|
---|
86 | fi
|
---|
87 |
|
---|
88 | bootdrive=$1
|
---|
89 |
|
---|
90 | LogIt "stabraw-me --- starting"
|
---|
91 | LocateOldFstab
|
---|
92 | old_mountlist=/tmp/mountlist.original
|
---|
93 | new_mountlist=/tmp/mountlist.txt
|
---|
94 | QuitIfNotFound $old_mountlist
|
---|
95 | QuitIfNotFound $new_mountlist
|
---|
96 | QuitIfNotFound $old_fstab
|
---|
97 | LogIt "OK so far: I've found all the files I need." 2
|
---|
98 |
|
---|
99 | MakeBackups
|
---|
100 |
|
---|
101 | new_fstab=/tmp/fstab.new
|
---|
102 | [ ! -e "$new_fstab" ] && new_fstab=/tmp/fstab
|
---|
103 |
|
---|
104 | LogIt "Modifying fstab..." 2
|
---|
105 | outval=0
|
---|
106 | hack-fstab $old_mountlist $old_fstab $new_mountlist $new_fstab
|
---|
107 | res=$?
|
---|
108 | if [ "$res" -ne "0" ] ; then
|
---|
109 | echo "Warning - hack-fstab failed"
|
---|
110 | outval=$(($outval+$res))
|
---|
111 | fi
|
---|
112 |
|
---|
113 | if [ "$outval" -ne "0" ] ; then
|
---|
114 | LogIt "Fstab modifications failed" 3
|
---|
115 | RestoreBackups
|
---|
116 | else
|
---|
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
|
---|
136 | fi
|
---|
137 |
|
---|
138 | if [ "$outval" -ne "0" ] ; then
|
---|
139 | LogIt "Error(s) occurred during mbr/fstab processing. "
|
---|
140 | LogIt "Restoring originals. "
|
---|
141 | RestoreBackups
|
---|
142 | elif [ "$mbr_res" -ne "0" ] ; then
|
---|
143 | LogIt "Fstab was modified OK but mbr failed to be installed. "
|
---|
144 | outval=$(($outval+1))
|
---|
145 | else
|
---|
146 | LogIt "/etc/fstab was modified ok; mbr was installed ok, too. "
|
---|
147 | fi
|
---|
148 | LogIt "stabraw-me --- leaving"
|
---|
149 | echo -en "\n\n\n"
|
---|
150 | exit $outval
|
---|
151 |
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 |
|
---|