From 77c66897f4aa2944dce1e9c98c72dfef10fc5699 Mon Sep 17 00:00:00 2001 From: natemaia Date: Sun, 18 Aug 2019 14:22:41 -0700 Subject: [PATCH] Optimize some mounting functions to only setup some variables when needed eg. when using auto partition no further setup is needed Also added dialog to give feedback when a partition is selected automatically --- archlabs-installer | 107 +++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 48 deletions(-) diff --git a/archlabs-installer b/archlabs-installer index bdc2e30..72a4384 100755 --- a/archlabs-installer +++ b/archlabs-installer @@ -5,7 +5,7 @@ # Some ideas and code reworked from other resources # AIF, Cnichi, Calamares, Arch Wiki.. Credit where credit is due -VER="2.0.50" # installer version +VER="2.0.51" # installer version DIST="ArchLabs" # linux distributor MNT="/mnt" # install mountpoint ANS="/tmp/ans" # dialog answer file @@ -1064,9 +1064,9 @@ part_cryptlv() part_countdec() { - for i in "$@"; do + for pt; do if (( COUNT > 0 )); then - PARTS="$(sed "/${i//\//\\/}/d" <<< "$PARTS")" + PARTS="$(sed "/${pt//\//\\/}/d" <<< "$PARTS")" (( COUNT-- )) fi done @@ -1199,22 +1199,26 @@ select_filesystem() select_efi_partition() { - local pts size dev isize bsize ptcount=0 - - # walk partition list and skip ones that are too small/big for boot - while read -r dev size; do - size_t="${size: -1:1}" # size type eg. K, M, G, T - isize=${size:0:-1} # remove trailing size type character - isize=${isize%.*} # remove any decimal (round down) - [[ $size_t =~ [KT] || ($size_t == 'G' && $isize -gt 2) || ($size_t == 'M' && $isize -lt 100) ]] || { pts+="$dev $size "; (( ptcount++ )); } - done <<< "$PARTS" - if [[ $AUTO_BOOT_PART ]]; then + msg "EFI Boot Partition" "\nUsing partition created during automatic format." 1 BOOT_PART="$AUTO_BOOT_PART"; return 0 # were done here - elif (( ptcount == 1 )); then - BOOT_PART="$(awk 'NF > 0 {print $1}' <<< "$pts")" else - dlg BOOT_PART menu "EFI Partition" "$_uefi" $pts + local pts size dev isize bsize ptcount=0 + + # walk partition list and skip ones that are too small/big for boot + while read -r dev size; do + size_t="${size: -1:1}" # size type eg. K, M, G, T + isize=${size:0:-1} # remove trailing size type character + isize=${isize%.*} # remove any decimal (round down) + [[ $size_t =~ [KT] || ($size_t == 'G' && $isize -gt 2) || ($size_t == 'M' && $isize -lt 100) ]] || { pts+="$dev $size "; (( ptcount++ )); } + done <<< "$PARTS" + + if (( ptcount == 1 )); then + msg "EFI Boot Partition" "\nOnly one partition that meets size requirements available." 1 + BOOT_PART="$(awk 'NF > 0 {print $1}' <<< "$pts")" + else + dlg BOOT_PART menu "EFI Partition" "$_uefi" $pts + fi fi [[ $BOOT_PART ]] || return 1 @@ -1233,24 +1237,27 @@ select_efi_partition() select_boot_partition() { - local pts size dev isize bsize ptcount=0 - - # walk partition list and skip ones that are too small/big for boot - while read -r dev size; do - size_t="${size: -1:1}" # size type eg. K, M, G, T - isize=${size:0:-1} # remove trailing size type character - isize=${isize%.*} # remove any decimal (round down) - [[ $size_t =~ [KT] || ($size_t == 'G' && $isize -gt 2) || ($size_t == 'M' && $isize -lt 100) ]] || { pts+="$dev $size "; (( ptcount++ )); } - done <<< "$PARTS" - if [[ $AUTO_BOOT_PART && ! $LVM ]]; then + msg "BIOS Boot Partition" "\nUsing partition created during automatic format." 1 BOOT_PART="$AUTO_BOOT_PART"; return 0 # were done here - elif [[ $LUKS && ! $LVM ]]; then - dlg BOOT_PART menu "Boot Partition" "$_biosluks" $pts - [[ $BOOT_PART ]] || return 1 else - dlg BOOT_PART menu "Boot Partition" "$_bios" "skip" "don't use a separate boot" $pts - [[ -z $BOOT_PART || $BOOT_PART == "skip" ]] && { BOOT_PART=''; return 0; } + local pts size dev isize bsize ptcount=0 + + # walk partition list and skip ones that are too small/big for boot + while read -r dev size; do + size_t="${size: -1:1}" # size type eg. K, M, G, T + isize=${size:0:-1} # remove trailing size type character + isize=${isize%.*} # remove any decimal (round down) + [[ $size_t =~ [KT] || ($size_t == 'G' && $isize -gt 2) || ($size_t == 'M' && $isize -lt 100) ]] || { pts+="$dev $size "; (( ptcount++ )); } + done <<< "$PARTS" + + if [[ $LUKS && ! $LVM ]]; then + dlg BOOT_PART menu "Boot Partition" "$_biosluks" $pts + [[ $BOOT_PART ]] || return 1 + else + dlg BOOT_PART menu "Boot Partition" "$_bios" "skip" "don't use a separate boot" $pts + [[ -z $BOOT_PART || $BOOT_PART == "skip" ]] && { BOOT_PART=''; return 0; } + fi fi if grep -q 'ext[34]' <<< "$(fsck -N "$BOOT_PART")"; then @@ -1266,24 +1273,28 @@ select_boot_partition() select_root_partition() { - local pts size dev isize bsize ptcount=0 - - # walk partition list and skip ones that are too small for / (root) - while read -r dev size; do - size_t="${size: -1:1}" # size type eg. K, M, G, T - isize=${size:0:-1} # remove trailing size type character - isize=${isize%.*} # remove any decimal (round down) - [[ $size_t =~ [MK] || ($size_t == 'G' && $isize -lt 4) ]] || { pts+="$dev $size "; (( ptcount++ )); } - done <<< "$PARTS" - if [[ $AUTO_ROOT_PART && -z $LVM && -z $LUKS ]]; then ROOT_PART="$AUTO_ROOT_PART" + msg "Select Root Partition (/)" "\nUsing partition created during automatic format." 1 part_mount "$ROOT_PART" || { ROOT_PART=''; return 1; } return 0 # we're done here - elif (( ptcount == 1 )); then # only one available device - ROOT_PART="$(awk 'NR==1 {print $1}' <<< "$pts")" else - dlg ROOT_PART menu "Mount Root" "\nSelect the root (/) partition, this is where $DIST will be installed.\n\nDevices smaller than 8G will not be shown here." $pts + local pts size dev isize bsize ptcount=0 + + # walk partition list and skip ones that are too small for / (root) + while read -r dev size; do + size_t="${size: -1:1}" # size type eg. K, M, G, T + isize=${size:0:-1} # remove trailing size type character + isize=${isize%.*} # remove any decimal (round down) + [[ $size_t =~ [MK] || ($size_t == 'G' && $isize -lt 4) ]] || { pts+="$dev $size "; (( ptcount++ )); } + done <<< "$PARTS" + + if (( ptcount == 1 )); then # only one available device + msg "Select Root Partition (/)" "\nOnly one partition that meets size requirements available." 1 + ROOT_PART="$(awk 'NR==1 {print $1}' <<< "$pts")" + else + dlg ROOT_PART menu "Mount Root" "\nSelect the root (/) partition, this is where $DIST will be installed.\n\nDevices smaller than 8G will not be shown here." $pts + fi fi [[ $ROOT_PART ]] || return 1 @@ -1295,16 +1306,16 @@ select_root_partition() select_extra_partitions() { - local part pts size dev isize bsize ptcount=0 + local part size dev # walk partition list and skip ones that are too small to be usable while read -r dev size; do - [[ ${size: -1:1} =~ [KM] ]] || { pts+="$dev $size "; (( ptcount++ )); } + [[ ${size: -1:1} =~ [KM] ]] && part_countdec "$dev" done <<< "$PARTS" - while (( ptcount > 0 )); do + while (( COUNT > 0 )); do part='' - dlg part menu 'Mount Extra' "$_expart" 'done' 'finish mounting step' $pts || break + dlg part menu 'Mount Extra' "$_expart" 'done' 'finish mounting step' $PARTS || break if [[ $part == 'done' ]]; then break elif select_filesystem "$part" && select_mountpoint && part_mount "$part" "$EXMNT"; then