source: MondoRescue/branches/3.2/mondo/src/restore-scripts/mondo/make-me-bootable@ 3510

Last change on this file since 3510 was 3377, checked in by Bruno Cornec, 9 years ago
  • Rename mr_parted2fdisk to mr-parted2fdisk for consistency with all other new mr-* commands
  • Adds functions mr_center_string and mr_popup_and_get_string with dynamic allocation to solve a memory allocation issue reported on the ML
  • Fix mr_boot_type to detect correctly a UEFI based system
  • Property svn:keywords set to Id
  • Property svn:unix-mode set to 755
File size: 1.9 KB
Line 
1#!/bin/sh
2
3
4if [ "$#" -ne "2" ] && [ "$#" -ne "3" ] ; then
5 echo "make-me-bootable <fname> <drive> [noaction]"
6 exit 1
7fi
8
9drivetouse=$2
10boot_drv=""
11boot_part=""
12root_drv=""
13root_part=""
14if [ ! "$LOGFILE" ]; then
15 LOGFILE="/tmp/mondorestore2.log"
16fi
17dummy="$3"
18
19activepart=`mr-parted2fdisk -l $drivetouse 2>/dev/null | tr -s '\t' ' ' | grep "$drivetouse" | grep '*' | cut -d' ' -f1`
20
21for 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
37done
38
39if [ "$boot_drv" ] ; then
40 drive=$boot_drv
41 partno=$boot_part
42elif [ "$root_drv" ] ; then
43 drive=$root_drv
44 partno=$root_part
45else
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"
50fi
51
52if [ "$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" | mr-parted2fdisk $drive >> $LOGFILE 2>> $LOGFILE
69 fi
70fi
71exit 0
Note: See TracBrowser for help on using the repository browser.