[1] | 1 | #!/bin/sh
|
---|
| 2 |
|
---|
| 3 |
|
---|
[3057] | 4 | if [ "$#" -ne "2" ] && [ "$#" -ne "3" ] ; then
|
---|
| 5 | echo "make-me-bootable <fname> <drive> [noaction]"
|
---|
[1] | 6 | exit 1
|
---|
| 7 | fi
|
---|
| 8 |
|
---|
[3057] | 9 | drivetouse=$2
|
---|
[1] | 10 | boot_drv=""
|
---|
| 11 | boot_part=""
|
---|
| 12 | root_drv=""
|
---|
| 13 | root_part=""
|
---|
[3057] | 14 | if [ ! "$LOGFILE" ]; then
|
---|
| 15 | LOGFILE="/tmp/mondorestore2.log"
|
---|
| 16 | fi
|
---|
| 17 | dummy="$3"
|
---|
[1] | 18 |
|
---|
[3377] | 19 | activepart=`mr-parted2fdisk -l $drivetouse 2>/dev/null | tr -s '\t' ' ' | grep "$drivetouse" | grep '*' | cut -d' ' -f1`
|
---|
[3057] | 20 |
|
---|
[680] | 21 | for i in `cat $1 | tr -s '\t' ' ' | cut -d' ' -f1 | grep -vE "/dev/fd|none|#"` ; do
|
---|
[2196] | 22 | # Warning wrong if LVM !
|
---|
[1] | 23 | drive=`echo $i | sed -e 's/[0-9]*$//' -e 's/\([0-9]\)p$/\1/'`
|
---|
[3057] | 24 | if [ "$drivetouse" = "$drive" ]; then
|
---|
| 25 | # We can continue as this is the drive we ned to work on
|
---|
| 26 | partno=`echo $i | sed -e 's/^.*[^0-9]\([0-9]*\)$/\1/'`
|
---|
| 27 | mountpt=`grep "$i " $1 | tr -s '\t' ' ' | cut -d' ' -f2`
|
---|
[1] | 28 |
|
---|
| 29 | if [ "$mountpt" = "/" ] ; then
|
---|
| 30 | root_drv=$drive
|
---|
[3057] | 31 | root_part=$partno
|
---|
[1] | 32 | elif [ "$mountpt" = "/boot" ] ; then
|
---|
| 33 | boot_drv=$drive
|
---|
| 34 | boot_part=$partno
|
---|
| 35 | fi
|
---|
| 36 | fi
|
---|
| 37 | done
|
---|
| 38 |
|
---|
| 39 | if [ "$boot_drv" ] ; then
|
---|
| 40 | drive=$boot_drv
|
---|
| 41 | partno=$boot_part
|
---|
| 42 | elif [ "$root_drv" ] ; then
|
---|
| 43 | drive=$root_drv
|
---|
| 44 | partno=$root_part
|
---|
| 45 | else
|
---|
[911] | 46 | driveline=`grep -E '[ ]/boot[ ]' $1`
|
---|
| 47 | [ ! "$driveline" ] && driveline=`grep -E '[ ]/[ ]' $1`
|
---|
[1] | 48 | partno=`echo "$driveline" | cut -d' ' -f1 | awk -F "[a-z]" '{print $NF;}'`
|
---|
| 49 | # echo "driveline=$driveline --> partno=$partno"
|
---|
| 50 | fi
|
---|
| 51 |
|
---|
| 52 | if [ "$drive" ] ; then
|
---|
[3057] | 53 | if [ "$partno" = "0" ] || [ ! "$partno" ] ; then
|
---|
| 54 | partno="1"
|
---|
| 55 | fi
|
---|
| 56 | cmd=""
|
---|
| 57 | for p in "$activepart"; do
|
---|
| 58 | # First desactivate active partitions (coming from previous usage)
|
---|
| 59 | cmd="${cmd}a\n$p\n"
|
---|
| 60 | if [ "$dummy" != "" ] ; then
|
---|
| 61 | echo "Will desactivate $p on $drive" >> $LOGFILE
|
---|
| 62 | fi
|
---|
| 63 | done
|
---|
| 64 | # Then activate the one which should
|
---|
[1] | 65 | if [ "$dummy" != "" ] ; then
|
---|
[3071] | 66 | echo "Would activate $partno on $drive" >> $LOGFILE
|
---|
[3057] | 67 | else
|
---|
[3377] | 68 | echo -en "${cmd}a\n$partno\np\nw\n" | mr-parted2fdisk $drive >> $LOGFILE 2>> $LOGFILE
|
---|
[3057] | 69 | fi
|
---|
[1] | 70 | fi
|
---|
| 71 | exit 0
|
---|