]> git.ipfire.org Git - people/jschlag/ipfire-3.x-image.git/commitdiff
Check for free space before build
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Thu, 15 Nov 2018 13:37:43 +0000 (13:37 +0000)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Thu, 15 Nov 2018 13:37:43 +0000 (13:37 +0000)
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
generate_image.sh

index 13c8343257e4a8097fcc346a8622d3b6a0c6108d..f9289dfffafb77a663c2219728481543bcc20b34 100755 (executable)
@@ -202,6 +202,21 @@ get_compression_type() {
 
 }
 
+check_for_free_space() {
+               local space=${1}
+               local path=${2}
+
+               # Space needs to passed in MB
+               # df returns bytes so we multiple by 1024²
+               space=$(( ${space} * 1024 * 1024 ))
+
+               if [[ $(df --output=avail ${path} | tail -n 1) -lt ${space} ]]; then
+                       log error "Not enough free space available under ${path}"
+                       log error "Free space is $(df -h -B MB --output=avail ${path} | tail -n 1) but we need at least $(( ${space} / 1024 / 1024 ))MB"
+                       return ${EXIT_ERROR}
+               fi
+}
+
 #
 # General settings
 #
@@ -267,6 +282,9 @@ LOCAL_REPO_FILE="/etc/pakfire/repos/local.repo"
 # Check that pakfire is working
 check_for_pakfire
 
+if ! check_for_free_space 10000 "${WORKING_DIR}"; then
+       exit ${EXIT_ERROR}
+fi
 
 # Check that the image does not exist yet
 if [ -f ${IMAGE_BASE_FILE} ]; then