You've already forked al-installer
Fix other bootloaders being deleted, add option to add grub as default bootloader
This commit is contained in:
160
src/installer
160
src/installer
@ -15,7 +15,7 @@
|
||||
# immutable variables {
|
||||
|
||||
readonly DIST="Archlabs" # Linux distributor
|
||||
readonly VER="1.6.28" # Installer version
|
||||
readonly VER="1.6.29" # Installer version
|
||||
readonly LIVE="liveuser" # Live session user
|
||||
readonly TRN="/usr/share/archlabs-installer" # Translation path
|
||||
readonly MNT="/mnt/install" # Install mountpoint
|
||||
@ -148,6 +148,7 @@ initialize_variables() {
|
||||
declare -g BOOT_DONE=false
|
||||
declare -g FULL_DONE=false
|
||||
declare -g CONFIRM_DONE=false
|
||||
declare -g GRUB_UEFI_FALLBACK=false
|
||||
|
||||
# Commands used to install each bootloader.
|
||||
# NOTE: syslinux and grub in particular can/will change during runtime
|
||||
@ -330,18 +331,6 @@ check_base_unpacked() {
|
||||
return 1
|
||||
}
|
||||
|
||||
decrease_part_count() {
|
||||
# remove a partition from the dialog list and decrement the number partitions left
|
||||
local p="$1"
|
||||
PARTS="$(sed "s~${p} [0-9]*[G-M]~~; s~${p} [0-9]*\.[0-9]*[G-M]~~" <<< "$PARTS")"
|
||||
(( COUNT > 0 )) && (( COUNT-- ))
|
||||
return 0
|
||||
}
|
||||
|
||||
######################################################################
|
||||
## Dialog Functions ##
|
||||
######################################################################
|
||||
|
||||
getinput() {
|
||||
local answer
|
||||
answer="$(dialog --cr-wrap --max-input 63 --stdout --backtitle "$BT" --title " $1 " --inputbox "$2" 0 0 "$3")"
|
||||
@ -433,8 +422,8 @@ EOF
|
||||
set_locale() {
|
||||
local locale
|
||||
tput civis
|
||||
locale="$(dialog --cr-wrap --stdout --backtitle "$BT" --title "$_ConfLocale" \
|
||||
--menu "$_LocaleBody" 25 70 12 $LOCALES)"
|
||||
locale="$(dialog --cr-wrap --stdout --no-cancel --backtitle "$BT" \
|
||||
--title "$_ConfLocale" --menu "$_LocaleBody" 25 70 12 $LOCALES)"
|
||||
[[ $? != 0 || $locale == "" ]] && return 1
|
||||
|
||||
infobox "$_ConfLocale" "$_GenLocale $locale\n"
|
||||
@ -450,16 +439,14 @@ set_locale() {
|
||||
}
|
||||
|
||||
set_timezone() {
|
||||
local zone subzone
|
||||
|
||||
tput civis
|
||||
zone="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_TimeZTitle " \
|
||||
--menu "$_TimeZBody" 20 70 10 $ZONES)"
|
||||
[[ $? != 0 || $zone == "" ]] && return 1
|
||||
|
||||
subzone="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_TimeZTitle " \
|
||||
--menu "$_TimeSubZBody" 20 70 12 ${SUBZONES[$zone]})"
|
||||
[[ $? != 0 || $subzone == "" ]] && return 1
|
||||
local zone
|
||||
zone="$(dialog --cr-wrap --stdout --no-cancel --backtitle "$BT" \
|
||||
--title " $_TimeZTitle " --menu "$_TimeZBody" 20 70 10 $ZONES)"
|
||||
local subzone
|
||||
subzone="$(dialog --cr-wrap --stdout --no-cancel --backtitle "$BT" \
|
||||
--title " $_TimeZTitle " --menu "$_TimeSubZBody" 20 70 12 ${SUBZONES[$zone]})"
|
||||
|
||||
if yesno "$_TimeZTitle" "$_TimeZQ $zone/$subzone?\n"; then
|
||||
chroot_cmd "ln -sf /usr/share/zoneinfo/$zone/$subzone /etc/localtime" 2>$ERR
|
||||
@ -474,9 +461,9 @@ set_timezone() {
|
||||
|
||||
set_hwclock() {
|
||||
chroot_cmd "hwclock --systohc --utc"
|
||||
if (( $? != 0 )); then
|
||||
if [[ $? != 0 ]]; then
|
||||
chroot_cmd "hwclock --systohc --utc --directisa"
|
||||
(( $? != 0 )) && infobox "$_ErrTitle" "\nHwclock setup attempts failed.\n\nContinuing anyway.\n"
|
||||
[[ $? != 0 ]] && infobox "$_ErrTitle" "\nHwclock setup attempts failed.\n\nContinuing anyway.\n"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
@ -500,10 +487,9 @@ EOF
|
||||
user_input_values() {
|
||||
local user="$1"
|
||||
tput cnorm
|
||||
|
||||
local values
|
||||
if [[ $SET_ROOT_PASSWD != true ]]; then
|
||||
values="$(dialog --stdout --separator '~' --ok-label "Submit" --backtitle "$BT" \
|
||||
values="$(dialog --stdout --no-cancel --separator '~' --ok-label "Submit" --backtitle "$BT" \
|
||||
--title " $_UserTitle " --insecure --mixedform "$_UserBody" 27 75 10 \
|
||||
"$_Username" 1 1 "$user" 1 $((${#_Username} + 2)) 71 0 0 \
|
||||
"$_Password" 2 1 "" 2 $((${#_Password} + 2)) 71 0 1 \
|
||||
@ -512,7 +498,7 @@ user_input_values() {
|
||||
"$_Password" 8 1 "" 8 $((${#_Password} + 2)) 71 0 1 \
|
||||
"$_Password2" 9 1 "" 9 $((${#_Password2} + 2)) 71 0 1)"
|
||||
else
|
||||
values="$(dialog --stdout --separator '~' --ok-label "Submit" --backtitle "$BT" \
|
||||
values="$(dialog --stdout --no-cancel --separator '~' --ok-label "Submit" --backtitle "$BT" \
|
||||
--title " $_UserTitle " --insecure --mixedform "$_UserBody" 20 75 4 \
|
||||
"$_Username" 1 1 "$user" 1 $((${#_Username} + 2)) 71 0 0 \
|
||||
"$_Password" 2 1 "" 2 $((${#_Password} + 2)) 71 0 1 \
|
||||
@ -706,6 +692,14 @@ choose_window_manager() {
|
||||
## System Partitioning Functions ##
|
||||
######################################################################
|
||||
|
||||
decrease_part_count() {
|
||||
# remove a partition from the dialog list and decrement the number partitions left
|
||||
local p="$1"
|
||||
PARTS="$(sed "s~${p} [0-9]*[G-M]~~; s~${p} [0-9]*\.[0-9]*[G-M]~~" <<< "$PARTS")"
|
||||
(( COUNT > 0 )) && (( COUNT-- ))
|
||||
return 0
|
||||
}
|
||||
|
||||
wipe_device() {
|
||||
local device="$1"
|
||||
if yesno "$_PartWipe" "$_PartBody1 $device $_PartWipeBody2"; then
|
||||
@ -807,15 +801,13 @@ auto_partition() {
|
||||
# confirm or bail
|
||||
yesno "$_PrepParts" "$_PartBody1 $device $_PartBody2" || return 0
|
||||
infobox "$_PrepParts" "\nAuto partitioning device: $device\n"
|
||||
|
||||
swapoff -a # make sure swap is disabled
|
||||
|
||||
# partition number of each partition on the device in reverse order
|
||||
local dev_info="$(parted -s $device print)"
|
||||
|
||||
# partition number of each partition on the device NOTE: MUST be in reverse order
|
||||
for part in $(awk '/^ [1-9][0-9]?/ {print $1}' <<< "$dev_info" | sort -r); do
|
||||
parted -s "$device" rm $part 2>$ERR
|
||||
check_for_errors "parted -s $device rm $part" || { break; return 1; }
|
||||
for i in $(awk '/^ [1-9][0-9]?/ {print $1}' <<< "$dev_info" | sort -r); do
|
||||
parted -s $device rm $i 2>$ERR
|
||||
check_for_errors "parted -s $device rm $i" || { break; return 1; }
|
||||
done
|
||||
|
||||
# make sure we have the correct device table for the system type, gpt or msdos
|
||||
@ -827,7 +819,7 @@ auto_partition() {
|
||||
fi
|
||||
|
||||
# if the current device table isn't correct run mklabel
|
||||
if [[ "$table" != "$newtable" ]]; then
|
||||
if [[ $table != "$newtable" ]]; then
|
||||
parted -s $device mklabel $newtable 2>$ERR
|
||||
check_for_errors "parted -s $device mklabel $newtable" || return 1
|
||||
fi
|
||||
@ -845,6 +837,8 @@ auto_partition() {
|
||||
check_for_errors "parted -s $device mkpart ESP fat32 1MiB 513MiB" || { BOOT_PART=""; return 1; }
|
||||
mkfs.vfat -F32 $BOOT_PART >/dev/null 2>$ERR
|
||||
check_for_errors "mkfs.vfat -F32 $BOOT_PART" || { BOOT_PART=""; return 1; }
|
||||
parted -s $device set 1 esp on 2>$ERR
|
||||
check_for_errors "parted -s $device set 1 esp on" || { BOOT_PART=""; return 1; }
|
||||
fi
|
||||
|
||||
parted -s $device set 1 boot on 2>$ERR
|
||||
@ -925,7 +919,7 @@ select_swap() {
|
||||
check_for_errors "swapon $MNT/swapfile" || return 1
|
||||
SWAP_FILE="/swapfile"
|
||||
else
|
||||
# Warn user if creating a new swap
|
||||
# Warn user if creating a new swap on the chosen partition
|
||||
if ! grep -qi "swap" <<< "$(lsblk -o FSTYPE $SWAP)"; then
|
||||
yesno "$_PrepMount" "\nmkswap $SWAP\n" || return 0
|
||||
mkswap $SWAP >/dev/null 2>$ERR
|
||||
@ -988,22 +982,18 @@ select_filesystem() {
|
||||
local part="$1"
|
||||
local cur_fs
|
||||
cur_fs="$(lsblk -lno FSTYPE $part)"
|
||||
|
||||
tput civis
|
||||
|
||||
local choice
|
||||
choice="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_FSTitle: $part" \
|
||||
--menu "\nPartition: ${part}$([[ $cur_fs != "" ]] && echo -n "\nCurrent: ${cur_fs}")\n$_FSBody" 0 0 0 $([[ $cur_fs != "" ]] && echo -n "$_Skip -") \
|
||||
--menu "\nPartition: ${part}$([[ $cur_fs != "" ]] && echo -n "\nCurrent: ${cur_fs}")\n$_FSBody" 0 0 0 \
|
||||
$([[ $cur_fs != "" ]] && echo -n "$_Skip -") \
|
||||
"ext4" "${FS_CMDS[ext4]}" "ext3" "${FS_CMDS[ext3]}" \
|
||||
"ext2" "${FS_CMDS[ext2]}" "vfat" "${FS_CMDS[vfat]}" \
|
||||
"ntfs" "${FS_CMDS[ntfs]}" "f2fs" "${FS_CMDS[f2fs]}" \
|
||||
"jfs" "${FS_CMDS[jfs]}" "nilfs2" "${FS_CMDS[nilfs2]}" \
|
||||
"reiserfs" "${FS_CMDS[reiserfs]}" "xfs" "${FS_CMDS[xfs]}")"
|
||||
if [[ $choice == "$_Skip" ]]; then
|
||||
return 0
|
||||
elif [[ $choice == "" ]]; then
|
||||
return 1
|
||||
fi
|
||||
[[ $choice == "$_Skip" ]] && return 0
|
||||
[[ $? != 0 || $choice == "" ]] && return 1
|
||||
|
||||
if yesno "$_FSTitle" "\nFormat $part as $choice?\n"; then
|
||||
infobox "$_FSTitle" "\nFormatting: $part\n\nCommand: ${FS_CMDS[$choice]}\n"
|
||||
@ -1019,31 +1009,34 @@ select_filesystem() {
|
||||
select_boot_setup() {
|
||||
# choose bootloader and by extension mountpoint (if needed)
|
||||
tput civis
|
||||
BOOTLOADER="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_PrepMount " \
|
||||
--menu "$_MntBootBody" 0 0 0 ${BOOTLOADERS[$SYS]})"
|
||||
BOOTLOADER="$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_PrepMount " --menu "$_MntBootBody" 0 0 0 ${BOOTLOADERS[$SYS]})"
|
||||
[[ $? != 0 || $BOOTLOADER == "" ]] && return 1
|
||||
|
||||
if [[ $SYS == "BIOS" ]]; then
|
||||
if [[ $SYS == 'BIOS' ]]; then
|
||||
if [[ $BOOTLOADER == "grub" && $BOOT_DEVICE == "" ]]; then
|
||||
# grub BIOS needs an install device eg. /dev/sda
|
||||
select_device 'boot' || return 1
|
||||
BOOT_DEVICE="$DEVICE"
|
||||
|
||||
elif [[ $BOOTLOADER == "syslinux" ]]; then
|
||||
else
|
||||
local cmd
|
||||
cmd="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_InstSysTitle " \
|
||||
--menu "$_InstSysBody\nDefault: ${BOOT_CMDS[syslinux]}" 0 0 0 \
|
||||
"syslinux-install_update -iam" "[MBR]" \
|
||||
"syslinux-install_update -i" "[/]")"
|
||||
case $cmd in
|
||||
"syslinux-install_update -iam"|"syslinux-install_update -i")
|
||||
BOOT_CMDS[syslinux]="$cmd"
|
||||
EDIT_FILES[8]="/boot/syslinux/syslinux.cfg" ;;
|
||||
*) return 1
|
||||
esac
|
||||
[[ $? != 0 || $cmd == "" ]] && return 1
|
||||
BOOT_CMDS[syslinux]="$cmd"
|
||||
EDIT_FILES[8]="/boot/syslinux/syslinux.cfg" ;;
|
||||
fi
|
||||
else
|
||||
if [[ $BOOTLOADER == 'systemd-boot' ]]; then
|
||||
EDIT_FILES[8]="/boot/loader/entries/archlabs.conf"
|
||||
else
|
||||
EDIT_FILES[8]="/etc/default/grub"
|
||||
if yesno "$_PrepMount" "$_SetBootDefault"; then
|
||||
GRUB_UEFI_FALLBACK=true
|
||||
fi
|
||||
fi
|
||||
elif [[ $BOOTLOADER == "systemd-boot" ]]; then
|
||||
EDIT_FILES[8]="/boot/loader/entries/archlabs.conf"
|
||||
fi
|
||||
|
||||
# if BOOT_PART was set, mount the partition to the correct mountpoint
|
||||
@ -2082,26 +2075,20 @@ EOF
|
||||
}
|
||||
|
||||
grub_uefi_fallback() {
|
||||
# some UEFI firmware is finicky and requires special treatment this loops
|
||||
# /boot/efi/EFI or /boot/efi/EFI and finds a directory named 'boot' 'Boot' 'BOOT'
|
||||
# once/if found we copy grub's efi stub binary to that directory as bootx64.efi
|
||||
local esp="${MNT}${BOOT_MNTS[$SYS-$BOOTLOADER]}"
|
||||
# some UEFI firmware is finicky and requires a specific folder in
|
||||
# /boot/efi/EFI/ and named 'boot', 'Boot', or 'BOOT'
|
||||
local fb="boot"
|
||||
|
||||
for i in $(find "$esp/EFI" -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do
|
||||
local esp="${MNT}${BOOT_MNTS[$SYS-$BOOTLOADER]}/EFI/"
|
||||
for i in $(find "$esp" -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do
|
||||
if grep -qi "boot" <<< "$(basename $i)"; then
|
||||
fb="$(basename $i)"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
mkdir -p $esp/EFI/$fb
|
||||
cp -f $esp/EFI/$DIST/grubx64.efi $esp/EFI/$fb/grubx64.efi
|
||||
|
||||
if [[ ! -e $esp/EFI/$fb/bootx64.efi ]]; then
|
||||
cp -f $esp/EFI/$DIST/grubx64.efi $esp/EFI/$fb/bootx64.efi
|
||||
fi
|
||||
|
||||
# copy grub's efi stub binary to that directory as $stub
|
||||
mkdir -p ${esp}$fb
|
||||
cp -f ${esp}$DIST/grubx64.efi ${esp}$fb/bootx64.efi
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -2113,16 +2100,20 @@ setup_bootloader() {
|
||||
|
||||
infobox "$_InstBootTitle" "$msg\nMountpoint: ${BOOT_MNTS[$SYS-$BOOTLOADER]}\n"
|
||||
|
||||
if [[ $SYS == "UEFI" ]] && grep -q "/sys/firmware/efi/efivars" <<< "$(mount)"; then
|
||||
if [[ $SYS == "UEFI" ]]; then
|
||||
# ensure efivarfs is mounted in host and in chroot
|
||||
local eficmd="mount -o remount,rw -t efivarfs efivarfs /sys/firmware/efi/efivars"
|
||||
$eficmd >/dev/null 2>&1
|
||||
BOOT_CMDS[$BOOTLOADER]="$eficmd ; ${BOOT_CMDS[$BOOTLOADER]}"
|
||||
|
||||
# remove old EFI boot entries from previous installs
|
||||
find $MNT/boot/efi/EFI/ -name '[aA][rR][cC][hH][lL]abs*' \
|
||||
-type d -exec rm -rf '{}' \; 2>/dev/null
|
||||
find $MNT/boot/efi/EFI/ -name '[Bb][oO][oO][tT]' \
|
||||
-type d -exec rm -rf '{}' \; 2>/dev/null
|
||||
find $MNT/boot/efi/EFI/ -maxdepth 1 -mindepth 1 -name '[aA][rR][cC][hH][lL]abs*' \
|
||||
-type d -exec rm -rf '{}' \; >/dev/null 2>&1
|
||||
|
||||
if [[ $GRUB_UEFI_FALLBACK == true ]]; then
|
||||
find $MNT/boot/efi/EFI/ -maxdepth 1 -mindepth 1 -name '[Bb][oO][oO][tT]' \
|
||||
-type d -exec rm -rf '{}' \; >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
|
||||
# grub is finicky and requires special treatment
|
||||
@ -2132,7 +2123,7 @@ setup_bootloader() {
|
||||
$udevcmd >/dev/null 2>&1
|
||||
BOOT_CMDS[grub]="$udevcmd ; ${BOOT_CMDS[grub]}"
|
||||
|
||||
# BIOS uses the base device name, eg. /dev/sda
|
||||
# BIOS uses the base device name, eg. /dev/sda.. so add it to the end of BOOT_CMDS[grub]
|
||||
[[ $SYS == "BIOS" ]] && BOOT_CMDS[grub]="${BOOT_CMDS[grub]} $BOOT_DEVICE"
|
||||
|
||||
# add grub-mkconfig last
|
||||
@ -2144,20 +2135,19 @@ setup_bootloader() {
|
||||
BOOT_CMDS[$BOOTLOADER]="pacman -Rs grub --noconfirm && ${BOOT_CMDS[$BOOTLOADER]}"
|
||||
fi
|
||||
|
||||
# create bootloader config first, grub and systemd-boot require this
|
||||
# create the bootloader configs and run the setup commands, BOOT_CMDS[$BOOTLOADER]
|
||||
bootloader_config
|
||||
|
||||
# install the selected bootloader using the array command
|
||||
chroot_cmd "${BOOT_CMDS[$BOOTLOADER]}" 2>$ERR >/dev/null 2>&1
|
||||
check_for_errors "${BOOT_CMDS[$BOOTLOADER]}" || return 1
|
||||
|
||||
[[ $SYS == "UEFI" && $BOOTLOADER == "grub" ]] && grub_uefi_fallback
|
||||
# copy grub efi stub to generic catch all
|
||||
[[ $GRUB_UEFI_FALLBACK == true ]] && grub_uefi_fallback
|
||||
|
||||
BOOT_DONE=true
|
||||
|
||||
if [[ $LUKS -eq 1 && $SYS != "BIOS" && $BOOTLOADER == "grub" ]]; then
|
||||
if [[ $LUKS_PASS && $LUKS_UUID ]]; then
|
||||
luks_keyfile || return 1
|
||||
fi
|
||||
# offer to setup a keyfile for LUKS.. Only when choosing grub and system is UEFI
|
||||
if [[ $LUKS -eq 1 && $SYS == 'UEFI' && $BOOTLOADER == 'grub' && $LUKS_PASS && $LUKS_UUID ]]; then
|
||||
luks_keyfile || return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
@ -2179,7 +2169,7 @@ run_mkinitcpio() {
|
||||
|
||||
tput civis
|
||||
chroot_cmd "mkinitcpio -p linux" 2>$ERR | dialog --cr-wrap --backtitle "$BT" \
|
||||
--title " $_RunMkinit " --progressbox "$_RunMkinitBody\nAdded HOOKS: $MKINIT_HOOKS $add\n" 30 90
|
||||
--title " $_RunMkinit " --progressbox "$_RunMkinitBody\nHOOKS: $MKINIT_HOOKS $add\n" 30 90
|
||||
check_for_errors "mkinitcpio -p linux" || return 1
|
||||
|
||||
return 0
|
||||
|
Reference in New Issue
Block a user