source: trunk/mondo/mondo/restore-scripts/mondo/stablilo-me @ 274

Last change on this file since 274 was 274, checked in by bcornec, 13 years ago

merge -r272:273 $SVN_M/branches/2.06

  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
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
13QuitIfNotFound() {
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
23FindLiloDir() {
24    list=`find / | grep -name lilo.conf`
25}
26
27
28
29LocateOldFstab() {
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
72MakeBackups() {
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
81RestoreBackups() {
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
92WhatIsFirstDriveCalled() {
93    cut -d' ' -f1 /tmp/mountlist.txt \
94| sed s/[0-9]// | sed s/[0-9]// \
95| sort | uniq | head -n 1
96}
97
98
99# --------------------------------- main -------------------------------
100
101LogIt "stablilo-me --- starting"
102LocateOldFstab
103old_mountlist=/tmp/mountlist.original
104new_mountlist=/tmp/mountlist.txt
105QuitIfNotFound $old_mountlist
106QuitIfNotFound $new_mountlist
107QuitIfNotFound $old_fstab
108QuitIfNotFound $old_liloconf
109LogIt "OK so far: I've found all the files I need." 2
110
111MakeBackups
112
113new_fstab=/mnt/RESTORING/etc/fstab.NEW
114[ ! -e "$new_fstab" ] && new_fstab=/mnt/RESTORING/etc/fstab
115new_liloconf=/mnt/RESTORING/etc/lilo.conf.NEW
116[ ! -e "$new_liloconf" ] && new_liloconf=/mnt/RESTORING/etc/lilo.conf
117
118LogIt "Modifying fstab..." 2
119outval=0
120hack-fstab $old_mountlist $old_fstab $new_mountlist $new_fstab
121res=$?
122if [ "$res" -ne "0" ] ; then
123    echo "Warning - hack-fstab failed"
124    outval=$(($outval+$res))
125fi
126   
127LogIt "Modifying lilo.conf. Please wait..." 2
128hack-lilo $old_mountlist $old_fstab $old_liloconf $new_mountlist $new_fstab $new_liloconf
129res=$?
130outval=$(($outval+$res))
131if [ "$outval" -ne "0" ] ; then
132    LogIt "Fstab and/or lilo modifications failed" 3
133#    RestoreBackups
134else
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
163fi
164
165if [ "$outval" -ne "0" ] ; then
166    LogIt "Error(s) occurred during lilo/fstab processing." 3
167    LogIt "Restoring originals." 3
168    RestoreBackups
169else
170    LogIt "/etc/fstab and /etc/lilo.conf were modified ok. LILO ran ok." 3
171fi
172LogIt "stablilo-me --- leaving"
173exit $outval
174
175
Note: See TracBrowser for help on using the repository browser.