1 | #!/bin/sh |
---|
2 | # |
---|
3 | # 2004-03-08: First draft Bruno Cornec <Bruno.Cornec@hp.com> |
---|
4 | # |
---|
5 | |
---|
6 | QuitIfNotFound() { |
---|
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 | |
---|
16 | FindLiloDir() { |
---|
17 | list=`find / | grep -name elilo.conf` |
---|
18 | } |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | LocateOldFstab() { |
---|
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 | |
---|
67 | MakeBackups() { |
---|
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 | |
---|
76 | RestoreBackups() { |
---|
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 | |
---|
87 | WhatIsFirstDriveCalled() { |
---|
88 | cut -d' ' -f1 /tmp/mountlist.txt \ |
---|
89 | | sed s/[0-9]// | sed s/[0-9]// \ |
---|
90 | | sort -u | head -n 1 |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | # --------------------------------- main ------------------------------- |
---|
95 | |
---|
96 | LogIt "stabelilo-me --- starting" |
---|
97 | LocateOldFstab |
---|
98 | old_mountlist=/tmp/mountlist.original |
---|
99 | new_mountlist=/tmp/mountlist.txt |
---|
100 | QuitIfNotFound $old_mountlist |
---|
101 | QuitIfNotFound $new_mountlist |
---|
102 | QuitIfNotFound $old_fstab |
---|
103 | QuitIfNotFound $old_eliloconf |
---|
104 | LogIt "OK so far: I've found all the files I need." 2 |
---|
105 | |
---|
106 | MakeBackups |
---|
107 | |
---|
108 | new_fstab=/mnt/RESTORING/etc/fstab.NEW |
---|
109 | [ ! -e "$new_fstab" ] && new_fstab=/mnt/RESTORING/etc/fstab |
---|
110 | new_eliloconf=/mnt/RESTORING/etc/elilo.conf.NEW |
---|
111 | [ ! -e "$new_eliloconf" ] && new_eliloconf=/mnt/RESTORING/etc/elilo.conf |
---|
112 | |
---|
113 | LogIt "Modifying fstab..." 2 |
---|
114 | outval=0 |
---|
115 | hack-fstab $old_mountlist $old_fstab $new_mountlist $new_fstab |
---|
116 | res=$? |
---|
117 | if [ "$res" -ne "0" ] ; then |
---|
118 | echo "Warning - hack-fstab failed" |
---|
119 | outval=$(($outval+$res)) |
---|
120 | fi |
---|
121 | |
---|
122 | LogIt "Modifying elilo.conf. Please wait..." 2 |
---|
123 | hack-elilo $old_mountlist $old_fstab $old_liloconf $new_mountlist $new_fstab $new_liloconf |
---|
124 | res=$? |
---|
125 | outval=$(($outval+$res)) |
---|
126 | if [ "$outval" -ne "0" ] ; then |
---|
127 | LogIt "Fstab and/or elilo modifications failed" 3 |
---|
128 | # RestoreBackups |
---|
129 | else |
---|
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 .. |
---|
145 | fi |
---|
146 | |
---|
147 | if [ "$outval" -ne "0" ] ; then |
---|
148 | LogIt "Error(s) occurred during elilo/fstab processing." 3 |
---|
149 | LogIt "Restoring originals." 3 |
---|
150 | RestoreBackups |
---|
151 | else |
---|
152 | LogIt "/etc/fstab and /etc/elilo.conf were modified ok." 3 |
---|
153 | fi |
---|
154 | LogIt "stabelilo-me --- leaving" |
---|
155 | exit $outval |
---|
156 | |
---|
157 | |
---|