diff --git a/bin/disk-image-create b/bin/disk-image-create index acb50492..ad811a8f 100755 --- a/bin/disk-image-create +++ b/bin/disk-image-create @@ -338,26 +338,28 @@ mv $TMP_BUILD_DIR/mnt $TMP_BUILD_DIR/built # logs with du output below. xtrace=$(set +o | grep xtrace) +# temp file for holding du output +du_output=${TMP_BUILD_DIR}/du_output.tmp + if [ -n "$DIB_IMAGE_SIZE" ]; then du_size=$(echo "$DIB_IMAGE_SIZE" | awk '{printf("%d\n",$1 * 1024 *1024)}') else set +o xtrace echo "Calculating image size (this may take a minute)..." - du_output=$(sudo du -a -c -x ${TMP_BUILD_DIR}/built) + sudo du -a -c -x ${TMP_BUILD_DIR}/built > ${du_output} # the last line is the total size from "-c". # scale this by 0.6 to create a slightly bigger image - du_size=$(echo "$du_output" | tail -n1 | cut -f1 | \ - awk '{print int($1 / 0.6)}') + du_size=$(tail -n1 ${du_output} | cut -f1 | awk '{print int($1 / 0.6)}') $xtrace fi if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then set +o xtrace - if [ -z "$du_output" ]; then - du_output=$(sudo du -a -c -x ${TMP_BUILD_DIR}/built) + if [ ! -f "$du_output" ]; then + sudo du -a -c -x ${TMP_BUILD_DIR}/built > ${du_output} fi - du_output_show="sort -nr | + du_output_show="sort -nr ${du_output} | numfmt --to=iec-i --padding=7 --suffix=B --field=1 --from-unit=1024" @@ -376,7 +378,7 @@ if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then echo "=================" fi - eval ${du_output_show} <<< "$du_output" + eval ${du_output_show} echo echo "===== end image size report =====" @@ -385,6 +387,8 @@ if [[ "${DIB_SHOW_IMAGE_USAGE:-0}" != 0 ]]; then $xtrace fi +rm -f ${du_output} + if [ "$FS_TYPE" = "ext4" ] ; then # Very conservative to handle images being resized a lot # We set journal size to 64M so our journal is large enough when we