diff options
-rw-r--r-- | setup-bootable.in | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/setup-bootable.in b/setup-bootable.in index 7143ee7..1736f69 100644 --- a/setup-bootable.in +++ b/setup-bootable.in @@ -136,11 +136,16 @@ fi rm -rf "$destdir"/.new "$destdir"/.old # check that we have the space we need -needed_space=$(cd "$srcdir" && du -s -c boot apks syslinux.cfg .alpine-release | awk '$2 == "total" {print $1}') -[ -n "$verbose" ] && echo "Needed space: $needed_space kB" - -available_space=$(df -k "$destdir" | tail -n 1 | awk '{print $4}') -[ -n "$verbose" ] && echo "Available space: $available_space kB" +# we calculate on MB since shell arthimetic gets problems with big disks +# and bytes. +needed_space=$(cd "$srcdir" && du -m -s -c boot apks syslinux.cfg .alpine-release | awk '$2 == "total" {print $1}') +[ -n "$verbose" ] && echo "Needed space: $needed_space MiB" + +free_blocks=$(stat -f -c "%f" "$destdir") +block_size=$(stat -f -c "%s" "$destdir") +blocks_per_mb=$(( 1024 * 1024 / $block_size)) +available_space=$(( $free_blocks / $blocks_per_mb )) +[ -n "$verbose" ] && echo "Available space: $available_space MiB" [ $available_space -lt $needed_space ] && die "Not enough space on $destdir. Aborting." # copy the files to .new |