+part_shrink()
+{
+ part=""
+ typeset -i size num
+ local device="$1" fs=""
+
+ part_find "${device##*/}[^ ]" || return 1
+ (( COUNT == 1 )) && part="$(awk '{print $1}' <<< "${PARTS[@]}" )"
+
+ if (( COUNT == 1 )) || dlg part menu "Resize" "\nWhich partition on $device do you want to resize?" $PARTS; then
+ fs=$(lsblk -lno FSTYPE "$part")
+ case "$fs" in
+ ext*|ntfs)
+ msg "Resize" "\nGathering device size info.\n" 0
+ num="${part: -1}"
+ 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 $3}') # whole device size in KiB
+ mount "$part" $MNT >/dev/null 2>&1; sleep 0.5
+ min=$(df --output=used --block-size=MiB "$part" | awk 'NR == 2 {print int($1) + 256}')
+ max=$(df --output=avail --block-size=MiB "$part" | awk 'NR == 2 {print int($1)}')
+ umount_dir $MNT
+ tput cnorm
+ if dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Resize: $part " --rangebox "$_resize" 17 "$COLUMNS" "$min" "$max" $((max / 2)) 2>$ANS; then
+ size=$(< "$ANS")
+ size=$((size * 1024))
+ else
+ return 1
+ fi
+ clear
+ case "$fs" in
+ ntfs)
+ if ntfsresize -fc "$part"; then
+ ntfsresize -ff --size $(( (size * 1024) / 1000 ))k "$part" 2>$ERR # k=10^3 bytes
+ errshow "ntfsresize -f -s $(( (size * 1024) / 1000 ))k $part" || return 1
+ else
+ msg "Resize" "\nThe ntfs partition $part cannot be resized because it is scheduled for a consistency check.\n\nTo do a consistency check in windows open command prompt as admin and run:\n\n\tchkdsk /f /r /x\n"
+ return 1
+ fi
+ ;;
+ *)
+ e2fsck -f "$part"; sleep 0.5
+ resize2fs -f "$part" ${size}K 2>$ERR # K=2^10 bytes
+ errshow "resize2fs -f $part ${size}K" || return 1
+ ;;
+ esac
+ sleep 0.5
+ parted "$device" resizepart "$num" ${size}KiB || return 1
+ (( size++ ))
+ sleep 0.5
+ if [[ $devsize == "$end" ]]; then
+ parted -s "$device" mkpart primary ext4 ${size}KiB 100% 2>$ERR
+ errshow "parted -s $device mkpart primary ext4 ${size}KiB 100%" || return 1
+ else
+ parted -s "$device" mkpart primary ext4 ${size}KiB ${end}KiB 2>$ERR
+ errshow "parted -s $device mkpart primary ext4 ${size}KiB ${end}KiB" || return 1
+ fi
+ msg "Resize Complete" "\n$part has been successfully resized to $((size / 1024))M.\n" 1
+ ;;
+ "") msg "No Filesystem" "\nFor unformatted partitions, cfdisk can be used in the partition menu.\n" ;;
+ *) msg "Invalid Filesystem: $fs" "\nResizing only supports ext and ntfs.\n" ;;
+ esac
+ fi
+}
+
+###############################################################################
+# partition management functions
+# these are helpers for use by other functions to do essential setup/teardown
+