Add fstype to partition size field, improve part_find.

This commit is contained in:
natemaia 2020-03-07 15:10:17 -08:00
parent 8472e150c3
commit b2a3db3cfd

View File

@ -5,7 +5,7 @@
# Some ideas and code reworked from other resources # Some ideas and code reworked from other resources
# AIF, Calamares, and the Arch Wiki.. Credit where credit is due # AIF, Calamares, and the Arch Wiki.. Credit where credit is due
VER=2.1.19 VER=2.1.20
# default values { # default values {
@ -641,13 +641,9 @@ part_menu()
part_show() part_show()
{ {
local txt msg "Device Tree" "\n\n$(
if [[ $IGNORE_DEV ]]; then lsblk -o NAME,MODEL,SIZE,TYPE,FSTYPE,MOUNTPOINT | awk "!/${IGNORE_DEV:-NONEXX}/"' && /disk|part|lvm|crypt|NAME/'
txt="$(lsblk -o NAME,MODEL,SIZE,TYPE,FSTYPE,MOUNTPOINT | awk "!/$IGNORE_DEV/"' && /disk|part|lvm|crypt|NAME/')" )\n\n"
else
txt="$(lsblk -o NAME,MODEL,SIZE,TYPE,FSTYPE,MOUNTPOINT | awk '/disk|part|lvm|crypt|NAME/')"
fi
msg "Device Tree" "\n\n$txt\n\n"
} }
part_auto() part_auto()
@ -696,35 +692,41 @@ part_auto()
############################################################################### ###############################################################################
# partition management functions # partition management functions
# these are helpers for use by other functions to do essential setup/teardown # these are helpers used by other functions to do essential setup/teardown
part_find() part_find()
{ {
PARTS=""
COUNT=0
local regexp="$1" err='' local regexp="$1" err=''
local pts dev size isize ptcount=0 local s dev size isize
# string of partitions as /TYPE/PART SIZE.. eg. /dev/sda1 256G # string of partitions >= 80M as /TYPE/PART SIZE__FSTYPE
if [[ $IGNORE_DEV ]]; then while read -r dev size; do
PARTS="$(lsblk -lno TYPE,NAME,SIZE | awk "/$regexp/"' && !'"/$IGNORE_DEV/"' {sub(/^part/, "/dev/"); sub(/^lvm|^crypt/, "/dev/mapper/"); print $1$2, $3}')"
else
PARTS="$(lsblk -lno TYPE,NAME,SIZE | awk "/$regexp/"' {sub(/^part/, "/dev/"); sub(/^lvm|^crypt/, "/dev/mapper/"); print $1$2 " " $3}')"
fi
# ensure we have enough partitions for the system and action were trying to do
COUNT=$(wc -l <<< "$PARTS")
while read -r dev size; do # walk partition list and skip ones that are too small
[[ $dev && $size ]] || continue [[ $dev && $size ]] || continue
size_t="${size: -1:1}" s=${size%%__*}
isize=${size:0:-1} size_t="${s: -1:1}"
isize=${s:0:-1}
isize=${isize%.*} isize=${isize%.*}
[[ $size_t == 'K' || ($size_t == 'M' && $isize -lt 100) ]] || { pts+="$dev $size "; (( ptcount++ )); } if ! [[ $size_t == 'K' || ($size_t == 'M' && $isize -lt 80) ]]; then
done <<< "$PARTS" if [[ $PARTS ]]; then
PARTS+=$'\n'"$dev $size"
else
PARTS="$dev $size"
fi
(( COUNT++ ))
fi
done < <(lsblk -lno TYPE,NAME,SIZE,FSTYPE |
awk "/$regexp/"' && !'"/${IGNORE_DEV:-NONEXX}/"' {
sub(/^part/, "/dev/")
sub(/^lvm|^crypt/, "/dev/mapper/")
print $1$2, $3"__"$4
}')
case "$regexp" in case "$regexp" in
'part|lvm|crypt') [[ $ptcount -lt 1 || ($SYS == 'UEFI' && $COUNT -lt 2) ]] && err="$_errpart" ;; 'part|lvm|crypt') [[ $COUNT -lt 1 || ($SYS == 'UEFI' && $COUNT -lt 2) ]] && err="$_errpart" ;;
'part|crypt') (( ptcount < 1 )) && err="$_lvmerr" ;; 'part|crypt') (( COUNT < 1 )) && err="$_lvmerr" ;;
'part|lvm') (( ptcount < 2 )) && err="$_lukserr" ;; 'part|lvm') (( COUNT < 2 )) && err="$_lukserr" ;;
esac esac
if [[ $err ]]; then if [[ $err ]]; then
@ -737,16 +739,18 @@ part_find()
part_swap() part_swap()
{ {
if [[ $1 == "$MNT/swapfile" && $SWAP_S ]]; then local swp="$1"
fallocate -l $SWAP_S "$1" 2> "$ERR"
errshow 0 "fallocate -l '$SWAP_S' '$1'" if [[ $swp == "$MNT/swapfile" && $SWAP_S ]]; then
chmod 600 "$1" 2> "$ERR" fallocate -l $SWAP_S "$swp" 2> "$ERR"
errshow 0 "chmod 600 '$1'" errshow 0 "fallocate -l '$SWAP_S' '$swp'"
chmod 600 "$swp" 2> "$ERR"
errshow 0 "chmod 600 '$swp'"
fi fi
mkswap "$1" > /dev/null 2> "$ERR" mkswap "$swp" > /dev/null 2> "$ERR"
errshow 0 "mkswap '$1' > /dev/null" errshow 0 "mkswap '$swp' > /dev/null"
swapon "$1" > /dev/null 2> "$ERR" swapon "$swp" > /dev/null 2> "$ERR"
errshow 0 "swapon '$1' > /dev/null" errshow 0 "swapon '$swp' > /dev/null"
return 0 return 0
} }
@ -903,7 +907,7 @@ mount_menu()
select_boot() select_boot()
{ {
local pts dev size isize ptcount=0 local s pts dev size isize ptcount=0
if [[ -z $BOOT ]]; then if [[ -z $BOOT ]]; then
if [[ $AUTO_BOOT && -z $LVM && -z $LUKS ]]; then if [[ $AUTO_BOOT && -z $LVM && -z $LUKS ]]; then
@ -913,40 +917,67 @@ select_boot()
if (( COUNT )); then if (( COUNT )); then
while read -r dev size; do # walk partition list and skip ones that are too small/big for boot while read -r dev size; do # walk partition list and skip ones that are too small/big for boot
size_t="${size: -1:1}" s=${size%%__*}
isize=${size:0:-1} size_t="${s: -1:1}"
isize=${s:0:-1}
isize=${isize%.*} isize=${isize%.*}
[[ $size_t =~ [KT] || ($size_t == 'G' && $isize -gt 2) || ($size_t == 'M' && $isize -lt 100) ]] || { pts+="$dev $size "; (( ptcount++ )); } if ! [[ $size_t == 'T' || ($size_t == 'G' && $isize -gt 2) ]]; then
pts+="$dev $size "
(( ptcount++ ))
fi
done <<< "$PARTS" done <<< "$PARTS"
fi fi
local txt="\nNo partitions available that meet size requirements!!\n\nReturning to the main menu.\n"
case "$SYS" in case "$SYS" in
UEFI) UEFI)
case "$ptcount" in case "$ptcount" in
0) msg "EFI Boot Partition" "\nNo partitions available that meet size requirements!!\n\nReturning to the main menu.\n" 2; return 1 ;; 0)
1) msg "EFI Boot Partition" "\nOnly one partition available that meets size requirements.\n" 1; BOOT="$(awk 'NF > 0 {print $1}' <<< "$pts")" ;; msg "EFI Boot Partition" "$txt" 2
*) dlg BOOT menu "EFI Partition" "$_uefi" $pts ;; return 1
;;
1)
msg "EFI Boot Partition" "\nOnly one partition available that meets size requirements.\n" 1
BOOT="$(awk 'NF > 0 {print $1}' <<< "$pts")"
;;
*)
dlg BOOT menu "EFI Partition" "$_uefi" $pts
;;
esac esac
[[ $BOOT ]] || return 1 [[ $BOOT ]] || return 1
;; ;;
BIOS) BIOS)
if [[ $LUKS && ! $LVM ]]; then if [[ $LUKS && ! $LVM ]]; then
case "$ptcount" in case "$ptcount" in
0) msg "Boot Partition" "\nLUKS without LVM requires a separate boot partition.\nNo partitions available that meet size requirements!!\n\nReturning to the main menu.\n" 2; return 1 ;; 0)
1) msg "Boot Partition" "\nOnly one partition available that meets size requirements.\n" 1; BOOT="$(awk 'NF > 0 {print $1}' <<< "$pts")" ;; txt="\nLUKS without LVM requires a separate boot partition.$txt"
*) dlg BOOT menu "Boot Partition" "$_biosluks" $pts ;; msg "Boot Partition" "$txt" 2
return 1
;;
1)
msg "Boot Partition" "\nOnly one partition available that meets size requirements.\n" 1
BOOT="$(awk 'NF > 0 {print $1}' <<< "$pts")"
;;
*)
dlg BOOT menu "Boot Partition" "$_biosluks" $pts
;;
esac esac
[[ $BOOT ]] || return 1 [[ $BOOT ]] || return 1
else else
(( ptcount == 0 )) && return 0 (( ptcount == 0 )) && return 0
dlg BOOT menu "Boot Partition" "$_bios" "skip" "no separate boot" $pts dlg BOOT menu "Boot Partition" "$_bios" "skip" "no separate boot" $pts
[[ -z $BOOT || $BOOT == "skip" ]] && { BOOT=''; return 0; } if [[ -z $BOOT || $BOOT == "skip" ]]; then
BOOT=''
return 0
fi
fi fi
;; ;;
esac esac
fi fi
if ([[ $SYS == 'BIOS' ]] && grep -q 'ext[34]' <<< "$(fsck -N "$BOOT")") || ([[ $SYS == 'UEFI' ]] && grep -q 'fat' <<< "$(fsck -N "$BOOT")"); then local fs="$(fsck -N "$BOOT")"
if ([[ $SYS == 'BIOS' ]] && grep -q 'ext[34]' <<< "$fs") || ([[ $SYS == 'UEFI' ]] && grep -q 'fat' <<< "$fs"); then
yesno "Format Boot Partition" "\nIMPORTANT: The boot partition $BOOT $_format" "Format $BOOT" "Skip Formatting" 1 || return 0 yesno "Format Boot Partition" "\nIMPORTANT: The boot partition $BOOT $_format" "Format $BOOT" "Skip Formatting" 1 || return 0
fi fi
@ -968,19 +999,24 @@ select_root()
else else
local pts dev size isize ptcount=0 local pts dev size isize ptcount=0
# walk partition list and skip ones that are too small for / (root) # walk partition list and skip ones that are < 4G
while read -r dev size; do while read -r dev size; do
size_t="${size: -1:1}" # size type eg. K, M, G, T s=${size%%__*}
isize=${size:0:-1} # remove trailing size type character size_t="${s: -1:1}"
isize=${isize%.*} # remove any decimal (round down) isize=${s:0:-1}
[[ $size_t =~ [MK] || ($size_t == 'G' && $isize -lt 4) ]] || { pts+="$dev $size "; (( ptcount++ )); } isize=${isize%.*}
if ! [[ $size_t == 'M' || ($size_t == 'G' && $isize -lt 4) ]]; then
pts+="$dev $size "
(( ptcount++ ))
fi
done <<< "$PARTS" done <<< "$PARTS"
if (( ptcount == 1 )); then # only one available device if (( ptcount == 1 )); then # only one available device
msg "Root Partition (/)" "\nOnly one partition available that meets size requirements.\n" 2 msg "Root Partition (/)" "\nOnly one partition available that meets size requirements.\n" 2
ROOT="$(awk 'NF > 0 {print $1}' <<< "$pts")" ROOT="$(awk 'NF > 0 {print $1}' <<< "$pts")"
else else
local txt="\nSelect the root (/) partition, this is where $DIST will be installed.\n\nDevices smaller than 4G will not be shown here." local txt="\nSelect the root (/) partition, this is where $DIST will be installed."
txt+="\n\nDevices smaller than 4G will not be shown here."
dlg ROOT menu "Mount Root" "$txt" $pts dlg ROOT menu "Mount Root" "$txt" $pts
fi fi
fi fi
@ -998,17 +1034,20 @@ select_swap()
local pts dev size isize local pts dev size isize
if (( COUNT )) ; then if (( COUNT )) ; then
while read -r dev size; do # walk partition list and skip ones that are too small/big for swap while read -r dev size; do # walk partition list and skip ones that are > 64G
size_t="${size: -1:1}" s=${size%%__*}
isize=${size:0:-1} size_t="${s: -1:1}"
isize=${s:0:-1}
isize=${isize%.*} isize=${isize%.*}
[[ $size_t =~ [KT] || ($size_t == 'G' && $isize -gt 16) || ($size_t == 'M' && $isize -lt 100) ]] || pts+="$dev $size " if ! [[ $size_t == 'T' || ($size_t == 'G' && $isize -gt 64) ]]; then
pts+="$dev $size "
fi
done <<< "$PARTS" done <<< "$PARTS"
fi fi
dlg SWAP menu "Swap Setup" "\nSelect whether to use a swapfile, swap partition, or none." \ dlg SWAP menu "Swap Setup" "\nSelect whether to use a swapfile, swap partition, or none." \
"none" "Don't allocate any swap space" \ "none" "No swap space" \
"swapfile" "Allocate $SYS_MEM at /swapfile" \ "swapfile" "/swapfile (recommended -- editable size)" \
$pts $pts
if [[ -z $SWAP || $SWAP == "none" ]]; then if [[ -z $SWAP || $SWAP == "none" ]]; then
@ -1017,8 +1056,15 @@ select_swap()
elif [[ $SWAP == "swapfile" ]]; then elif [[ $SWAP == "swapfile" ]]; then
local i=0 local i=0
until [[ ${SWAP_S:0:1} =~ [1-9] && ${SWAP_S: -1} =~ (M|G) ]]; do until [[ ${SWAP_S:0:1} =~ [1-9] && ${SWAP_S: -1} =~ (M|G) ]]; do
(( i > 0 )) && msg "Swap Size Error" "\nSwap size must be 1(M|G) or greater, and can only contain whole numbers\n\nSize entered: $SWAP_S\n" 2 if (( i > 0 )); then
dlg SWAP_S input "Swap Setup" "$_swapsize" "$SYS_MEM" || { SWAP=''; SWAP_S=''; return 1; } msg "Swap Size Error" \
"\nSwap size must be 1(M|G) or greater, and can only contain whole numbers\n\nSize entered: $SWAP_S\n" 2
fi
if ! dlg SWAP_S input "Swap Setup" "$_swapsize" "$SYS_MEM"; then
SWAP=''
SWAP_S=''
return 1
fi
(( i++ )) (( i++ ))
done done
part_swap "$MNT/$SWAP" part_swap "$MNT/$SWAP"
@ -1035,10 +1081,11 @@ select_extra()
{ {
local part dev size local part dev size
# walk partition list and skip ones that are too small to be usable # walk partition list and skip ones that are < 1G
if (( COUNT )); then if (( COUNT )); then
while read -r dev size; do while read -r dev size; do
[[ ${size: -1:1} =~ [KM] ]] && part_countdec "$dev" s=${size%%__*}
[[ ${s: -1:1} == 'M' ]] && part_countdec "$dev"
done <<< "$PARTS" done <<< "$PARTS"
fi fi
@ -1055,7 +1102,9 @@ select_extra()
fi fi
done done
(( COUNT == 0 )) && msg "Mount Extra" "\nMounting Finished\n\nNo more partitions to mount, returning to main menu.\n" 2 if (( COUNT == 0 )); then
msg "Mount Extra" "\nMounting Finished\n\nNo more partitions to mount, returning to main menu.\n" 2
fi
return 0 return 0
} }
@ -1069,9 +1118,10 @@ select_mntopts()
opts+="$i - off " opts+="$i - off "
done done
yesno "$title" "\nPerform automatic mount with default options?\n" && return 1
until [[ $MNT_OPTS ]]; do until [[ $MNT_OPTS ]]; do
dlg MNT_OPTS check "$title" "$_mount" $opts dlg MNT_OPTS check "$title" "$_mount" $opts
[[ $MNT_OPTS ]] || return 1 [[ $MNT_OPTS ]] || return 1 # no options is auto mount
MNT_OPTS="${MNT_OPTS// /,}" MNT_OPTS="${MNT_OPTS// /,}"
yesno "$title" "\nConfirm the following options: $MNT_OPTS\n" || MNT_OPTS='' yesno "$title" "\nConfirm the following options: $MNT_OPTS\n" || MNT_OPTS=''
done done
@ -1214,6 +1264,7 @@ install_base()
chrun "locale-gen" chrun "locale-gen"
chrun "ln -svf /usr/share/zoneinfo/$ZONE/$SUBZ /etc/localtime" chrun "ln -svf /usr/share/zoneinfo/$ZONE/$SUBZ /etc/localtime"
mkdir -pv "$MNT/etc/X11/xorg.conf.d" "$MNT/etc/default"
cat > "$MNT/etc/X11/xorg.conf.d/00-keyboard.conf" <<- EOF cat > "$MNT/etc/X11/xorg.conf.d/00-keyboard.conf" <<- EOF
# Use localectl(1) to instruct systemd-localed to update it. # Use localectl(1) to instruct systemd-localed to update it.
Section "InputClass" Section "InputClass"
@ -2047,7 +2098,6 @@ lvm_partitions()
part_find 'part|crypt' || return 1 part_find 'part|crypt' || return 1
PARTS="$(awk 'NF > 0 {print $0 " off"}' <<< "$PARTS")" PARTS="$(awk 'NF > 0 {print $0 " off"}' <<< "$PARTS")"
dlg LVM_PARTS check "$_lvmnew" "\nSelect the partition(s) to use for the physical volume (PV)." $PARTS dlg LVM_PARTS check "$_lvmnew" "\nSelect the partition(s) to use for the physical volume (PV)." $PARTS
[[ $LVM_PARTS ]]
} }
lvm_group_name() lvm_group_name()
@ -2564,11 +2614,7 @@ system_devices()
{ {
IGNORE_DEV="$(lsblk -lno NAME,MOUNTPOINT | awk '/\/run\/archiso\/bootmnt/ {sub(/[1-9]/, ""); print $1}')" IGNORE_DEV="$(lsblk -lno NAME,MOUNTPOINT | awk '/\/run\/archiso\/bootmnt/ {sub(/[1-9]/, ""); print $1}')"
if [[ $IGNORE_DEV ]]; then SYS_DEVS="$(lsblk -lno NAME,SIZE,TYPE | awk '/disk/ && !'"/${IGNORE_DEV:-NONEXX}/"' {print "/dev/" $1 " " $2}')"
SYS_DEVS="$(lsblk -lno NAME,SIZE,TYPE | awk '/disk/ && !'"/$IGNORE_DEV/"' {print "/dev/" $1 " " $2}')"
else
SYS_DEVS="$(lsblk -lno NAME,SIZE,TYPE | awk '/disk/ {print "/dev/" $1 " " $2}')"
fi
if [[ -z $SYS_DEVS ]]; then if [[ -z $SYS_DEVS ]]; then
msg "Device Error" "\nNo available devices...\n\nExiting..\n" 2 msg "Device Error" "\nNo available devices...\n\nExiting..\n" 2
@ -2643,7 +2689,7 @@ system_identify
system_devices system_devices
while :; do while :; do
dlg fontsize menu "Font Size" "\nSelect a font size from the list below." \ dlg fontsize menu "Font Size" "\nSelect a font size from the list below.\n\nDefault: 16" \
12 "setfont ter-i12n" 14 "setfont ter-i14n" 16 "setfont ter-i16n" 18 "setfont ter-i18n" \ 12 "setfont ter-i12n" 14 "setfont ter-i14n" 16 "setfont ter-i16n" 18 "setfont ter-i18n" \
20 "setfont ter-i20n" 22 "setfont ter-i22n" 24 "setfont ter-i24n" 28 "setfont ter-i28n" \ 20 "setfont ter-i20n" 22 "setfont ter-i22n" 24 "setfont ter-i24n" 28 "setfont ter-i28n" \
32 "setfont ter-i32n" || break 32 "setfont ter-i32n" || break