]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/usb/src/scripts/restore/newsize
Add new usb rescue key code
[bacula/rescue] / rescue / linux / usb / src / scripts / restore / newsize
1 #!/bin/sh
2 if [ -f nozen ]; then 
3 DIALOG=dialog
4 else
5 DIALOG=Xdialog
6 fi
7 set -x                          
8 MB=MB
9                                 part=`echo $disk|cut -d"/" -f3`
10                                 fdisk -l /dev/$part |grep bytes|grep -v Units|awk '{print $5}'>samesize
11                                 cat working/diskinfo/fdisk.$part |grep bytes|grep -v Units|awk '{print $5}'>samesize2
12                                 diff samesize samesize2 >/dev/null 2>&1
13                         if [ ! $? = 0 ] ;then
14                                 nowdisk=`cat samesize`
15                                 oldisk=`cat samesize2`
16                                 
17
18
19                                 $DIALOG --title "different disk" --msgbox "The size of the disk you are trying to restore \n and the one we have backed up differ for /dev/$part  \n \n The old disk size was  $oldisk  \n And the actual disk size is  $nowdisk \n \n We'll have to do things manually" 60 60
20                                 oldiskparted=`cat working/diskinfo/parted.$part`
21                                 howmanyparts=`cat working/diskinfo/parted.$part|wc -l`
22                                 howmanyparts=$(( $howmanyparts - 7 ))
23                                         $DIALOG --title "different disk" --yesno "Do you want to do it manually \n ( we will launch gparted) (yes) \n Or only adjust the LAST partition size to fit the disk ?  (no)" 60 60
24                                         if [ $? = 0 ];then
25                                 if [ $DIALOG = Xdialog ];then
26                                 echo $$oldiskparted
27                                 $DIALOG --title "different disk" --msgbox "the old partition sizes for this disk was \n \n $oldiskparted \n \n We will now launch gparted so you can adjust you disk partitions " 60 60
28                                 gparted /dev/$part
29                                 else
30                                 $DIALOG --title "different disk" --msgbox "the old partition sizes for this disk was \n \n $oldiskparted \n \n please use fdisk or cfdisk to repartition your drive \n \n and the re-run this script pointing to the partitions of the new disks  \n (like /dev/sda1 ) instead of the whole disk (/dev/sda)" 60 60
31                                 exit 1
32                                 fi
33                                         else
34
35                                 a=` sfdisk -n /dev/$part < working/diskinfo/sfdisk.$part.make.bsi 2>&1`
36                                 echo $a > tmp
37                                 grep Warning tmp
38                                 if [ $? = 0 ];then
39                                 tr ' ' '\n' < tmp >tmp2
40                                 cat tmp2|awk /given/,/sfdisk/ >tmp3
41                                 currentsize=`cat tmp3|grep -m1 "("|cut -d"(" -f2 |cut -d")" -f1`
42                                 maxsize=`cat tmp3|grep -m2 "("|cut -d"(" -f2 |cut -d")" -f1|tail -n1`
43                                 sed -i "s/$currentsize/$maxsize/g" working/diskinfo/sfdisk.make.$part.bsi
44                                 nowarn=1
45                                 while [ $nowarn = 1 ];do
46                                 a=` sfdisk -n /dev/$part < working/diskinfo/sfdisk.$part.make.bsi 2>&1`
47                                 echo $a > tmp
48                                 grep Warning tmp
49                                 if [ $? = 0 ];then
50                                 tr ' ' '\n' < tmp >tmp2
51                                 cat tmp2|awk /given/,/sfdisk/ >tmp3
52                                 currentsize=`cat tmp3|grep -m1 "("|cut -d"(" -f2 |cut -d")" -f1`
53                                 maxsize=`cat tmp3|grep -m2 "("|cut -d"(" -f2 |cut -d")" -f1|tail -n1`
54                                 sed -i "s/$currentsize/$maxsize/g" working/diskinfo/sfdisk.make.$part.bsi
55                                 else
56                                 nowarn=0
57                                 fi
58
59                                                 partprobe /dev/$part >/dev/null 2>&1
60                                                 . ./unmount-all
61                                                 sfdisk /dev/$part < working/diskinfo/sfdisk.$part.make.bsi
62                                                 fi