aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Vrzić <vvrzic@gmail.com>2021-04-27 13:41:19 +0200
committerSam James <sam@gentoo.org>2023-07-28 10:52:55 +0100
commitc96acc3259ed4a4d8d3605ef27013f9cec4c1ed6 (patch)
tree54f349955e1b54edd75633d7efe75a5d9912f5d7 /gen_funcs.sh
parentEnabling zstd multithreaded compression (diff)
downloadgenkernel-c96acc3259ed4a4d8d3605ef27013f9cec4c1ed6.tar.gz
genkernel-c96acc3259ed4a4d8d3605ef27013f9cec4c1ed6.tar.bz2
genkernel-c96acc3259ed4a4d8d3605ef27013f9cec4c1ed6.zip
gen_funcs.sh: use stat(1) to check free disk space
By using stat(1) to get free disk space we avoid tricky parsing of df(1) output. Signed-off-by: Vladimir Vrzić <vvrzic@gmail.com> Closes: https://github.com/gentoo/genkernel/pull/22 Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'gen_funcs.sh')
-rwxr-xr-xgen_funcs.sh26
1 files changed, 14 insertions, 12 deletions
diff --git a/gen_funcs.sh b/gen_funcs.sh
index 476f5ee..c31e15a 100755
--- a/gen_funcs.sh
+++ b/gen_funcs.sh
@@ -1904,20 +1904,21 @@ check_disk_space_requirements() {
gen_die "--check-free-disk-space-bootdir value '${CHECK_FREE_DISK_SPACE_BOOTDIR}' is not a valid number!"
fi
- available_free_disk_space=$(unset POSIXLY_CORRECT && df -BM "${BOOTDIR}" | awk '$3 ~ /[0-9]+/ { print $4 }')
+ available_free_disk_space="$(($(stat -fc '%f * %S' "${BOOTDIR}")))"
if [ -n "${available_free_disk_space}" ]
then
print_info 2 '' 1 0
print_info 2 "Checking for at least ${CHECK_FREE_DISK_SPACE_BOOTDIR} MB free disk space in '${BOOTDIR}' ..."
- print_info 5 "df reading: ${available_free_disk_space}"
+ print_info 5 "stat(1) reading: ${available_free_disk_space} bytes free"
- available_free_disk_space=${available_free_disk_space%M}
- if [ ${available_free_disk_space} -lt ${CHECK_FREE_DISK_SPACE_BOOTDIR} ]
+ bytes_in_mb=1048576
+ minimum_free_space_bytes_bootdir="$((${CHECK_FREE_DISK_SPACE_BOOTDIR} * ${bytes_in_mb}))"
+ if [ "${available_free_disk_space}" -lt "${minimum_free_space_bytes_bootdir}" ]
then
- gen_die "${CHECK_FREE_DISK_SPACE_BOOTDIR} MB free disk space is required in '${BOOTDIR}' but only ${available_free_disk_space} MB is available!"
+ gen_die "${CHECK_FREE_DISK_SPACE_BOOTDIR} MB free disk space is required in '${BOOTDIR}' but only ${available_free_disk_space} bytes is available!"
fi
else
- print_warning 1 "Invalid df value; Skipping free disk space check for '${BOOTDIR}' ..."
+ print_warning 1 "Invalid stat(1) value; Skipping free disk space check for '${BOOTDIR}' ..."
fi
fi
@@ -1941,20 +1942,21 @@ check_disk_space_requirements() {
gen_die "--check-free-disk-space-kerneloutputdir value '${CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR}' is not a valid number!"
fi
- available_free_disk_space=$(unset POSIXLY_CORRECT && df -BM "${KERNEL_OUTPUTDIR}" | awk '$3 ~ /[0-9]+/ { print $4 }')
+ available_free_disk_space="$(($(stat -fc '%f * %S' "${KERNEL_OUTPUTDIR}")))"
if [ -n "${available_free_disk_space}" ]
then
print_info 2 '' 1 0
print_info 2 "Checking for at least ${CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR} MB free disk space in '${KERNEL_OUTPUTDIR}' ..."
- print_info 5 "df reading: ${available_free_disk_space}"
+ print_info 5 "stat(1) reading: ${available_free_disk_space} bytes free"
- available_free_disk_space=${available_free_disk_space%M}
- if [ ${available_free_disk_space} -lt ${CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR} ]
+ bytes_in_mb=1048576
+ minimum_free_space_bytes_kerneloutputdir="$((${CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR} * ${bytes_in_mb}))"
+ if [ "${available_free_disk_space}" -lt "${minimum_free_space_bytes_kerneloutputdir}" ]
then
- gen_die "${CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR} MB free disk space is required in '${KERNEL_OUTPUTDIR}' but only ${available_free_disk_space} MB is available!"
+ gen_die "${CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR} MB free disk space is required in '${KERNEL_OUTPUTDIR}' but only ${available_free_disk_space} bytes is available!"
fi
else
- print_warning 1 "Invalid df value; Skipping free disk space check for '${KERNEL_OUTPUTDIR}' ..."
+ print_warning 1 "Invalid stat(1) value; Skipping free disk space check for '${KERNEL_OUTPUTDIR}' ..."
fi
fi
}