1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # $Id: stabraw-me 1315 2007-04-16 14:13:59Z bruno $
|
---|
4 | #
|
---|
5 | #####################################################################
|
---|
6 |
|
---|
7 |
|
---|
8 | QuitIfNotFound() {
|
---|
9 | if [ ! -f "$1" ] ; then
|
---|
10 | LogIt "(stabraw-me) Where's $1? I cannot continue." 1
|
---|
11 | exit 1
|
---|
12 | fi
|
---|
13 | }
|
---|
14 |
|
---|
15 | LocateOldFstab() {
|
---|
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 |
|
---|
54 | MakeBackups() {
|
---|
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 |
|
---|
63 | RestoreBackups() {
|
---|
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 |
|
---|
75 | if [ "$#" -ne "1" ] ; then
|
---|
76 | LogIt "stabraw-me </dev/bootdrive>"
|
---|
77 | exit 1
|
---|
78 | fi
|
---|
79 |
|
---|
80 | bootdrive=$1
|
---|
81 |
|
---|
82 | LogIt "stabraw-me --- starting"
|
---|
83 | LocateOldFstab
|
---|
84 | old_mountlist=/tmp/mountlist.original
|
---|
85 | new_mountlist=/tmp/mountlist.txt
|
---|
86 | QuitIfNotFound $old_mountlist
|
---|
87 | QuitIfNotFound $new_mountlist
|
---|
88 | QuitIfNotFound $old_fstab
|
---|
89 | LogIt "OK so far: I've found all the files I need." 2
|
---|
90 |
|
---|
91 | MakeBackups
|
---|
92 |
|
---|
93 | new_fstab=/tmp/fstab.new
|
---|
94 | [ ! -e "$new_fstab" ] && new_fstab=/tmp/fstab
|
---|
95 |
|
---|
96 | LogIt "Modifying fstab..." 2
|
---|
97 | outval=0
|
---|
98 | hack-fstab $old_mountlist $old_fstab $new_mountlist $new_fstab
|
---|
99 | res=$?
|
---|
100 | if [ "$res" -ne "0" ] ; then
|
---|
101 | echo "Warning - hack-fstab failed"
|
---|
102 | outval=$(($outval+$res))
|
---|
103 | fi
|
---|
104 |
|
---|
105 | if [ "$outval" -ne "0" ] ; then
|
---|
106 | LogIt "Fstab modifications failed" 3
|
---|
107 | RestoreBackups
|
---|
108 | else
|
---|
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
|
---|
128 | fi
|
---|
129 |
|
---|
130 | if [ "$outval" -ne "0" ] ; then
|
---|
131 | LogIt "Error(s) occurred during mbr/fstab processing. "
|
---|
132 | LogIt "Restoring originals. "
|
---|
133 | RestoreBackups
|
---|
134 | elif [ "$mbr_res" -ne "0" ] ; then
|
---|
135 | LogIt "Fstab was modified OK but mbr failed to be installed. "
|
---|
136 | outval=$(($outval+1))
|
---|
137 | else
|
---|
138 | LogIt "/etc/fstab was modified ok; mbr was installed ok, too. "
|
---|
139 | fi
|
---|
140 | LogIt "stabraw-me --- leaving"
|
---|
141 | echo -en "\n\n\n"
|
---|
142 | exit $outval
|
---|
143 |
|
---|
144 |
|
---|
145 |
|
---|
146 |
|
---|
147 |
|
---|