1 | #!/bin/sh
|
---|
2 |
|
---|
3 |
|
---|
4 | if [ "$#" -ne "2" ] && [ "$#" -ne "3" ] ; then
|
---|
5 | echo "make-me-bootable <fname> <drive> [noaction]"
|
---|
6 | exit 1
|
---|
7 | fi
|
---|
8 |
|
---|
9 | drivetouse=$2
|
---|
10 | boot_drv=""
|
---|
11 | boot_part=""
|
---|
12 | root_drv=""
|
---|
13 | root_part=""
|
---|
14 | if [ ! "$LOGFILE" ]; then
|
---|
15 | LOGFILE="/tmp/mondorestore2.log"
|
---|
16 | fi
|
---|
17 | dummy="$3"
|
---|
18 |
|
---|
19 | activepart=`parted2fdisk -l $drivetouse | tr -s '\t' ' ' | grep "$drivetouse" | grep '*' | cut -d' ' -f1`
|
---|
20 |
|
---|
21 | for i in `cat $1 | tr -s '\t' ' ' | cut -d' ' -f1 | grep -vE "/dev/fd|none|#"` ; do
|
---|
22 | # Warning wrong if LVM !
|
---|
23 | drive=`echo $i | sed -e 's/[0-9]*$//' -e 's/\([0-9]\)p$/\1/'`
|
---|
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`
|
---|
28 |
|
---|
29 | if [ "$mountpt" = "/" ] ; then
|
---|
30 | root_drv=$drive
|
---|
31 | root_part=$partno
|
---|
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
|
---|
46 | driveline=`grep -E '[ ]/boot[ ]' $1`
|
---|
47 | [ ! "$driveline" ] && driveline=`grep -E '[ ]/[ ]' $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
|
---|
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
|
---|
65 | if [ "$dummy" != "" ] ; then
|
---|
66 | echo "Would activate $partno on $drive" >> $LOGFILE
|
---|
67 | else
|
---|
68 | echo -en "${cmd}a\n$partno\np\nw\n" | parted2fdisk $drive >> $LOGFILE 2>> $LOGFILE
|
---|
69 | fi
|
---|
70 | fi
|
---|
71 | exit 0
|
---|