source: trunk/mondo/mondo/restore-scripts/mondo/stabelilo-me @ 1

Last change on this file since 1 was 1, checked in by bcornec, 14 years ago

Initial import from latest mondo-2.04_cvs_20050503/mindi-1.04_cvs_20050503 on http://www.mondorescue.org

File size: 4.0 KB
Line 
1#!/bin/sh
2#
3# 2004-03-08: First draft Bruno Cornec <Bruno.Cornec@hp.com>
4#
5
6QuitIfNotFound() {
7    if [ ! -f "$1" ] ; then
8    LogIt "(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
22LocateOldFstab() {
23    old_fstab=""
24    old_eliloconf=""
25    if [ -f "/mnt/RESTORING/etc/fstab" ] ; then
26        LogIt "No need for fstab search." 2
27#        fstab_list=/mnt/RESTORING/etc/fstab
28    old_fstab=/mnt/RESTORING/etc/fstab
29    old_eliloconf=/mnt/RESTORING/boot/efi/efi/redhat/elilo.conf
30    return 0
31    elif [ -f "/mnt/cdrom/archives/CUCKOO" ] ; then
32        LogIt "Because I'm cuckoo, I'll stop searching." 2
33        return 1
34    else
35        LogIt "Looking for fstab. Please wait." 2
36        fstab_list=`find /mnt/RESTORING -name fstab 2> /dev/null`
37    fi
38    where_they_live=""
39    for curr_fstab in $fstab_list ; do
40    curr_dir=`echo $curr_fstab | gawk '{i=index($0,"/fstab");print substr($0,0,i-1);}'`
41    resA=$?
42    curr_inetd=`find $curr_dir -name inetd.conf | grep -v "linuxconf"`
43    resB=$?
44    if [ "$resA" -eq "0" ] ; then
45        if [ "$where_they_live" != "" ] ; then
46        LogIt "Two directories found! One is $where_they_live, the other $curr_dir" 1
47        LogIt "I don't know which to choose. I'll abort the search." 1
48        return 1
49        fi
50        where_they_live=$curr_dir
51    fi
52    done
53    if [ "$where_they_live" = "" ] ; then
54    LogIt "Cannot find any folder which holds fstab _and_ inetd.conf" 1
55    return 1
56    fi
57    ### Will NOT work for ELILO
58    ###old_eliloconf=$where_they_live/elilo.conf
59    old_eliloconf=/boot/efi/efi/redhat/elilo.conf
60    old_fstab=$where_they_live/fstab
61    LogIt "LILO and fstab found." 2
62    return 0
63}
64
65
66
67MakeBackups() {
68    LogIt "Backing up original files before modifying them..." 2
69    for i in $old_eliloconf $old_fstab ; do
70    LogIt "Backing up $i"
71        [ -f "$i" ] && cp $i $i.prehack -f
72    done
73}
74
75
76RestoreBackups() {
77    LogIt "Restoring original versions of modified files..." 2
78    cp -f $old_eliloconf /tmp/elilo.conf.ugly
79    cp -f $old_fstab /tmp/fstab.ugly
80    for i in $old_eliloconf $old_fstab ; do
81    LogIt "Restoring $i"
82    [ -f "$i.prehack" ] && cp $i.prehack $i -f
83    done
84}
85
86
87WhatIsFirstDriveCalled() {
88    cat /tmp/mountlist.txt | cut -d' ' -f1 \
89| sed s/[0-9]// | sed s/[0-9]// \
90| sort | uniq | head -n 1
91}
92
93
94# --------------------------------- main -------------------------------
95
96LogIt "stabelilo-me --- starting"
97LocateOldFstab
98old_mountlist=/tmp/mountlist.original
99new_mountlist=/tmp/mountlist.txt
100QuitIfNotFound $old_mountlist
101QuitIfNotFound $new_mountlist
102QuitIfNotFound $old_fstab
103QuitIfNotFound $old_eliloconf
104LogIt "OK so far: I've found all the files I need." 2
105
106MakeBackups
107
108new_fstab=/mnt/RESTORING/etc/fstab.NEW
109[ ! -e "$new_fstab" ] && new_fstab=/mnt/RESTORING/etc/fstab
110new_eliloconf=/mnt/RESTORING/etc/elilo.conf.NEW
111[ ! -e "$new_eliloconf" ] && new_eliloconf=/mnt/RESTORING/etc/elilo.conf
112
113LogIt "Modifying fstab..." 2
114outval=0
115hack-fstab $old_mountlist $old_fstab $new_mountlist $new_fstab
116res=$?
117if [ "$res" -ne "0" ] ; then
118    echo "Warning - hack-fstab failed"
119    outval=$(($outval+$res))
120fi
121   
122LogIt "Modifying elilo.conf. Please wait..." 2
123hack-elilo $old_mountlist $old_fstab $old_liloconf $new_mountlist $new_fstab $new_liloconf
124res=$?
125outval=$(($outval+$res))
126if [ "$outval" -ne "0" ] ; then
127    LogIt "Fstab and/or elilo modifications failed" 3
128#    RestoreBackups
129else
130    LogIt "Modifications succeeded." 2
131    LogIt "Copying over $old_fstab" 2
132    cp -f $new_fstab $old_fstab
133    outval=$(($outval+$?))
134    LogIt "Copying over $old_eliloconf" 2
135    cp -f $new_liloconf $old_eliloconf
136    outval=$(($outval+$?))
137    if [ "$outval" -ne "0" ] ; then
138    LogIt "Modifications (copying) failed. Restoring from backups." 3
139    RestoreBackups
140    else
141    LogIt "Fstab and elilo files modified ok." 2
142    fi
143    cd $where_they_live
144    cd ..
145fi
146
147if [ "$outval" -ne "0" ] ; then
148    LogIt "Error(s) occurred during elilo/fstab processing." 3
149    LogIt "Restoring originals." 3
150    RestoreBackups
151else
152    LogIt "/etc/fstab and /etc/elilo.conf were modified ok." 3
153fi
154LogIt "stabelilo-me --- leaving"
155exit $outval
156
157
Note: See TracBrowser for help on using the repository browser.