]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/usb/src/scripts/chrootscript
Add new usb rescue key code
[bacula/rescue] / rescue / linux / usb / src / scripts / chrootscript
1 #!/bin/sh
2 #iface=`ifconfig |cut -d" " -f1|head -n1`
3
4 swp=`blkid |grep swap|awk '{print $1}'|cut -d: -f1|head -n1`
5 if [ ! $swp = "" ];then
6 swapon $swp
7 fi
8
9 iface=`grep dev= working/scripts/start_network|cut -d= -f2`
10 . ./unmount-all
11 howmany=`ifconfig |cut -d" " -f1 |grep -v '^$' |grep -v lo|wc -l`
12
13 tmp=""
14 echo "">tmp
15 ifconfig |cut -d" " -f1 |grep -v '^$' |grep -v lo |while read line; do
16 #line=${line%?}
17
18 echo `echo $line $line'\'`>>tmp
19
20 tmp2=`cat tmp`
21 #tmp2=${tmp2%?}
22 echo $tmp2 >tmp
23 done
24 tmp=`cat tmp`
25
26 if [ -f ../../../scripts/nozen ]; then 
27 DIALOG=dialog
28 else
29 DIALOG=Xdialog
30 fi
31
32 $DIALOG --menu "Which ethernet adapter connects to the director ??:" 30 60 20 $tmp 2>ans 
33 ifaceans=`cat ans`
34
35
36
37
38 sed -i 's/'$iface'/'$ifaceans'/g' working/scripts/start_network
39 . ./working/scripts/start_network
40 . ./unmount-all
41 if [ -f mount_drives ];then
42 rm mount_drives
43 fi
44
45 if [ -d /media/bs-rescue/chroot ];then
46 rm -r /media/bs-rescue/chroot
47 fi
48 mkdir /media/bs-rescue/chroot
49
50
51 touch mount_drives
52 cat disklist|while read line;do
53 cat working/scripts/mount_drives|grep $line>>/dev/null 2>&1
54 if [ $? = 0 ];then
55 cat working/scripts/mount_drives|grep $line|while read LINE;do
56 cat mount_drives|grep "$LINE"
57 if [ ! $? = 0 ];then
58 echo $LINE>>mount_drives
59 fi
60 done
61 fi
62 done
63
64 cat lvdisks|while read line;do
65 cat working/scripts/mount_drives|grep $line>>/dev/null 2>&1
66 if [ $? = 0 ];then
67 cat working/scripts/mount_drives|grep $line|while read LINE;do
68 cat mount_drives|grep "$LINE"
69 if [ ! $? = 0 ];then
70 echo $LINE>>mount_drives
71 fi
72 done
73 fi
74 done
75
76 chmod +x mount_drives
77 . ./mount_drives
78 if [ ! -d /media/bs-rescue/chroot/sys ];then
79 mkdir /media/bs-rescue/chroot/sys
80 fi
81 if [ ! -d /media/bs-rescue/chroot/tmp ];then
82 mkdir /media/bs-rescue/chroot/tmp
83 chmod 777 /media/bs-rescue/chroot/tmp
84 fi
85 if [ ! -d /media/bs-rescue/chroot/dev ];then
86 mkdir /media/bs-rescue/chroot/dev
87 fi
88 if [ -f /media/bs-rescue/chroot/bacula-fdstatic ];then
89 rm /media/bs-rescue/chroot/bacula-fdstatic
90 fi
91 #cp bacula-fdstatic /media/bs-rescue/chroot
92 #cp batermined /media/bs-rescue/chroot
93 #cp working/diskinfo/bacula-fd.conf /media/bs-rescue/chroot #### doesn t work if you copy files
94 #cp working/diskinfo/bat.conf /media/bs-rescue/chroot           before mounting disks
95 if [ ! -d /media/bs-rescue/chroot/proc ];then
96 mkdir /media/bs-rescue/chroot/proc
97 fi
98 mount -o bind /proc /media/bs-rescue/chroot/proc
99
100
101
102
103
104
105 cp working/diskinfo/bacula-fd.conf /media/bs-rescue/chroot
106
107 if [ ! -d /media/bs-rescue/chroot/etc ];then
108 mkdir -p /media/bs-rescue/chroot/etc
109 fi
110 if [ ! -d /media/bs-rescue/chroot/lib ];then
111 mkdir -p /media/bs-rescue/chroot/lib
112 fi
113 cp /lib/libnss_dns.so.2 /media/bs-rescue/chroot/lib
114 cp /etc/nsswitch.conf /media/bs-rescue/chroot/etc
115 cp /etc/resolv.conf /media/bs-rescue/chroot/etc
116 cp ping.ermined /media/bs-rescue/chroot/ping
117
118 if [ ! -d /media/bs-rescue/chroot/var/bacula/working ];then
119 mkdir -p /media/bs-rescue/chroot/var/bacula/working
120 fi
121 if [ ! -d /media/bs-rescue/chroot/var/run/bacula ];then
122 mkdir -p /media/bs-rescue/chroot/var/run/bacula
123 fi
124
125 if [  -d /etc/bacula ];then
126 rm -r /etc/bacula
127 fi
128 mkdir /etc/bacula
129
130
131 if [ -f  working/diskinfo/bconsole.conf ];then
132
133 cp working/diskinfo/bconsole.conf /etc/bacula
134 ../bin/bconsole.ermined < bcon > bconsole_output
135         cat bconsole_output |grep Version|awk '{print $5}'|grep 3.0
136         if [ $? = 0 ];then
137         cp /media/bs-rescue/bacula-rescue/bin/bacula-fd-static-3.0.3 /media/bs-rescue/chroot/bacula-fd-static
138         fi
139                 cat bconsole_output |grep Version|awk '{print $5}'|grep 2.4
140                 if [ $? = 0 ];then
141                 cp /media/bs-rescue/bacula-rescue/bin/bacula-fd-static-2.4.4 /media/bs-rescue/chroot/bacula-fd-static
142                 fi
143 else
144
145 $DIALOG --backtitle "If you want to connect to the director from this machine, \n you must provide a bconsole.conf , where is it ? \n (otherwise you can restore this client from another bconsole bat or bweb \n on another machine ) " --title "(spacebar to select)" --aspect 12 --begin 4 3 --fselect / 30 60 2>tmp
146     if [ $? = 1 ];then
147     $DIALOG --title "!!!!!!" --msgbox "No bconsole.conf, you will have to access your director \n from another machine and restore the directories \n that correspond to the drives you just formated" 30 60
148 $DIALOG --radiolist "Which director version do you use ?:" 10 40 3 \
149         1 "  2.4.x" off \
150         2 "  3.0.x" off 2>ans
151         if [ $? = 1 ];then
152         exit 1
153         fi
154    
155                         version=`cat ans`
156                         if [ $version = "1" ];then
157                         cp /media/bs-rescue/bacula-rescue/bin/bacula-fd-static-2.4.4 /media/bs-rescue/chroot/bacula-fd-static
158                         fi
159                                 if [ $version = "2" ];then
160                                 cp /media/bs-rescue/bacula-rescue/bin/bacula-fd-static-3.0.3 /media/bs-rescue/chroot/bacula-fd-static
161                                 fi
162         rm ans
163    fi
164                 if [ -f tmp ];then
165                 bakonf=`cat tmp`
166                 rm tmp
167                 else
168                 bakonf=""
169                 fi
170
171 echo $bakonf |grep bconsole.conf
172   if [ $? = 0 ];then
173
174   cp $bakonf /etc/bacula
175   else
176  $DIALOG --radiolist "Which director version do you use ?:" 10 40 3 \
177         1 "  2.4.x" off \
178         2 "  3.0.x" off 2>ans
179         if [ $? = 1 ];then
180         exit 1
181         fi
182     fi
183                 version=`cat ans`
184                 if [ $version = "1" ];then
185                 cp /media/bs-rescue/bacula-rescue/bin/bacula-fd-static-2.4.4 /media/bs-rescue/chroot/bacula-fd-static
186                 fi
187                         if [ $version = "2" ];then
188                         cp /media/bs-rescue/bacula-rescue/bin/bacula-fd-static-3.0.3 /media/bs-rescue/chroot/bacula-fd-static
189                         fi
190                         rm ans
191
192
193   fi
194 chroot /media/bs-rescue/chroot /bacula-fd-static -c /bacula-fd.conf &
195 df |grep /media/bs-rescue/chroot |grep -v /media/bs-rescue/chroot/ >/dev/null 2>&1
196 if [ $? = 1 ];then
197 df |grep /media/bs-rescue/chroot >tmp 
198 place=`cat tmp|awk '{print $6}'|cut -c 24-1000`
199 if [ -f tmp2 ];then
200 rm tmp2
201 touch tmp2
202 fi
203         df |grep /media/bs-rescue/chroot >tmp 
204         place=""
205                 cat tmp|while read line;do
206                 b=`echo $line|awk '{print $6}'|cut -c 24-1000`
207                         if [ ! $b = "" ];then
208                         placet=`echo $b`
209                         
210                         else
211                         lv=`df |grep mapper`
212                         placet=`df $lv|grep media|awk '{print $5}'|cut -c 24-1000`
213                         
214                                 
215                                 
216         
217                         fi
218                                 if [ -f tmp2 ];then
219                                   cat tmp2|grep $placet
220                                   if [ ! $? = 0 ];then
221                                   echo  $placet>>tmp2
222                                   fi
223                                 else
224                                 echo  $placet>>tmp2
225                                 fi
226
227                 done
228
229 place=`cat tmp2`
230 rm tmp2
231
232
233
234
235
236 $DIALOG --title "!!! WARNING !!!" --msgbox "Be carefull you didn't choose your root disk, so you must ONLY restore \n files that are situated on  \$ $place \n otherwise you would fill up this usb key instead of your disks \n \n \n But you still want to point to / (where to ?? >>>  / )" 30 60
237 fi
238 $DIALOG --title "!!! WARNING !!!" --msgbox "Now you must restore your files pointing to / \n We are faking that your disks are mounted on the root ( / ) \n \n \n If you restore your files anywhere else it wont work" 30 60
239 if [ -f /etc/bacula/bconsole.conf ];then
240  ../bin/bconsole.ermined
241 fi
242 $DIALOG --title "PROCESSING" --msgbox "Please press ok when your job is done" 30 60
243 if [ -d /media/bs-rescue/chroot/boot/grub ];then
244 $DIALOG --title "Install GRUB ?" --yesno "You seem to have GRUB installed on this disk, \n Do you want to run install-grub (grub 1) on this disk ? \n (we will back up the grub dir in grub.bak in case something goes wrong)" 30 60 
245 if [ $? = 0 ];then
246 grubdisk=`df |grep /media/bs-rescue/chroot |grep -v /media/bs-rescue/chroot/ |awk '{print $1}'`
247 cp -r /media/bs-rescue/chroot/boot/grub /media/bs-rescue/chroot/boot/grub.bak
248 grub-install --root-directory=/media/bs-rescue/chroot/boot/grub $grubdisk
249 fi
250 fi
251 $DIALOG --title "THAT'S IT" --msgbox "That's it , we're all done \n \n \n Enjoy !!!" 30 60
252 if [ -f added_disks ];then
253 rm added_disks
254 fi
255 if [ -f alldisks ];then
256 rm alldisks
257 fi
258
259 if [ -f ans ];then
260 rm ans
261 fi
262
263 if [ -f badblocksnoprompt ];then
264 rm badblocksnoprompt
265 fi
266
267 if [ -f noprompt ];then
268 rm noprompt
269 fi
270
271 if [ -f clientmp ];then
272 rm clientmp
273 fi
274
275
276 if [ -f dialogtest ];then
277 rm dialogtest
278 fi
279
280 if [ -f disklist ];then
281 rm disklist
282 fi
283
284 if [ -f fulldisks ];then
285 rm fulldisks
286 fi
287
288 if [ -d working ];then
289 rm -r working
290 fi
291
292 if [ -f mount_drives ];then
293 rm mount_drives
294 fi
295
296 if [ -f tmp ];then
297 rm tmp
298 fi
299  pid=`ps -ax|grep ermine|grep -v grep|awk '{print $1}'`
300 if [ ! $pid = "" ];then
301 kill $pid
302 fi
303 lsof |grep /media/bs-rescue/chroot|awk '{print $2}'|while read line ;do
304 if [ ! $line = "" ];then
305 kill $line
306 fi
307 done