summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2010-10-28 14:45:01 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2010-10-28 14:45:01 +0000
commit3c506aa5bbe9bf4341b827f034e2a17d069a6708 (patch)
tree20ec15af13b74a2a714423519357c186b6fb938e
parenta3dd3912d0a1f046555b6d366be747bb3d863620 (diff)
downloadalpine-conf-3c506aa5bbe9bf4341b827f034e2a17d069a6708.tar.bz2
alpine-conf-3c506aa5bbe9bf4341b827f034e2a17d069a6708.tar.xz
setup-bootable: use stat to calculate needed disk spacev2.5.2
-rw-r--r--setup-bootable.in15
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