]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/usb/src/scripts/getdiskinfo
Add new usb rescue key code
[bacula/rescue] / rescue / linux / usb / src / scripts / getdiskinfo
1 #!/bin/sh
2 #
3 # Create bootstrap information files -- prelude to creating a
4 #   Bacula Rescue data for USB key
5 #
6 #   Kern Sibbald, December MMII
7 #      This source distributed under the GPLv2
8 #
9 #find out on which device is the usb key
10
11 if [ -f ../../../scripts/nozen ]; then 
12 DIALOG=dialog
13 else
14 DIALOG=Xdialog
15 fi
16
17 cd ..
18 one=1
19 etherdone=0
20 none=" "
21 usbdev=`blkid|grep bs-rescue|awk '{print $1}'|cut -d: -f1`
22 usbdev=${usbdev%?}
23
24 export LANG=C
25 cwd=`pwd`
26 owd=`pwd`
27
28
29 os=`uname -s`
30 if [ ! "x$1" = "x" ] ; then
31   host=clients/$1
32 else
33   host=clients/`hostname`
34 fi
35
36 if [ -f scripts/differenthostname ]; then 
37 host=clients/`cat scripts/differenthostname`
38 rm scripts/differenthostname
39 fi
40
41 echo "Host specific data will be saved in the directory: ${host}"
42 echo " "
43
44 if [ -f $host.bak/scripts/mount_drives ] ;then
45 rm -r $host.bak
46 fi
47
48 if [ -f $host/scripts/mount_drives ] ;then
49 mv $host $host.bak
50 fi
51
52 mkdir -p $host
53 di=${cwd}/$host/diskinfo
54 scr=${cwd}/$host/scripts
55 dirusb=/media/bs-rescue/bacula-rescue/$host
56 case $os in
57  Linux)
58   ;;
59  FreeBSD | SunOS | IRIX)
60    echo ""
61    echo "This code is not yet adapted to this OS"     
62    exit 1
63    ;;
64  *)
65    echo ""
66    echo "Unknown operating system type: $os"     
67    exit 1
68    ;;
69 esac
70 if [ ! `whoami` = "root" ] ; then
71   echo ""
72   echo "You need to be root to run this script ..."
73   echo ""
74   exit 1
75 fi
76
77 #
78 #  First collect information
79 #
80 rm -rf format.* partition.* $di create-* $scr
81 echo "Begin collecting system info ..."
82 mkdir -p $di
83 cd $di
84 mount -l >mount.bsi
85  fdisk -l|grep :|grep -v identifier|grep -v $usbdev|awk '{print $2}'|cut -d: -f1 >devtmp
86 cat devtmp|while read line;do
87 li=`echo $line|cut -d/ -f3`
88 fdisk -l $line > fdisk.$li
89 parted $line print > parted.$li
90 done
91 rm devtmp
92
93 mount -l -t jfs >mount.jfs.bsi
94 blkid |grep jfs >blkid.jfs.bsi
95 mount -l -t vfat >mount.vfat.bsi
96 blkid |grep vfat >blkid.vfat.bsi
97 mount -l -t xfs >mount.xfs.bsi
98 blkid |grep xfs >blkid.xfs.bsi
99 mount -l -t hfs >mount.hfs.bsi
100 blkid |grep hfs >blkid.hfs.bsi
101 mount -l -t hfsplus >mount.hfsplus.bsi
102 blkid |grep hfsplus >blkid.hfsplus.bsi
103 mount -l -t fuseblk >mount.fuseblk.bsi
104 mount -l -t ext2 >mount.ext2.bsi
105 blkid |grep ext2 >blkid.ext2.bsi
106 mount -l -t ext3 >mount.ext3.bsi
107 blkid |grep ext3 >blkid.ext3.bsi
108 mount -l -t ext4 >mount.ext4.bsi
109 blkid |grep ext4 >blkid.ext4.bsi
110
111 ########################################## problem
112 #blkid |grep ntfs >mount.ntfs.bsi
113
114 blkid |grep ntfs >blkid.ntfs.bsi
115 touch mount.ntfs.bsi
116 cat mount.fuseblk.bsi |awk '{print $1}'|while read line; do
117 blkid|grep $line|grep ntfs>/dev/null 2>&1
118 if [ $? = 0 ];then
119 a=`cat mount.fuseblk.bsi|grep $line|sed 's/fuseblk/ntfs/g'`
120 echo $a >>mount.ntfs.bsi
121 fi
122 done
123
124 ###########################################3
125
126 mount -l -t reiserfs >mount.reiser.bsi
127 blkid |grep reiserfs >blkid.reiserfs.bsi
128 cp /etc/fstab fstab.bsi
129 cp /etc/mtab  mtab.bsi     
130 df -Tl >df.bsi
131
132
133
134 # Pickup all disks except USB_DEV
135 sfdisk -s | grep -v ${usbdev}  >sfdisk.disks.bsi
136 #sfdisk -s  >sfdisk.disks.bsi
137 grep "^/dev/" sfdisk.disks.bsi | sed -n 's%\(^/dev/[A-Za-z]*\):.*$%\1%p' >disks.bsi
138 for i in `cat disks.bsi`; do
139    j=`echo $i | cut -c6-`
140    sfdisk -l $i >sfdisk.$j.bsi 
141    sfdisk -d $i >sfdisk.make.$j.bsi
142 done
143 cat /proc/swaps > swaps.bsi
144 route -n >route.bsi
145 ifconfig >ifconfig.bsi
146
147 # Gather LVM information
148 # Only tested on LVM2
149 dolvm=0
150 if  which lvm > /dev/null 2>/dev/null ; then
151     echo "Gathering LVM information"
152     dolvm=1
153
154     lvm pvs --noheadings --nosuffix -o pv_name,vg_name | cat > lvm-pv.bsi
155     lvm vgs --noheadings --nosuffix -o vg_name,vg_extent_size --units=k | cat > lvm-vg.bsi
156     lvm lvs --noheadings --nosuffix -o lv_name,vg_name,lv_size --units=k | cat > lvm-lv.bsi
157 fi
158
159 echo "Done collecting info."
160
161 #
162 # Done collecting information
163 #
164
165
166 echo "Begin creating scripts ..."
167 #
168 # First create partitioning script(s)
169 #
170 mkdir -p $scr
171 for i in `cat disks.bsi`; do
172   j=`echo $i | cut -c6-`
173   cat >$scr/partition.$j <<END_OF_DATA
174
175 #!/bin/sh
176 #
177 #  Partition disk $i  -- created by getdiskinfo
178 echo ""
179 echo "This script will repartition disk $i."
180 echo ""
181 echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
182 echo ""
183 if [ ! -f noprompt ];then
184 echo -n "Are you sure you want to continue? yes/no: "
185 read a
186 if [ x\$a != xyes ] ; then
187    exit 1
188 fi 
189 fi
190 echo "Partitioning disk $i"
191 # zap partition info
192 dd if=/dev/zero of=$i bs=512 count=1
193 # repartition
194 sfdisk --force $i <$dirusb/diskinfo/sfdisk.make.$j.bsi | less
195 echo ""
196 echo "The previous partitioning was:"
197 cat $dirusb/diskinfo/sfdisk.$j.bsi
198 #
199 echo ""
200 echo "The new partitioning is:"
201 sfdisk -l $i
202 echo ""
203 echo "If the disk is correctly partitioned, you should"
204 echo "now run the \"format.$j\" script."
205 echo ""
206 partprobe >>/dev/null 2>&1
207 END_OF_DATA
208
209
210 chmod 755 $scr/partition.$j
211 done
212 echo "Done making partitioning scripts"
213
214 if [ $dolvm -eq 1 ] ; then
215
216 # LVM phase 1: create the Physical Volumess
217 #
218     cat > $scr/create-pv <<EOF
219 #!/bin/sh
220 #
221 # Create PVs for LVM -- created by getdiskinfo
222 echo ""
223 echo "This script will format all partitions listed in diskinfo/lvm-pv.bsi"
224 echo ""
225 echo "IT WILL DESTROY ALL DATA ON THESE PARTITIONS!!!!"
226 echo ""
227 EOF
228     for pv in `cat lvm-pv.bsi | awk '{print $1}'`; do
229         echo "echo \"    $pv\"" >> $scr/create-pv
230     done
231
232     cat >> $scr/create-pv <<EOF
233 echo ""
234 if [ ! -f noprompt ];then
235 echo -n "Are you sure you want to continue? yes/no: "
236 read a
237 if [ x\$a != xyes ] ; then
238    exit 1
239 fi 
240 fi
241 EOF
242     for pv in `cat lvm-pv.bsi | awk '{print $1}'`; do
243         echo "echo \"Creating PV on $pv\"" >> $scr/create-pv
244         echo "lvm pvcreate -ff -y -v $pv" >> $scr/create-pv
245     done
246     echo "echo \"Done.\"" >> $scr/create-pv
247     echo "echo \"If there were no errors, run create-vg to create the volume groups.\"" >> $scr/create-pv
248     chmod +x $scr/create-pv
249
250 #
251 # LVM phase 2: create Volume Groups
252 #
253     cat > $scr/create-vg <<EOF
254 #!/bin/sh
255 echo ""
256 echo "This script will create all volume groups listed in diskinfo/lvm-vg.bsi"
257 echo "You must have sucesfully run create-pv to create the requesite PVs first"
258 echo ""
259 if [ ! -f noprompt ];then
260 echo -n "Are you sure you want to continue? yes/no: "
261 read a
262 if [ x\$a != xyes ] ; then
263    exit 1
264 fi
265 fi
266 EOF
267     cat lvm-vg.bsi | awk '{print $1, $2}' | while read vg pesize ; do
268         echo "echo \"Creating VG $vg PE extent size $pesize kbytes"\" >> $scr/create-vg
269         pelist=""
270         for pv in `cat lvm-pv.bsi | awk "\\\$2 == \"$vg\" { print \\\$1 }"` ; do
271             pelist="$pelist $pv"
272         done
273         echo "lvm vgcreate $vg -v -s ${pesize}k $pelist" >> $scr/create-vg
274     done
275     echo "echo \"Done.\"" >> $scr/create-vg
276     echo "echo \"If there were no errors, run create-lv to create the logical volumes.\"" >> $scr/create-vg
277     chmod +x $scr/create-vg
278
279
280 #
281 # LVM phase 3: create Logical Volumes 
282 #
283 # One quick sidenote: this script creates LVs with a size based on the
284 # physical extent count, rather than the size in bytes.  This is because
285 # at the time of writing this script, lvdisplay erroneously prints out
286 # the size in 512 byte sector count rather than 1024 byte blocks.
287 # Using the extent count should allow this script to continue to work
288 # even after the bug is fixed.
289
290     cat > $scr/create-lv <<EOF
291 #!/bin/sh
292 echo ""
293 echo "This script will create all logical volumes listed in diskinfo/lvm-lv.bsi"
294 echo "You must have sucesfully run create-vg to create the requesite VGs first"
295 echo ""
296 if [ ! -f noprompt ];then
297 echo -n "Are you sure you want to continue? yes/no: "
298 read a
299 if [ x\$a != xyes ] ; then
300    exit 1
301 fi
302 fi
303 EOF
304     cat lvm-lv.bsi | awk '{print $1, $2, $3}' | while read lv vg lvsize ; do
305         # lv=`echo $lv | sed -e 's/.*\///'`
306         echo "echo \"Creating LV $lv\"" >> $scr/create-lv
307         echo "lvm lvcreate -L ${lvsize}k $vg -n $lv" >> $scr/create-lv
308     done
309     chmod +x $scr/create-lv
310 fi
311
312 #
313 # Create formatting script(s)
314 #
315 echo "Begin making formatting script(s) ..."
316 for i in `cat disks.bsi`; do
317   j=`echo $i | cut -c6-`
318   cat >$scr/format.$j <<END_OF_DATA
319 #!/bin/sh
320 #
321 #  Format all partitions on disk $i -- created by getdiskinfo
322 #
323 echo ""
324 echo "This script will format all partitions on disk $i."
325 echo ""
326 echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
327 echo ""
328 if [ ! -f noprompt ];then
329 echo -n "Are you sure you want to continue? yes/no: "
330 read a
331 if [ x\$a != xyes ] ; then
332    exit 1
333 fi 
334 fi
335 if [ ! -f badblocksnoprompt ];then
336 echo "Do you want to do a disk check for bad blocks?"
337 echo -n "It is recommended, but takes time. yes/no: "
338 read a
339 if [ x\$a = xyes ] ; then
340    check="-c"
341 else
342    check=
343 fi
344 else
345    check=
346 fi
347 END_OF_DATA
348
349    # Find swap partitions in output from sfdisk
350    k=`grep "^$i.*82  Linux swap" sfdisk.$j.bsi | cut -d ' ' -f 1`
351    for disk in $k; do
352    fields=`blkid |grep $disk|wc -w`
353      kid=`blkid |grep $disk`
354      while [ $fields -ne 0 ];do
355      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
356      if [ $? = 0 ];then
357      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
358      fi
359      fields=$(( fields - 1 ))
360      done    
361    echo "echo \"Formatting $disk -- swap partition\"" >>$scr/format.$j
362       echo "mkswap $check -U $u $disk" >>$scr/format.$j
363       echo "echo \"\"" >>$scr/format.$j
364    done
365
366    # Find ext2 partitions in mount output
367    k=`grep "^$i" mount.ext2.bsi | cut -d ' ' -f 1`
368    for disk in $k; do
369     fields=`blkid |grep $disk|wc -w`
370      kid=`blkid |grep $disk`
371      while [ $fields -ne 0 ];do
372      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
373      if [ $? = 0 ];then
374      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
375      fi
376      fields=$(( fields - 1 ))
377      done  
378    echo "echo \"Formating $disk -- ext2 partition\"" >>$scr/format.$j
379       label=`grep "^$disk" mount.ext2.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
380       if [ x$label = x ] ; then
381          echo "mkfs.ext2 -v \$check $disk" >>$scr/format.$j
382       else
383          echo "mkfs.ext2 -v \$check -L $label -U $u $disk" >>$scr/format.$j
384       fi
385       echo "echo \"\"" >>$scr/format.$j
386    done
387    # Find ext3 partitions in mount output
388    k=`grep "^$i" mount.ext3.bsi | cut -d ' ' -f 1`
389    for disk in $k; do
390     fields=`blkid |grep $disk|wc -w`
391      kid=`blkid |grep $disk`
392      while [ $fields -ne 0 ];do
393      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
394      if [ $? = 0 ];then
395      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
396      fi
397      fields=$(( fields - 1 ))
398      done  
399     echo "echo \"Formating $disk -- ext3 partition\"" >>$scr/format.$j
400       label=`grep "^$disk" mount.ext3.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
401       if [ x$label = x ] ; then
402          echo "mkfs.ext3 -v -j \$check -U $u $disk" >>$scr/format.$j
403       else
404          echo "mkfs.ext3 -v -j \$check -L $label -U $u $disk" >>$scr/format.$j
405       fi
406       echo "echo \"\"" >>$scr/format.$j
407    done
408
409
410 # Find ext4 partitions in mount output
411    k=`grep "^$i" mount.ext4.bsi | cut -d ' ' -f 1`
412    for disk in $k; do
413     fields=`blkid |grep $disk|wc -w`
414      kid=`blkid |grep $disk`
415      while [ $fields -ne 0 ];do
416      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
417      if [ $? = 0 ];then
418      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
419      fi
420      fields=$(( fields - 1 ))
421      done  
422     echo "echo \"Formating $disk -- ext4 partition\"" >>$scr/format.$j
423       label=`grep "^$disk" mount.ext4.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
424       if [ x$label = x ] ; then
425          echo "mkfs.ext4 -v -j \$check -U $u $disk" >>$scr/format.$j
426       else
427          echo "mkfs.ext4 -v -j \$check -L $label -U $u $disk" >>$scr/format.$j
428       fi
429       echo "echo \"\"" >>$scr/format.$j
430    done
431
432  # Find xfs partitions in mount output
433    k=`grep "^$i" mount.xfs.bsi | cut -d ' ' -f 1`
434    for disk in $k; do
435      fields=`blkid |grep $disk|wc -w`
436      kid=`blkid |grep $disk`
437      while [ $fields -ne 0 ];do
438      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
439  
440    
441      if [ $? = 0 ];then
442      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
443      fi
444      fields=$(( fields - 1 ))
445      done
446
447
448    
449      echo "echo \"Formating $disk -- xfs partition\"" >>$scr/format.$j
450       label=`grep "^$disk" mount.xfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
451       if [ x$label = x ] ; then
452          echo "mkfs.xfs -f \$check  $disk" >>$scr/format.$j
453       else
454          echo "mkfs.xfs -f \$check -L $label  $disk" >>$scr/format.$j
455       fi
456         echo "xfs_admin -U $u $disk">>$scr/format.$j
457       echo "echo \"\"" >>$scr/format.$j
458    done 
459
460
461  # Find jfs partitions in mount output
462    k=`grep "^$i" mount.jfs.bsi | cut -d ' ' -f 1`
463    for disk in $k; do
464  fields=`blkid |grep $disk|wc -w`
465      kid=`blkid |grep $disk`
466      while [ $fields -ne 0 ];do
467      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
468     
469      if [ $? = 0 ];then
470      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
471      fi
472      fields=$(( fields - 1 ))
473      done
474      echo "echo \"Formating $disk -- jfs partition\"" >>$scr/format.$j
475       label=`grep "^$disk" mount.jfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
476       if [ x$label = x ] ; then
477          echo "mkfs.jfs -f \$check  $disk" >>$scr/format.$j
478       else
479          echo "mkfs.jfs -f \$check -L $label $disk" >>$scr/format.$j
480       fi
481          echo "jfs_tune -U $u $disk " >>$scr/format.$j
482       echo "echo \"\"" >>$scr/format.$j
483    done 
484  # Find vfat partitions in mount output
485    k=`grep "^$i" mount.vfat.bsi | cut -d ' ' -f 1`
486    for disk in $k; do
487      fields=`blkid |grep $disk|wc -w`
488      kid=`blkid |grep $disk`
489      while [ $fields -ne 0 ];do
490      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
491      if [ $? = 0 ];then
492      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
493      u=`echo $u|sed 's/-//g'`
494      fi
495      fields=$(( fields - 1 ))
496      done  
497       echo "echo \"Formating $disk -- vfat partition\"" >>$scr/format.$j
498       label=`grep "^$disk" mount.vfat.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
499       if [ x$label = x ] ; then
500          echo "mkfs.vfat \$check -i $u $disk" >>$scr/format.$j
501       else
502          echo "mkfs.vfat \$check -n $label -i $u $disk" >>$scr/format.$j
503       fi
504       echo "echo \"\"" >>$scr/format.$j
505    done
506  # Find reiserfs partitions in mount output
507    k=`grep "^$i" mount.reiser.bsi | cut -d ' ' -f 1`
508    for disk in $k; do
509       fields=`blkid |grep $disk|wc -w`
510      kid=`blkid |grep $disk`
511      while [ $fields -ne 0 ];do
512      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
513      if [ $? = 0 ];then
514      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
515      fi
516      fields=$(( fields - 1 ))
517      done
518      echo "echo \"Formating $disk -- reiser partition\"" >>$scr/format.$j
519       label=`grep "^$disk" mount.reiser.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
520       if [ x$label = x ] ; then
521          echo "mkreiserfs -u $u $disk" >>$scr/format.$j
522       else
523          echo "mkreiserfs -l $label -u $u $disk" >>$scr/format.$j
524       fi
525       echo "echo \"\"" >>$scr/format.$j
526    done
527
528
529 # Find hfs partitions in mount output
530
531    k=`grep "^$i" mount.hfs.bsi | cut -d ' ' -f 1`
532    for disk in $k; do
533  
534      echo "echo \"Formating $disk -- hfs partition\"" >>$scr/format.$j
535        label=`grep "^$disk" mount.hfs.bsi  |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
536       if [ x$label = x ] ; then
537          echo "mkfs.hfs \$check  $disk" >>$scr/format.$j
538       else
539          echo "mkfs.hfs \$check -v $label  $disk" >>$scr/format.$j
540       fi
541       echo "echo \"\"" >>$scr/format.$j
542    done 
543
544
545 # Find hfsplus partitions in mount output
546
547    k=`grep "^$i" mount.hfsplus.bsi | cut -d ' ' -f 1`
548    for disk in $k; do
549      
550       echo "echo \"Formating $disk -- hfsplus partition\"" >>$scr/format.$j
551       label=`grep "^$disk" mount.hfsplus.bsi  |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
552       if [ x$label = x ] ; then
553          echo "mkfs.hfsplus \$check  $disk" >>$scr/format.$j
554       else
555          echo "mkfs.hfsplus \$check -v $label  $disk" >>$scr/format.$j
556       fi
557       echo "echo \"\"" >>$scr/format.$j
558    done
559
560
561 # Find ntfs partitions in mount output
562    k=`grep "^$i" mount.ntfs.bsi | cut -d ' ' -f 1`
563    for disk in $k; do
564      
565       echo "echo \"Formating $disk -- ntfs partition\"" >>$scr/format.$j
566       label=`grep "^$disk" mount.ntfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
567       if [ x$label = x ] ; then
568          echo "mkfs.ntfs \$check  $disk" >>$scr/format.$j
569       else
570          echo "mkfs.ntfs \$check -L $label  $disk" >>$scr/format.$j
571       fi
572       echo "echo \"\"" >>$scr/format.$j
573    done
574    chmod 755 $scr/format.$j
575 done
576 #
577 # Create LVM formatting scripts(s)
578 #
579 # Somebody more clever than I with bash scripting
580 # could probably factor a lot of this code out.
581 #
582 if [ $dolvm -eq 1 ] ; then
583     echo "Begin making LVM formatting script(s) ..."
584     for i in `cat lvm-vg.bsi | awk '{print $1}'`; do
585         cat >$scr/format.$i <<END_OF_DATA
586 #!/bin/sh
587 #
588 #  Format all partitions on VG $i -- created by getdiskinfo
589 #
590 echo ""
591 echo "This script will format all LVs on VG $i."
592 echo ""
593 echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
594 echo ""
595 if [ ! -f noprompt ];then
596 echo -n "Are you sure you want to continue? yes/no: "
597 read a
598 if [ x\$a != xyes ] ; then
599    exit 1
600 fi
601 fi
602 if [ ! -f badblocksnoprompt ];then
603 echo "Do you want to do a disk check for bad blocks?"
604 echo -n "It is recommended, but takes time. yes/no: "
605 read a
606 if [ x\$a = xyes ] ; then
607    check="-c"
608 else
609    check=
610 fi
611 else
612 check=
613 fi
614 END_OF_DATA
615
616    # Find swap partitions in output from sfdisk
617    
618     mapper="/dev/mapper/${i}"
619    k=`grep "^$mapper" swaps.bsi | awk '{print $1}'`
620    for disk in $k; do
621    fields=`blkid |grep $disk|wc -w`
622      kid=`blkid |grep $disk`
623      while [ $fields -ne 0 ];do
624      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
625      if [ $? = 0 ];then
626      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
627      fi
628      fields=$(( fields - 1 ))
629      done  
630    echo "echo \"Formatting $disk -- swap partition\"" >>$scr/format.$i
631       echo "mkswap $check -U $u $disk" >>$scr/format.$i
632       echo "echo \"\"" >>$scr/format.$i
633    done
634
635    # Find ext2 partitions in mount output
636    k=`grep "^$mapper" mount.ext2.bsi | cut -d ' ' -f 1`
637    for disk in $k; do
638     fields=`blkid |grep $disk|wc -w`
639      kid=`blkid |grep $disk`
640      while [ $fields -ne 0 ];do
641      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
642      if [ $? = 0 ];then
643      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
644      fi
645      fields=$(( fields - 1 ))
646      done  
647    echo "echo \"Formating $disk -- ext2 partition\"" >>$scr/format.$i
648       label=`grep "^$disk" mount.ext2.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
649       if [ x$label = x ] ; then
650          echo "mkfs.ext2 -v \$check $disk" >>$scr/format.$i
651       else
652          echo "mkfs.ext2 -v \$check -L $label -U $u $disk" >>$scr/format.$i
653       fi
654       echo "echo \"\"" >>$scr/format.$i
655    done
656    # Find ext3 partitions in mount output
657    k=`grep "^$mapper" mount.ext3.bsi | cut -d ' ' -f 1`
658    for disk in $k; do
659     fields=`blkid |grep $disk|wc -w`
660      kid=`blkid |grep $disk`
661      while [ $fields -ne 0 ];do
662      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
663      if [ $? = 0 ];then
664      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
665      fi
666      fields=$(( fields - 1 ))
667      done  
668     echo "echo \"Formating $disk -- ext3 partition\"" >>$scr/format.$i
669       label=`grep "^$disk" mount.ext3.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
670       if [ x$label = x ] ; then
671          echo "mkfs.ext3 -v -j \$check -U $u $disk" >>$scr/format.$i
672       else
673          echo "mkfs.ext3 -v -j \$check -L $label -U $u $disk" >>$scr/format.$i
674       fi
675       echo "echo \"\"" >>$scr/format.$i
676    done
677
678
679 # Find ext4 partitions in mount output
680    k=`grep "^$mapper" mount.ext4.bsi | cut -d ' ' -f 1`
681    for disk in $k; do
682     fields=`blkid |grep $disk|wc -w`
683      kid=`blkid |grep $disk`
684      while [ $fields -ne 0 ];do
685      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
686      if [ $? = 0 ];then
687      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
688      fi
689      fields=$(( fields - 1 ))
690      done  
691     echo "echo \"Formating $disk -- ext4 partition\"" >>$scr/format.$i
692       label=`grep "^$disk" mount.ext4.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
693       if [ x$label = x ] ; then
694          echo "mkfs.ext4 -v -j \$check -U $u $disk" >>$scr/format.$i
695       else
696          echo "mkfs.ext4 -v -j \$check -L $label -U $u $disk" >>$scr/format.$i
697       fi
698       echo "echo \"\"" >>$scr/format.$i
699    done
700
701  # Find xfs partitions in mount output
702    k=`grep "^$mapper" mount.xfs.bsi | cut -d ' ' -f 1`
703    for disk in $k; do
704      fields=`blkid |grep $disk|wc -w`
705      kid=`blkid |grep $disk`
706      while [ $fields -ne 0 ];do
707      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
708  
709    
710      if [ $? = 0 ];then
711      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
712      fi
713      fields=$(( fields - 1 ))
714      done
715
716
717    
718      echo "echo \"Formating $disk -- xfs partition\"" >>$scr/format.$i
719       label=`grep "^$disk" mount.xfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
720       if [ x$label = x ] ; then
721          echo "mkfs.xfs -f \$check  $disk" >>$scr/format.$i
722       else
723          echo "mkfs.xfs -f \$check -L $label  $disk" >>$scr/format.$i
724       fi
725         echo "xfs_admin -U $u $disk">>$scr/format.$i
726       echo "echo \"\"" >>$scr/format.$i
727    done 
728
729
730  # Find jfs partitions in mount output
731    k=`grep "^$mapper" mount.jfs.bsi | cut -d ' ' -f 1`
732    for disk in $k; do
733  fields=`blkid |grep $disk|wc -w`
734      kid=`blkid |grep $disk`
735      while [ $fields -ne 0 ];do
736      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
737     
738      if [ $? = 0 ];then
739      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
740      fi
741      fields=$(( fields - 1 ))
742      done
743      echo "echo \"Formating $disk -- jfs partition\"" >>$scr/format.$i
744       label=`grep "^$disk" mount.jfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
745       if [ x$label = x ] ; then
746          echo "mkfs.jfs -f \$check  $disk" >>$scr/format.$i
747       else
748          echo "mkfs.jfs -f \$check -L $label $disk" >>$scr/format.$i
749       fi
750          echo "jfs_tune -U $u $disk " >>$scr/format.$i
751       echo "echo \"\"" >>$scr/format.$i
752    done 
753  # Find vfat partitions in mount output
754    k=`grep "^$mapper" mount.vfat.bsi | cut -d ' ' -f 1`
755    for disk in $k; do
756      fields=`blkid |grep $disk|wc -w`
757      kid=`blkid |grep $disk`
758      while [ $fields -ne 0 ];do
759      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
760      if [ $? = 0 ];then
761      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
762      u=`echo $u|sed 's/-//g'`
763      fi
764      fields=$(( fields - 1 ))
765      done  
766       echo "echo \"Formating $disk -- vfat partition\"" >>$scr/format.$i
767       label=`grep "^$disk" mount.vfat.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
768       if [ x$label = x ] ; then
769          echo "mkfs.vfat \$check -i $u $disk" >>$scr/format.$i
770       else
771          echo "mkfs.vfat \$check -n $label -i $u $disk" >>$scr/format.$i
772       fi
773       echo "echo \"\"" >>$scr/format.$i
774    done
775  # Find reiserfs partitions in mount output
776    k=`grep "^$mapper" mount.reiser.bsi | cut -d ' ' -f 1`
777    for disk in $k; do
778       fields=`blkid |grep $disk|wc -w`
779      kid=`blkid |grep $disk`
780      while [ $fields -ne 0 ];do
781      echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
782      if [ $? = 0 ];then
783      u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
784      fi
785      fields=$(( fields - 1 ))
786      done
787      echo "echo \"Formating $disk -- reiser partition\"" >>$scr/format.$i
788       label=`grep "^$disk" mount.reiser.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
789       if [ x$label = x ] ; then
790          echo "mkreiserfs -u $u $disk" >>$scr/format.$i
791       else
792          echo "mkreiserfs -l $label -u $u $disk" >>$scr/format.$i
793       fi
794       echo "echo \"\"" >>$scr/format.$i
795    done
796
797
798 # Find hfs partitions in mount output
799
800    k=`grep "^$mapper" mount.hfs.bsi | cut -d ' ' -f 1`
801    for disk in $k; do
802  
803      echo "echo \"Formating $disk -- hfs partition\"" >>$scr/format.$i
804        label=`grep "^$disk" mount.hfs.bsi  |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
805       if [ x$label = x ] ; then
806          echo "mkfs.hfs \$check  $disk" >>$scr/format.$i
807       else
808          echo "mkfs.hfs \$check -v $label  $disk" >>$scr/format.$i
809       fi
810       echo "echo \"\"" >>$scr/format.$i
811    done 
812
813
814 # Find hfsplus partitions in mount output
815
816    k=`grep "^$mapper" mount.hfsplus.bsi | cut -d ' ' -f 1`
817    for disk in $k; do
818      
819       echo "echo \"Formating $disk -- hfsplus partition\"" >>$scr/format.$i
820       label=`grep "^$disk" mount.hfsplus.bsi  |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
821       if [ x$label = x ] ; then
822          echo "mkfs.hfsplus \$check  $disk" >>$scr/format.$i
823       else
824          echo "mkfs.hfsplus \$check -v $label  $disk" >>$scr/format.$i
825       fi
826       echo "echo \"\"" >>$scr/format.$i
827    done
828
829
830 # Find ntfs partitions in mount output
831    k=`grep "^$mapper" mount.ntfs.bsi | cut -d ' ' -f 1`
832    for disk in $k; do
833      
834       echo "echo \"Formating $disk -- ntfs partition\"" >>$scr/format.$i
835       label=`grep "^$disk" mount.ntfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
836       if [ x$label = x ] ; then
837          echo "mkfs.ntfs \$check  $disk" >>$scr/format.$i
838       else
839          echo "mkfs.ntfs \$check -L $label  $disk" >>$scr/format.$i
840       fi
841       echo "echo \"\"" >>$scr/format.$i
842    done
843
844
845
846
847    chmod 755 $scr/format.$i
848    done
849 fi
850
851 cd $scr
852
853 #
854 # Create network start script
855 #
856
857
858
859 if [ -f ../../../scripts/nozen ]; then 
860 DIALOG=dialog
861 else
862 DIALOG=Xdialog
863 fi
864
865 howmanyether=`ifconfig |cut -d" " -f1 |grep -v '^$' |grep -v lo|wc -l`
866 if [ $howmanyether -gt 1 ] ; then
867 netline=0
868 cp  ../../../scripts/dialognetworkorig  dialognetwork
869 sed -i 's/howmany/'$howmanyether'/g' dialognetwork
870 sed -i 's/DIAL/'$DIALOG'/g' dialognetwork
871 ifconfig |cut -d" " -f1 |grep -v '^$' |grep -v lo | while read LINE ; do
872 confnet=$LINE
873 netline=$(( netline + 1 ))
874 if [ $netline -ne $howmanyether ];then
875 echo $netline $LINE ' off  ' >> dialognetwork
876 else 
877 echo $netline $LINE ' off 2>ans ' >> dialognetwork
878 fi
879 done
880 dial=`cat dialognetwork`
881
882 echo $dial > dialognetwork
883 chmod +x dialognetwork
884 . ./dialognetwork
885         if [ $? = 1 ];then
886         exit 1
887         fi
888 ans=`cat ans`
889 rm ans
890 rm dialognetwork
891 ifconfig |cut -d" " -f1 |grep -v '^$' |grep -v lo > net
892 net=`cat net`
893 netdevice=`echo $net |awk "{print \$ $ans}" `
894 etherdone=1
895 rm net
896
897 fi
898
899
900 if [ $etherdone = 0 ] ; then
901  ether=`ifconfig |cut -d" " -f1 |grep -v '^$' |grep -v lo`
902
903 else
904     ether=`echo $netdevice`
905 fi
906
907 ifconfig $ether 2>/dev/null >/dev/null
908 if [ $? = 0 ] ; then
909   ip=`ifconfig $ether | grep inet | head -1 | sed -n 's/\ \+inet addr:\([0-9]\+\(\.[0-9]\+\)\{3\}\).*/\1/p'`
910   cat >start_network <<END_OF_DATA
911 #!/bin/sh
912 #
913 #  Start network -- created by getdiskinfo
914 #
915 ip=$ip
916 dev=$ether
917 ifconfig lo up
918 ifconfig \$dev up \$ip
919 END_OF_DATA
920 else
921    echo "Warning, no ethernet devices found."
922    echo "#!/bin/sh" >start_network
923 fi
924
925 ip=`route -n | grep UG | head -1 | awk '{print $2}'`
926 dev=`route -n | grep UG | head -1 | awk '{print $8}'`
927 cat >>start_network <<END_OF_DATA
928 route add default gw $ip  $ether
929 END_OF_DATA
930
931 chmod 755 start_network
932
933
934
935 cat >$scr/mount_drives <<END_OF_DATA
936 #!/bin/sh
937 #
938 #  Mount disk drives  -- created by getdiskinfo
939 #
940 PATH=$PATH:/var/chroot/sbin:/var/chroot/bin
941 END_OF_DATA
942 TMP1=`mktemp gdi.1.XXXXXXXXXX`
943 TMP2=`mktemp gdi.2.XXXXXXXXXX`
944 if test x${TMP1} = x; then
945    TMP1="/tmp/1$$"
946    if test -f ${TMP1}; then
947       echo "Temp file security problem on: ${TMP1}"
948       exit 1
949    fi
950 fi
951 if test x${TMP2} = x; then
952    TMP2="/tmp/2$$"
953    if test -f ${TMP2}; then
954       echo "Temp file security problem on: ${TMP2}"
955       rm -f ${TMP1}
956       exit 1
957    fi
958 fi
959 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.ext2.bsi >${TMP1}
960 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.ext3.bsi >>${TMP1}
961 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.reiser.bsi >>${TMP1}
962 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.hfs.bsi >>${TMP1}
963 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.xfs.bsi >>${TMP1}
964 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.jfs.bsi >>${TMP1}
965 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.fuseblk.bsi >>${TMP1}
966 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.vfat.bsi >>${TMP1}
967
968 # sort so that / is first
969 sort -k 2 <${TMP1} >${TMP2}
970 # output mkdir followed by its mount
971 sed -n 's/\(^.*\)\ \(.*$\)/mkdir -p \2  #\1\
972 mount \1 \2/p' ${TMP2} >>$scr/mount_drives
973
974 # Now build unmount_drives
975 cat >$scr/umount_drives <<END_OF_DATA
976 #!/bin/sh
977 #
978 #  Unmount disk drives  -- created by getdiskinfo
979 #
980 END_OF_DATA
981 sort -r -k 2 <${TMP1} >${TMP2}
982 sed -n 's/\(^.*\)\ \(.*$\)/umount \2/p' ${TMP2} >>$scr/umount_drives
983 echo "umount /mnt/cdrom 2>/dev/null >/dev/null" >>$scr/umount_drives
984 echo "sync" >>$scr/umount_drives
985 echo "sync" >>$scr/umount_drives
986
987 rm -f ${TMP1} ${TMP2}
988
989 chmod 755 $scr/mount_drives $scr/umount_drives
990
991 #output result of blkid
992
993 blkid | while read LINE ; do
994 echo $LINE >> $cwd/$host/diskinfo/blkidinfo
995 done
996
997 #find raid devices
998
999 .  $cwd/scripts/findraidevice/findraid_new
1000
1001 if [ ! -f $cwd/$host/scripts/recreate_raid_arrays ];then
1002  
1003 echo "";echo "";echo "";echo "You do not seem to have any soft raid devices";echo "";echo "";echo ""
1004 fi
1005
1006 . $cwd/scripts/new_baklient_conf
1007 . $cwd/scripts/get_serial
1008 rm $cwd/scripts/ans
1009
1010 echo "Done building scripts."
1011 $DIALOG --title "That's it" --msgbox "We are done gathering info \n you can now restore your machine \n (in case it crashes) \n booting on this usb key \n \n \n P.S. If your computer's bios doesn't support booting off usb, \n insert the provided boot cd as well as this usb key and the magic will happen...." 600 600