Commit ce161983 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

Check diskspace

parent 2d4b6e8b
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -10,10 +10,19 @@ DATA_SIZE=$(numfmt --from=iec "${DISK_SIZE}")
DATA="$IMG/data${DISK_SIZE}.img"

if [ ! -f "$DATA" ]; then

  # Check free diskspace
  SPACE=$(df --output=avail -B 1 "$IMG" | tail -n 1)

  if (( DATA_SIZE > SPACE )); then
    echo "ERROR: Not enough free space to create virtual disk." && exit 82
  fi

  if ! fallocate -l "${DATA_SIZE}" "${DATA}"; then
    rm -f "${DATA}"
    echo "ERROR: Not enough free space to create virtual disk." && exit 82
    echo "ERROR: Could not allocate file for virtual disk." && exit 82
  fi

fi

[ ! -f "$DATA" ] && echo "ERROR: Data image does not exist ($DATA)" && exit 83