Fix: broken finding of max size available for shrink

This commit is contained in:
natemaia 2019-04-21 13:09:03 -07:00
parent 62284e422f
commit 3a9fc5cbce

View File

@ -5,7 +5,7 @@
# Some ideas and code reworked from other resources # Some ideas and code reworked from other resources
# AIF, Cnichi, Calamares, Arch Wiki.. Credit where credit is due # AIF, Cnichi, Calamares, Arch Wiki.. Credit where credit is due
VER="2.0.42" # installer version VER="2.0.44" # installer version
DIST="ArchLabs" # linux distributor DIST="ArchLabs" # linux distributor
MNT="/mnt" # install mountpoint MNT="/mnt" # install mountpoint
ANS="/tmp/ans" # dialog answer file ANS="/tmp/ans" # dialog answer file
@ -939,28 +939,17 @@ part_shrink()
# get device size info # get device size info
num="${part: -1}" num="${part: -1}"
end=$(parted -s "$device" unit KiB print | awk '/^\s*'"$num"'/ {print int($3)}') # part size in KiB end=$(parted -s "$device" unit KiB print | awk '/^\s*'"$num"'/ {print $3}') # part size in KiB
devsize=$(parted -s "$device" unit KiB print | awk '/Disk '"${device//\//\\/}"':/ {print int($3)}') # whole device size in KiB devsize=$(parted -s "$device" unit KiB print | awk '/Disk '"${device//\//\\/}"':/ {print $3}') # whole device size in KiB
mount "$part" $MNT >/dev/null 2>&1; sleep 0.5
# minimum in KiB (2^10) min=$(df --output=used --block-size=MiB "$part" | awk 'NR == 2 {print int($1) + 256}')
case "$fs" in max=$(df --output=avail --block-size=MiB "$part" | awk 'NR == 2 {print int($1)}')
ext[2-4]) umount $MNT >/dev/null 2>&1
mount "$part" $MNT >/dev/null 2>&1; sleep 0.5
min=$(df --output=used --block-size=KiB "$part" | awk 'NR == 2 {print int($1)}')
umount $MNT >/dev/null 2>&1
;;
ntfs) min=$(ntfsresize -f -m "$part" | awk 'NR == 2 {print int(($NF * 1000 * 1000) / 1024)}') >/dev/null 2>&1 ;;
esac
# KiB -> MiB
mbmin=$(((min / 1024) + 200))
mbend=$((end / 1024))
# get new size from user # get new size from user
tput cnorm tput cnorm
if dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Resize: $part " --rangebox "$_resize" 17 "$COLUMNS" "$mbmin" "$mbend" $((mbend / 2)) 2>$ANS; then if dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Resize: $part " --rangebox "$_resize" 17 "$COLUMNS" "$min" "$max" $((max / 2)) 2>$ANS; then
(( (size = $(< "$ANS")) < mbend )) || return 1 size=$(< "$ANS"); size=$((size * 1024))
size=$((size * 1024))
else else
return 1 return 1
fi fi