From d93b0f529cdf132369b0dd450dadb5bae0ae799b Mon Sep 17 00:00:00 2001 From: natemaia Date: Sun, 20 Jan 2019 15:40:59 -0800 Subject: [PATCH] Update partition list handling --- src/archlabs-installer | 45 ++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/archlabs-installer b/src/archlabs-installer index 227b820..d75ea99 100755 --- a/src/archlabs-installer +++ b/src/archlabs-installer @@ -904,6 +904,16 @@ format_as() errshow "${FS_CMDS[$2]} $1" && FORMATTED+=" $part" } +decr_pcount() +{ + for i in $(printf "%s" "$@"); do + if (( COUNT > 0 )); then + PARTS="$(sed "/${i//\//\\/}/d" <<< "$PARTS")" + (( COUNT-- )) + fi + done +} + enable_swap() { if [[ $1 == "$MNT/swapfile" && $SWAP_SIZE ]]; then @@ -939,16 +949,15 @@ select_device() [[ $1 == 'boot' ]] && msg="$_DevSelTitle for bootloader\n" || umount_dir $MNT if [[ $DEV_COUNT -eq 1 && $SYS_DEVS ]]; then - # auto select without mention (it's annoying) DEVICE="$(awk '{print $1}' <<< "$SYS_DEVS")" elif (( DEV_COUNT > 1 )); then tput civis - DEVICE="$(menubox "$_DevSelTitle " "${msg}$_DevSelBody" $SYS_DEVS)" || return 1 + DEVICE="$(menubox "$_DevSelTitle " "${msg}$_DevSelBody" $SYS_DEVS)" + [[ $DEVICE ]] || return 1 elif [[ $DEV_COUNT -lt 1 && $1 != 'boot' ]]; then msgbox "$_ErrTitle" "\nNo available devices to use.\n$_Exit"; die 1 fi - # if the device selected was for bootloader, set the BOOT_DEVICE [[ $1 == 'boot' ]] && BOOT_DEVICE="$DEVICE" return 0 @@ -958,10 +967,10 @@ confirm_mount() { local part="$1" mount="$2" [[ $mount == "$MNT" ]] && local m="/ (root)" || local m="${mount#$MNT}" + if [[ $(mount) == *"$mount"* ]]; then infobox "$_MntTitle" "$_MntSucc\nPartition: $part\nMountpoint: $m\n" 1 - PARTS="$(sed "s~${part} [0-9]*[G-M]~~; s~${part} [0-9]*\.[0-9]*[G-M]~~" <<< "$PARTS")" - (( COUNT > 0 )) && (( COUNT-- )) + decr_pcount $part else infobox "$_MntTitle" "$_MntFail\n$msg\n" 1 return 1 @@ -1053,8 +1062,7 @@ auto_partition() sleep 0.5 AUTO_ROOT_PART="$(lsblk -lno NAME,TYPE $device | awk 'NR == 3 {print "/dev/"$1}')" mkfs.ext4 -q $AUTO_ROOT_PART >/dev/null 2>&1 - tput civis - sleep 0.5 + tput civis; sleep 0.5 msgbox "$_PrepParts" "\nAuto partitioning complete.\n\n$(lsblk -o NAME,MODEL,SIZE,TYPE,FSTYPE $device)\n" } @@ -1082,7 +1090,7 @@ find_partitions() local str="$1" err='' # string of partitions as /TYPE/PART SIZE - if [[ $IGNORE_DEV != "" ]]; then + if [[ $IGNORE_DEV ]]; then PARTS="$(lsblk -lno TYPE,NAME,SIZE | awk "/$str/"' && !'"/$IGNORE_DEV/"' { sub(/^part/, "/dev/"); @@ -1139,12 +1147,18 @@ mount_menu() lvm_detect umount_dir $MNT find_partitions 'part|lvm|crypt' || { SEL=2; return 1; } + + [[ $LUKS_PART ]] && decr_pcount $LUKS_PART + [[ $LVM_PARTS ]] && decr_pcount $LVM_PARTS + select_root_partition || return 1 + if [[ $SYS == "UEFI" ]]; then select_efi_partition || { BOOT_PART=""; return 1; } elif (( COUNT > 0 )); then select_boot_partition || { BOOT_PART=""; return 1; } fi + setup_boot || return 1 select_swap || return 1 select_extra_partitions || return 1 @@ -1174,9 +1188,8 @@ select_swap() enable_swap "$MNT/swapfile" SWAP_PART="/swapfile" else - enable_swap "$SWAP_PART" - PARTS="$(sed "s~${SWAP_PART} [0-9]*[G-M]~~; s~${SWAP_PART} [0-9]*\.[0-9]*[G-M]~~" <<< "$PARTS")" - (( COUNT > 0 )) && (( COUNT-- )) + enable_swap $SWAP_PART + decr_pcount $SWAP_PART SWAP_SIZE="$(lsblk -lno SIZE $SWAP_PART)" fi return 0 @@ -1328,9 +1341,10 @@ select_root_partition() { tput civis if (( COUNT == 1 )); then - ROOT_PART="$(awk 'NF > 0 {print $1}' <<< "$PARTS")" - elif ! ROOT_PART="$(menubox "$_PrepMount" "$_SelRootBody" $PARTS)"; then - return 1 + ROOT_PART="$(awk 'NR==1 {print $1}' <<< "$PARTS")" + else + ROOT_PART="$(menubox "$_PrepMount" "$_SelRootBody" $PARTS)" + [[ $ROOT_PART ]] || return 1 fi select_filesystem "$ROOT_PART" || { ROOT_PART=""; return 1; } @@ -1492,8 +1506,9 @@ create_user() fi fi - printf "Creating user $NEWUSER with: useradd -m -u 1000 -g users -G $groups -s $MYSHELL $NEWUSER\n" local groups='audio,autologin,floppy,log,network,rfkill,scanner,storage,optical,power,wheel' + + printf "Creating user $NEWUSER with: useradd -m -u 1000 -g users -G $groups -s $MYSHELL $NEWUSER\n" chrun "groupadd -r autologin" 2>$ERR errshow 1 "groupadd -r autologin" chrun "useradd -m -u 1000 -g users -G $groups -s $MYSHELL $NEWUSER" 2>$ERR