OSDN Git Service

Clean up part_shrink()
authornatemaia <natemaia10@gmail.com>
Sun, 21 Apr 2019 20:44:21 +0000 (13:44 -0700)
committernatemaia <natemaia10@gmail.com>
Sun, 21 Apr 2019 20:45:58 +0000 (13:45 -0700)
archlabs-installer

index dd70469..825d23d 100755 (executable)
@@ -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.44"     # installer version
+VER="2.0.45"     # installer version
 DIST="ArchLabs"  # linux distributor
 MNT="/mnt"       # install mountpoint
 ANS="/tmp/ans"   # dialog answer file
@@ -931,13 +931,11 @@ part_shrink()
        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 && [[ $part ]]; then
+       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
-
-                               # get device size info
                                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
@@ -945,35 +943,34 @@ part_shrink()
                                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 $MNT >/dev/null 2>&1
-
-                               # get new size from user
                                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))
+                                       size=$(< "$ANS")
+                                       size=$((size * 1024))
                                else
                                        return 1
                                fi
-
                                clear
                                case "$fs" in
-                                       ext[2-4])
+                                       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
                                                ;;
-                                       ntfs)
-                                               ntfsresize -fc "$part" || { 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; }
-                                               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
-                                               ;;
                                esac
-
-                               echo "filesystem shrunk successfully, now the partition"
                                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
@@ -981,10 +978,10 @@ part_shrink()
                                        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"
+                               msg "Resize Complete" "\n$part has been successfully resized to $((size / 1024))M.\n" 1
                                ;;
-                       *) msg "Invalid Filesystem: $fs" "\nResizing only supports ext and ntfs.\n\nFor unformatted partitions, cfdisk can be used.\n" ;;
+                       "") 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
 }