Replace `expr` with bash built-in arithmetic, and tidy up free-space calculation
This commit is contained in:
parent
8331faf8f3
commit
201db16c93
16
pishrink.sh
16
pishrink.sh
|
@ -143,13 +143,13 @@ if [[ $currentsize -eq $minsize ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Add some free space to the end of the filesystem
|
#Add some free space to the end of the filesystem
|
||||||
if [[ $(expr $currentsize - $minsize - 5000) -gt 0 ]]; then
|
extra_space=$(($currentsize - $minsize))
|
||||||
minsize=$(expr $minsize + 5000)
|
for space in 5000 1000 100; do
|
||||||
elif [[ $(expr $currentsize - $minsize - 1000) -gt 0 ]]; then
|
if [[ $extra_space -gt $space ]]; then
|
||||||
minsize=$(expr $minsize + 1000)
|
minsize=$(($minsize + $space))
|
||||||
elif [[ $(expr $currentsize - $minsize - 100) -gt 0 ]]; then
|
break
|
||||||
minsize=$(expr $minsize + 100)
|
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
#Shrink filesystem
|
#Shrink filesystem
|
||||||
resize2fs -p "$loopback" $minsize
|
resize2fs -p "$loopback" $minsize
|
||||||
|
@ -165,8 +165,8 @@ sleep 1
|
||||||
|
|
||||||
#Shrink partition
|
#Shrink partition
|
||||||
losetup -d "$loopback"
|
losetup -d "$loopback"
|
||||||
partnewsize=$(expr $minsize \* $blocksize)
|
partnewsize=$(($minsize * $blocksize))
|
||||||
newpartend=$(expr $partstart + $partnewsize)
|
newpartend=$(($partstart + $partnewsize))
|
||||||
parted -s "$img" rm $partnum >/dev/null
|
parted -s "$img" rm $partnum >/dev/null
|
||||||
parted -s "$img" unit B mkpart primary $partstart $newpartend >/dev/null
|
parted -s "$img" unit B mkpart primary $partstart $newpartend >/dev/null
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue