1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | #
|
---|
4 | # 2003/04/09
|
---|
5 | # - changed new_* paths from /tmp to /mnt/RESTORING/etc
|
---|
6 | #
|
---|
7 | #
|
---|
8 | # created in mid-2002?
|
---|
9 | ######################################################################
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 | QuitIfNotFound() {
|
---|
14 | if [ ! -f "$1" ] ; then
|
---|
15 | LogIt "(stablilo-me) Where's $1? I cannot continue." 1
|
---|
16 | exit 1
|
---|
17 | fi
|
---|
18 | }
|
---|
19 |
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 | FindLiloDir() {
|
---|
24 | list=`find / | grep -name lilo.conf`
|
---|
25 | }
|
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 | LocateOldFstab() {
|
---|
30 | old_fstab=""
|
---|
31 | old_liloconf=""
|
---|
32 | if [ -f "/mnt/RESTORING/etc/fstab" ] ; then
|
---|
33 | LogIt "No need for fstab search." 2
|
---|
34 | # fstab_list=/mnt/RESTORING/etc/fstab
|
---|
35 | old_fstab=/mnt/RESTORING/etc/fstab
|
---|
36 | old_liloconf=/mnt/RESTORING/etc/lilo.conf
|
---|
37 | return 0
|
---|
38 | elif [ -f "/mnt/cdrom/archives/CUCKOO" ] ; then
|
---|
39 | LogIt "Because I'm cuckoo, I'll stop searching." 2
|
---|
40 | return 1
|
---|
41 | else
|
---|
42 | LogIt "Looking for fstab. Please wait." 2
|
---|
43 | fstab_list=`find /mnt/RESTORING -name fstab 2> /dev/null`
|
---|
44 | fi
|
---|
45 | where_they_live=""
|
---|
46 | for curr_fstab in $fstab_list ; do
|
---|
47 | curr_dir=`echo $curr_fstab | gawk '{i=index($0,"/fstab");print substr($0,0,i-1);}'`
|
---|
48 | resA=$?
|
---|
49 | curr_inetd=`find $curr_dir -name inetd.conf | grep -v "linuxconf"`
|
---|
50 | resB=$?
|
---|
51 | if [ "$resA" -eq "0" ] ; then
|
---|
52 | if [ "$where_they_live" != "" ] ; then
|
---|
53 | LogIt "Two directories found! One is $where_they_live, the other $curr_dir" 1
|
---|
54 | LogIt "I don't know which to choose. I'll abort the search." 1
|
---|
55 | return 1
|
---|
56 | fi
|
---|
57 | where_they_live=$curr_dir
|
---|
58 | fi
|
---|
59 | done
|
---|
60 | if [ "$where_they_live" = "" ] ; then
|
---|
61 | LogIt "Cannot find any folder which holds fstab _and_ inetd.conf" 1
|
---|
62 | return 1
|
---|
63 | fi
|
---|
64 | old_liloconf=$where_they_live/lilo.conf
|
---|
65 | old_fstab=$where_they_live/fstab
|
---|
66 | LogIt "LILO and fstab found." 2
|
---|
67 | return 0
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 |
|
---|
72 | MakeBackups() {
|
---|
73 | LogIt "Backing up original files before modifying them..." 2
|
---|
74 | for i in $old_liloconf $old_fstab ; do
|
---|
75 | LogIt "Backing up $i"
|
---|
76 | [ -f "$i" ] && cp $i $i.prehack -f
|
---|
77 | done
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | RestoreBackups() {
|
---|
82 | LogIt "Restoring original versions of modified files..." 2
|
---|
83 | cp -f $old_liloconf /tmp/lilo.conf.ugly
|
---|
84 | cp -f $old_fstab /tmp/fstab.ugly
|
---|
85 | for i in $old_liloconf $old_fstab ; do
|
---|
86 | LogIt "Restoring $i"
|
---|
87 | [ -f "$i.prehack" ] && cp $i.prehack $i -f
|
---|
88 | done
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | WhatIsFirstDriveCalled() {
|
---|
93 | cut -d' ' -f1 /tmp/mountlist.txt \
|
---|
94 | | sed s/[0-9]// | sed s/[0-9]// \
|
---|
95 | | sort -u | head -n 1
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | # --------------------------------- main -------------------------------
|
---|
100 |
|
---|
101 | LogIt "stablilo-me --- starting"
|
---|
102 | LocateOldFstab
|
---|
103 | old_mountlist=/tmp/mountlist.original
|
---|
104 | new_mountlist=/tmp/mountlist.txt
|
---|
105 | QuitIfNotFound $old_mountlist
|
---|
106 | QuitIfNotFound $new_mountlist
|
---|
107 | QuitIfNotFound $old_fstab
|
---|
108 | QuitIfNotFound $old_liloconf
|
---|
109 | LogIt "OK so far: I've found all the files I need." 2
|
---|
110 |
|
---|
111 | MakeBackups
|
---|
112 |
|
---|
113 | new_fstab=/mnt/RESTORING/etc/fstab.NEW
|
---|
114 | [ ! -e "$new_fstab" ] && new_fstab=/mnt/RESTORING/etc/fstab
|
---|
115 | new_liloconf=/mnt/RESTORING/etc/lilo.conf.NEW
|
---|
116 | [ ! -e "$new_liloconf" ] && new_liloconf=/mnt/RESTORING/etc/lilo.conf
|
---|
117 |
|
---|
118 | LogIt "Modifying fstab..." 2
|
---|
119 | outval=0
|
---|
120 | hack-fstab $old_mountlist $old_fstab $new_mountlist $new_fstab
|
---|
121 | res=$?
|
---|
122 | if [ "$res" -ne "0" ] ; then
|
---|
123 | echo "Warning - hack-fstab failed"
|
---|
124 | outval=$(($outval+$res))
|
---|
125 | fi
|
---|
126 |
|
---|
127 | LogIt "Modifying lilo.conf. Please wait..." 2
|
---|
128 | hack-lilo $old_mountlist $old_fstab $old_liloconf $new_mountlist $new_fstab $new_liloconf
|
---|
129 | res=$?
|
---|
130 | outval=$(($outval+$res))
|
---|
131 | if [ "$outval" -ne "0" ] ; then
|
---|
132 | LogIt "Fstab and/or lilo modifications failed" 3
|
---|
133 | # RestoreBackups
|
---|
134 | else
|
---|
135 | LogIt "Modifications succeeded." 2
|
---|
136 | LogIt "Copying over $old_fstab" 2
|
---|
137 | cp -f $new_fstab $old_fstab
|
---|
138 | outval=$(($outval+$?))
|
---|
139 | LogIt "Copying over $old_liloconf" 2
|
---|
140 | cp -f $new_liloconf $old_liloconf
|
---|
141 | outval=$(($outval+$?))
|
---|
142 | if [ "$outval" -ne "0" ] ; then
|
---|
143 | LogIt "Modifications (copying) failed. Restoring from backups." 3
|
---|
144 | RestoreBackups
|
---|
145 | else
|
---|
146 | LogIt "Fstab and lilo files modified ok." 2
|
---|
147 | fi
|
---|
148 | cd $where_they_live
|
---|
149 | cd ..
|
---|
150 | LogIt "Running lilo from `pwd`" 2
|
---|
151 | cd /mnt/RESTORING
|
---|
152 | lilo -r `pwd` 2> /tmp/lilo.log.mondo
|
---|
153 | if [ "$?" -ne "0" ] ; then
|
---|
154 | lilo -L -r `pwd` 2> /tmp/lilo.log.mondo
|
---|
155 | fi
|
---|
156 | if [ "$?" -ne "0" ] ; then
|
---|
157 | LogIt "LILO failed." 3
|
---|
158 | cat /tmp/lilo.log.mondo
|
---|
159 | outval=$(($outval+1))
|
---|
160 | else
|
---|
161 | LogIt "LILO ran ok." 2
|
---|
162 | fi
|
---|
163 | fi
|
---|
164 |
|
---|
165 | if [ "$outval" -ne "0" ] ; then
|
---|
166 | LogIt "Error(s) occurred during lilo/fstab processing." 3
|
---|
167 | LogIt "Restoring originals." 3
|
---|
168 | RestoreBackups
|
---|
169 | else
|
---|
170 | LogIt "/etc/fstab and /etc/lilo.conf were modified ok. LILO ran ok." 3
|
---|
171 | fi
|
---|
172 | LogIt "stablilo-me --- leaving"
|
---|
173 | exit $outval
|
---|
174 |
|
---|
175 |
|
---|