[1] | 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 |
|
---|
[1564] | 22 | LocateOldElilo() {
|
---|
| 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
|
---|
[1570] | 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
|
---|
[1564] | 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 |
|
---|
[1] | 65 | LocateOldFstab() {
|
---|
| 66 | old_fstab=""
|
---|
| 67 | if [ -f "/mnt/RESTORING/etc/fstab" ] ; then
|
---|
| 68 | LogIt "No need for fstab search." 2
|
---|
[1564] | 69 | old_fstab=/mnt/RESTORING/etc/fstab
|
---|
| 70 | return 0
|
---|
[1] | 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
|
---|
[1564] | 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
|
---|
[1] | 92 | done
|
---|
| 93 | if [ "$where_they_live" = "" ] ; then
|
---|
[1564] | 94 | LogIt "Cannot find any folder which holds fstab _and_ inetd.conf" 1
|
---|
| 95 | return 1
|
---|
[1] | 96 | fi
|
---|
| 97 | old_fstab=$where_they_live/fstab
|
---|
[1564] | 98 | LogIt "fstab found." 2
|
---|
[1] | 99 | return 0
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | MakeBackups() {
|
---|
| 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 |
|
---|
| 112 | RestoreBackups() {
|
---|
| 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 |
|
---|
| 123 | WhatIsFirstDriveCalled() {
|
---|
[275] | 124 | cut -d' ' -f1 /tmp/mountlist.txt \
|
---|
[1] | 125 | | sed s/[0-9]// | sed s/[0-9]// \
|
---|
[275] | 126 | | sort -u | head -n 1
|
---|
[1] | 127 | }
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | # --------------------------------- main -------------------------------
|
---|
| 131 |
|
---|
| 132 | LogIt "stabelilo-me --- starting"
|
---|
| 133 | LocateOldFstab
|
---|
[1564] | 134 | LocateOldElilo
|
---|
[1] | 135 | old_mountlist=/tmp/mountlist.original
|
---|
| 136 | new_mountlist=/tmp/mountlist.txt
|
---|
| 137 | QuitIfNotFound $old_mountlist
|
---|
| 138 | QuitIfNotFound $new_mountlist
|
---|
| 139 | QuitIfNotFound $old_fstab
|
---|
| 140 | QuitIfNotFound $old_eliloconf
|
---|
| 141 | LogIt "OK so far: I've found all the files I need." 2
|
---|
| 142 |
|
---|
| 143 | MakeBackups
|
---|
| 144 |
|
---|
| 145 | new_fstab=/mnt/RESTORING/etc/fstab.NEW
|
---|
| 146 | [ ! -e "$new_fstab" ] && new_fstab=/mnt/RESTORING/etc/fstab
|
---|
| 147 | new_eliloconf=/mnt/RESTORING/etc/elilo.conf.NEW
|
---|
| 148 | [ ! -e "$new_eliloconf" ] && new_eliloconf=/mnt/RESTORING/etc/elilo.conf
|
---|
| 149 |
|
---|
| 150 | LogIt "Modifying fstab..." 2
|
---|
| 151 | outval=0
|
---|
| 152 | hack-fstab $old_mountlist $old_fstab $new_mountlist $new_fstab
|
---|
| 153 | res=$?
|
---|
| 154 | if [ "$res" -ne "0" ] ; then
|
---|
| 155 | echo "Warning - hack-fstab failed"
|
---|
| 156 | outval=$(($outval+$res))
|
---|
| 157 | fi
|
---|
| 158 |
|
---|
| 159 | LogIt "Modifying elilo.conf. Please wait..." 2
|
---|
| 160 | hack-elilo $old_mountlist $old_fstab $old_liloconf $new_mountlist $new_fstab $new_liloconf
|
---|
| 161 | res=$?
|
---|
| 162 | outval=$(($outval+$res))
|
---|
| 163 | if [ "$outval" -ne "0" ] ; then
|
---|
| 164 | LogIt "Fstab and/or elilo modifications failed" 3
|
---|
| 165 | # RestoreBackups
|
---|
| 166 | else
|
---|
| 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 ..
|
---|
| 182 | fi
|
---|
| 183 |
|
---|
| 184 | if [ "$outval" -ne "0" ] ; then
|
---|
| 185 | LogIt "Error(s) occurred during elilo/fstab processing." 3
|
---|
| 186 | LogIt "Restoring originals." 3
|
---|
| 187 | RestoreBackups
|
---|
| 188 | else
|
---|
| 189 | LogIt "/etc/fstab and /etc/elilo.conf were modified ok." 3
|
---|
| 190 | fi
|
---|
| 191 | LogIt "stabelilo-me --- leaving"
|
---|
| 192 | exit $outval
|
---|
| 193 |
|
---|
| 194 |
|
---|