Replace `expr` with bash built-in arithmetic, and tidy up free-space calculation

This commit is contained in:
Andrew Scheller 2018-01-22 03:31:19 +00:00
parent 8331faf8f3
commit 201db16c93
1 changed files with 9 additions and 9 deletions

View File

@ -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