This repository has been archived on 2024-09-01. You can view files and clone it, but cannot push or open issues or pull requests.
al-installer/src/lib/mount.sh

233 lines
7.3 KiB
Bash

#!/usr/bin/bash
# vim:ft=sh:fdm=marker:fmr={,}
# archlabs installer library script file
# this file is not meant to be run directly
# sourcing this file in a non bash shell is not advised
mount_main() {
msgbox "$_PrepMount" "$_WarnMount"
lvm_detect
# prepare partition list PARTS for dialog
unmount_partitions
find_partitions 'part|lvm|crypt' || return 1
# remove boot partition from dialog list if we auto partitioned one
[[ $BOOT_PART != "" ]] && decr_count "$BOOT_PART"
select_root_partition || return 1
if [[ $BOOT_PART == "" ]]; then
if [[ $SYS == "UEFI" ]]; then
select_efi_partition || { BOOT_PART=""; return 1; }
elif (( $COUNT > 0 )); then
select_boot_partition || { BOOT_PART=""; return 1; }
fi
else
infobox "$_PrepMount" "\nUsing boot partition: $BOOT_PART\n" 1
fi
select_boot_setup || { BOOTLDR=""; return 1; }
if [[ $BOOT_PART != "" ]]; then
setup_boot_device
mount_partition "$BOOT_PART" "${BMNTS[$SYS-$BOOTLDR]}" || return 1
SEPERATE_BOOT=true
fi
select_swap || return 1
select_extra_partitions || return 1
return 0
}
select_swap() {
# Ask user to select partition or create swapfile
tput civis
SWAP="$(dialog --backtitle "$BT" --cr-wrap --stdout --title " $_SelSwpSetup " \
--menu "$_SelSwpBody" 0 0 0 "$_SelSwpNone" "-" "$_SelSwpFile" "-" $PARTS)"
[[ $? != 0 || $SWAP == "$_SelSwpNone" ]] && return 0
if [[ $SWAP == "$_SelSwpFile" ]]; then
tput cnorm
SWAP_SIZE="$(getinput "$_SelSwpSetup" "$_SelSwpSize" "${SYS_MEM}M")"
[[ $? != 0 || $SWAP_SIZE == "" ]] && return 1
while ! [[ ${SWAP_SIZE:0:1} =~ [1-9] && ${SWAP_SIZE: -1} =~ (M|G) ]]; do
msgbox "$_SelSwpSetup Error" "\n$_SelSwpErr $SWAP_SIZE\n"
SWAP_SIZE="$(getinput "$_SelSwpSetup" "$_SelSwpSize" "${SYS_MEM}M")"
[[ $? != 0 || $SWAP_SIZE == "" ]] && { break; return 1; }
done
enable_swap "$MNT/swapfile"
SWAP="/swapfile"
else
enable_swap "$SWAP"
decr_count "$SWAP"
fi
return 0
}
select_mount_opts() {
local part="$1"
local fs="$2"
local title="${fs^} Mount Options"
tput civis
MNT_OPTS="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $title " \
--checklist "$_MntBody" 0 0 0 ${FS_OPTS[$fs]} | sed 's/ /,/g; $s/,$//')"
[[ $? != 0 || $MNT_OPTS == "" ]] && return 1
if ! yesno "$title" "$_MntConfBody $MNT_OPTS\n"; then
select_mount_opts "$part" "$fs" || return 1
fi
return 0
}
select_filesystem() {
local part="$1"
local cur_fs
cur_fs="$(lsblk -lno FSTYPE $part)"
tput civis
local fs
fs="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_FSTitle: $part " \
--menu "\nPartition: ${part}$([[ $cur_fs != "" ]] && echo -en "\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 [[ $fs == "$_Skip" ]]; then
return 0
elif [[ $fs == "" ]]; then
return 1
fi
if yesno "$_FSTitle" "\nFormat $part as $fs?\n"; then
format $part $fs
else
select_filesystem $part || return 1
fi
return 0
}
select_efi_partition() {
tput civis
if (( COUNT == 1 )); then
BOOT_PART="$(awk 'NF > 0 {print $1}' <<< "$PARTS")"
infobox "$_PrepMount" "$_OnlyOne for EFI: $BOOT_PART\n" 1
else
BOOT_PART="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_PrepMount " --menu "$_SelUefiBody" 0 0 0 $PARTS)"
[[ $? != 0 || $BOOT_PART == "" ]] && return 1
fi
if grep -q 'fat' <<< "$(fsck -N "$BOOT_PART")"; then
local msg="$_FormUefiBody $BOOT_PART $_FormUefiBody2"
yesno "$_PrepMount" "$msg" "Format $BOOT_PART" "Do Not Format" "no" &&
format "$BOOT_PART" "vfat"
else
format "$BOOT_PART" "vfat"
fi
return 0
}
select_boot_partition() {
tput civis
BOOT_PART="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_PrepMount " --menu "$_SelBiosBody" 0 0 0 "$_Skip" "-" $PARTS)"
if [[ $BOOT_PART == "$_Skip" || $BOOT_PART == "" ]]; then
BOOT_PART=""
else
if grep -q 'ext[34]' <<< "$(fsck -N "$BOOT_PART")"; then
local msg="$_FormBiosBody $BOOT_PART $_FormUefiBody2"
yesno "$_PrepMount" "$msg" "Format $BOOT_PART" "Skip Formatting" "no" &&
format "$BOOT_PART" "ext4"
else
format "$BOOT_PART" "ext4"
fi
fi
return 0
}
select_root_partition() {
# if we used LUKS and no LVM or LUKS+LVM
# remove the relevant partition labels from the list
if (( LUKS == 1 && LVM == 0 )); then
ROOT_PART="/dev/mapper/$LUKS_NAME"
decr_count "$LUKS_PART"
elif (( LUKS == 1 && LVM == 1 )); then
decr_count "$LUKS_PART"
for part in $(echo "$GROUP_PARTS"); do
decr_count "$part"
done
ROOT_PART=""
elif (( LUKS == 0 && LVM == 1 )); then
for part in $(echo "$GROUP_PARTS"); do
decr_count "$part"
done
ROOT_PART=""
fi
if [[ $COUNT -eq 1 && $ROOT_PART == "" ]]; then
ROOT_PART="$(awk 'NF > 0 {print $1}' <<< "$PARTS")"
infobox "$_PrepMount" "$_OnlyOne for root (/): $ROOT_PART\n" 1
elif [[ $ROOT_PART == "" || $LVM -eq 1 ]]; then
tput civis
ROOT_PART="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_PrepMount " --menu "$_SelRootBody" 0 0 0 $PARTS)"
[[ $? != 0 || $ROOT_PART == "" ]] && return 1
else
local msg="\nUsing $([[ $LUKS -eq 1 ]] && echo -n "encrypted ")root partition:"
infobox "$_PrepMount" "$msg $ROOT_PART\n" 1
fi
select_filesystem "$ROOT_PART" || { ROOT_PART=""; return 1; }
mount_partition "$ROOT_PART" || { ROOT_PART=""; return 1; }
return 0
}
select_extra_partitions() {
while (( COUNT > 0 )); do
tput civis
local part
part="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_PrepMount " --menu "$_ExtPartBody" 0 0 0 "$_Done" "-" $PARTS)"
[[ $? != 0 || $part == "$_Done" || $part == "" ]] && break
# choose what filesystem and get mountpoint
select_filesystem "$part" || { break; return 1; }
select_mountpoint || { break; return 1; }
# mount it
mount_partition "$part" "$EXTRA_MNT" || { break; return 1; }
EXTRA_MNTS="$EXTRA_MNTS $part: $EXTRA_MNT"
# if the mountpoint was /usr add 'usr' to MKINIT_HOOKS
[[ $EXTRA_MNT == "/usr" && $MKINIT_HOOKS != *usr* ]] && MKINIT_HOOKS="usr $MKINIT_HOOKS"
done
return 0
}
select_mountpoint() {
tput cnorm
EXTRA_MNT="$(getinput "$_PrepMount $part" "$_ExtPartBody1 /home /var\n" "/")"
[[ $? != 0 || $EXTRA_MNT == "" ]] && return 1
# bad mountpoint
if [[ ${EXTRA_MNT:0:1} != "/" || ${#EXTRA_MNT} -le 1 || $EXTRA_MNT =~ \ |\' ]]; then
msgbox "$_ErrTitle" "$_ExtErrBody"
select_mountpoint || return 1
fi
return 0
}