From 3c506aa5bbe9bf4341b827f034e2a17d069a6708 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 28 Oct 2010 14:45:01 +0000 Subject: setup-bootable: use stat to calculate needed disk space --- setup-bootable.in | 15 ++++++++++----- 1 file 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 -- cgit v1.2.3