dragora-installer: apply fixes and minor changes
[dragora.git] / archive / dragora-installer / parts / MenuBootloader
blob441513b5799fbe0b5a34e3a6e2d874e0335fd4de
1 #! /bin/bash -
3 # This file is part of the 'dragora-installer'.
5 # Purpose: Installation of GRUB boot loader into /media/dragora-root.
7 # Exit immediately on any error
8 set -e
10 # Make sure to have /proc and /dev available to install GRUB
11 if ! mountpoint -q /media/dragora-root/dev
12 then
13 mount --bind /dev /media/dragora-root/dev
15 if ! mountpoint -q /media/dragora-root/proc
16 then
17 mount -t proc proc /media/dragora-root/proc
19 if ! mountpoint -q /media/dragora-root/sys
20 then
21 mount -t sysfs sysfs /media/dragora-root/sys
24 # Loop for the main menu
25 while true
27 dialog --colors \
28 --backtitle "\ZbBoot loader installation" \
29 --title "GRand Unified Bootloader" \
30 --default-button "${_default_button:-ok}" \
31 --ok-label "Install / Reinstall" \
32 --cancel-label "Ignore & Continue" \
33 --menu \
34 "It's time to install a boot loader (GNU GRUB).\n\n\
35 If you do not have a boot loader, it is recommended to install it in\n\
36 the Master Boot Record (MBR). It is possible to overwrite your current \
37 boot loader.\n\n\
38 You can also install the boot loader on the Root partition (superblock), \
39 but note that the partition needs the boot flag to boot. If you have not \
40 used this flag before when you created the partitions you can do so later \
41 by invoking 'cfdisk' or 'fdisk'." 19 72 2 \
42 "0" "Install GRUB on the Master Boot Record" \
43 "1" "Install GRUB on the Super block" \
44 2> ${SUBTMPDIR}/return-MenuBootloader || _status=$?
45 if test -n "$_status" && test $_status -gt 0
46 then
47 if test $_status -eq 1
48 then
49 # Ignore exit status on 'cancel'
50 return 0
52 # Any other dialogs code.
53 return $_status
56 answer="$(cat -- ${SUBTMPDIR}/return-MenuBootloader)"
58 # Check for selected options
59 case $answer in
60 0 | 1) ## Master Boot Record or Super block
62 # Defining the title of the subsequent menu
63 if test "$answer" = 0
64 then
65 _submenu_title="Master Boot Record"
66 else
67 _submenu_title="Super block"
70 # Check if it is a logical volume
71 if pvs | grep -q dev
72 then
73 array=( $(pvs --ignorelockingfailure --noheadings | awk '{ print $1 }') )
75 # Verify on which partition to install
76 if (( ${#array[*]} > 1 ))
77 then
78 i=0 ; for partition in "${array[@]}"
80 partition="${partition/[0-9]*/}"
81 xlist[i++]=$partition
82 xlist[i++]=""
83 done
84 unset i partition
86 # Remove possible duplicate elements
87 xlist=( $(echo "${xlist[@]}" | awk '!s[$0]++') )
89 dialog --colors \
90 --backtitle "\ZbBoot loader installation" \
91 --title "$_submenu_title" \
92 --menu \
93 "More than one disk or partition has been detected.\n\n\
94 Please select the boot loader destination:" 0 0 0 "${xlist[@]}" \
95 2> ${SUBTMPDIR}/return-MenuBootloader_cases || continue;
96 BOOT_DEVICE="$(cat -- ${SUBTMPDIR}/return-MenuBootloader_cases)"
97 else
98 BOOT_DEVICE="${array[0]}"
101 unset array
103 unset _submenu_title
105 # To fallback if 'BOOT_DEVICE' is not defined, null
106 BOOT_DEVICE="${BOOT_DEVICE:=$(cat -- ${SUBTMPDIR}/root_device)}"
108 # If the super block was not chosen, we don't need
109 # the device number to install in the MBR
110 if test "$answer" != 1
111 then
112 BOOT_DEVICE="${BOOT_DEVICE/[0-9]*/}"
114 unset answer
116 # GRUB Installation
117 dialog --colors \
118 --backtitle "\ZbGRUB: Installing the boot loader" \
119 --title "Installing GRUB on $BOOT_DEVICE" \
120 --prgbox \
121 "chroot /media/dragora-root /usr/sbin/grub-install --force $BOOT_DEVICE && echo \"^ Return status = $?\ " $(( $LINES - 8 )) $COLUMNS
123 # GRUB config file
124 dialog --colors \
125 --backtitle "\ZbGRUB: Generating configuration file" \
126 --title "Generating grub.cfg" \
127 --prgbox \
128 "chroot /media/dragora-root /usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg && echo \"^ Return status = $?\"" $(( $LINES - 8 )) $COLUMNS
130 unset BOOT_DEVICE
131 _default_button=cancel
132 continue;
134 esac
135 done