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