source: MondoRescue/branches/3.2/mondo/src/restore-scripts/mondo/mr-stabelilo-me@ 3542

Last change on this file since 3542 was 3542, checked in by Bruno Cornec, 8 years ago
  • Rename all mondorestore scripts with the mr- prefix and adapt callers
  • Place these scripts in /usr/bin on the restore media
  • Fix a mindi bug where these scripts were not copied anymore with previous modifications around removal of cd
  • Property svn:keywords set to Id
  • Property svn:unix-mode set to 755
File size: 5.5 KB
Line 
1#!/bin/sh
2#
3# 2004-03-08: First draft Bruno Cornec <bruno@mondorescue.org>
4#
5
6QuitIfNotFound() {
7 if [ ! -f "$1" ] ; then
8 LogIt "(mr-stabelilo-me) Where's $1? I cannot continue." 1
9 exit 1
10 fi
11}
12
13
14
15
16FindLiloDir() {
17 list=`find / | grep -name elilo.conf`
18}
19
20
21
22LocateOldElilo() {
23 old_eliloconf=""
24 if [ -f "/mnt/RESTORING/boot/efi/efi/redhat/elilo.conf" ] ; then
25 LogIt "elilo.conf found at /mnt/RESTORING/boot/efi/efi/redhat/elilo.conf" 2
26 old_eliloconf="/mnt/RESTORING/boot/efi/efi/redhat/elilo.conf"
27 return 0
28 elif [ -f "/mnt/RESTORING/boot/efi/efi/SuSE/elilo.conf" ] ; then
29 LogIt "elilo.conf found at /mnt/RESTORING/boot/efi/efi/SuSE/elilo.conf" 2
30 old_eliloconf="/mnt/RESTORING/boot/efi/efi/SuSE/elilo.conf"
31 return 0
32 elif [ -f "/mnt/RESTORING/boot/efi/efi/debian/elilo.conf" ] ; then
33 LogIt "elilo.conf found at /mnt/RESTORING/boot/efi/efi/debian/elilo.conf" 2
34 old_eliloconf="/mnt/RESTORING/boot/efi/efi/debian/elilo.conf"
35 return 0
36 elif [ -f "/mnt/RESTORING/boot/efi/debian/elilo.conf" ] ; then
37 LogIt "elilo.conf found at /mnt/RESTORING/boot/efi/debian/elilo.conf" 2
38 old_eliloconf="/mnt/RESTORING/boot/efi/debian/elilo.conf"
39 return 0
40 else
41 LogIt "Looking for elilo.conf. Please wait." 2
42 elilo_list=`find /mnt/RESTORING/boot -name elilo.conf 2> /dev/null`
43 fi
44 where_they_live=""
45 for curr_elilo in $elilo_list ; do
46 curr_dir=`dirname $curr_elilo`
47 if [ "$?" -eq "0" ] ; then
48 if [ "$where_they_live" != "" ] ; then
49 LogIt "Two directories found! One is $where_they_live, the other $curr_dir" 1
50 LogIt "I don't know which to choose. I'll abort the search." 1
51 return 1
52 fi
53 where_they_live=$curr_dir
54 fi
55 done
56 if [ "$where_they_live" = "" ] ; then
57 LogIt "Cannot find any folder which holds elilo.conf" 1
58 return 1
59 fi
60 old_eliloconf=$where_they_live/elilo.conf
61 LogIt "ELILO found." 2
62 return 0
63}
64
65LocateOldFstab() {
66 old_fstab=""
67 if [ -f "/mnt/RESTORING/etc/fstab" ] ; then
68 LogIt "No need for fstab search." 2
69 old_fstab=/mnt/RESTORING/etc/fstab
70 return 0
71 elif [ -f "/mnt/cdrom/archives/CUCKOO" ] ; then
72 LogIt "Because I'm cuckoo, I'll stop searching." 2
73 return 1
74 else
75 LogIt "Looking for fstab. Please wait." 2
76 fstab_list=`find /mnt/RESTORING -name fstab 2> /dev/null`
77 fi
78 where_they_live=""
79 for curr_fstab in $fstab_list ; do
80 curr_dir=`echo $curr_fstab | gawk '{i=index($0,"/fstab");print substr($0,0,i-1);}'`
81 resA=$?
82 curr_inetd=`find $curr_dir -name inetd.conf | grep -v "linuxconf"`
83 resB=$?
84 if [ "$resA" -eq "0" ] ; then
85 if [ "$where_they_live" != "" ] ; then
86 LogIt "Two directories found! One is $where_they_live, the other $curr_dir" 1
87 LogIt "I don't know which to choose. I'll abort the search." 1
88 return 1
89 fi
90 where_they_live=$curr_dir
91 fi
92 done
93 if [ "$where_they_live" = "" ] ; then
94 LogIt "Cannot find any folder which holds fstab _and_ inetd.conf" 1
95 return 1
96 fi
97 old_fstab=$where_they_live/fstab
98 LogIt "fstab found." 2
99 return 0
100}
101
102
103MakeBackups() {
104 LogIt "Backing up original files before modifying them..." 2
105 for i in $old_eliloconf $old_fstab ; do
106 LogIt "Backing up $i"
107 [ -f "$i" ] && cp $i $i.prehack -f
108 done
109}
110
111
112RestoreBackups() {
113 LogIt "Restoring original versions of modified files..." 2
114 cp -f $old_eliloconf /tmp/elilo.conf.ugly
115 cp -f $old_fstab /tmp/fstab.ugly
116 for i in $old_eliloconf $old_fstab ; do
117 LogIt "Restoring $i"
118 [ -f "$i.prehack" ] && cp $i.prehack $i -f
119 done
120}
121
122
123WhatIsFirstDriveCalled() {
124 cut -d' ' -f1 /tmp/mountlist.txt \
125| sed s/[0-9]// | sed s/[0-9]// \
126| sort -u | head -n 1
127}
128
129
130# --------------------------------- main -------------------------------
131
132LogIt "mr-stabelilo-me --- starting"
133LocateOldFstab
134LocateOldElilo
135old_mountlist=/tmp/mountlist.original
136new_mountlist=/tmp/mountlist.txt
137QuitIfNotFound $old_mountlist
138QuitIfNotFound $new_mountlist
139QuitIfNotFound $old_fstab
140QuitIfNotFound $old_eliloconf
141LogIt "OK so far: I've found all the files I need." 2
142
143MakeBackups
144
145new_fstab=/mnt/RESTORING/etc/fstab.NEW
146[ ! -e "$new_fstab" ] && new_fstab=/mnt/RESTORING/etc/fstab
147new_eliloconf=/mnt/RESTORING/etc/elilo.conf.NEW
148[ ! -e "$new_eliloconf" ] && new_eliloconf=/mnt/RESTORING/etc/elilo.conf
149
150LogIt "Modifying fstab..." 2
151outval=0
152mr-hack-fstab $old_mountlist $old_fstab $new_mountlist $new_fstab
153res=$?
154if [ "$res" -ne "0" ] ; then
155 echo "Warning - mr-hack-fstab failed"
156 outval=$(($outval+$res))
157fi
158
159LogIt "Modifying elilo.conf. Please wait..." 2
160mr-hack-elilo $old_mountlist $old_fstab $old_liloconf $new_mountlist $new_fstab $new_liloconf
161res=$?
162outval=$(($outval+$res))
163if [ "$outval" -ne "0" ] ; then
164 LogIt "Fstab and/or elilo modifications failed" 3
165# RestoreBackups
166else
167 LogIt "Modifications succeeded." 2
168 LogIt "Copying over $old_fstab" 2
169 cp -f $new_fstab $old_fstab
170 outval=$(($outval+$?))
171 LogIt "Copying over $old_eliloconf" 2
172 cp -f $new_liloconf $old_eliloconf
173 outval=$(($outval+$?))
174 if [ "$outval" -ne "0" ] ; then
175 LogIt "Modifications (copying) failed. Restoring from backups." 3
176 RestoreBackups
177 else
178 LogIt "Fstab and elilo files modified ok." 2
179 fi
180 cd $where_they_live
181 cd ..
182fi
183
184if [ "$outval" -ne "0" ] ; then
185 LogIt "Error(s) occurred during elilo/fstab processing." 3
186 LogIt "Restoring originals." 3
187 RestoreBackups
188else
189 LogIt "/etc/fstab and /etc/elilo.conf were modified ok." 3
190fi
191LogIt "mr-stabelilo-me --- leaving"
192exit $outval
193
194
Note: See TracBrowser for help on using the repository browser.