From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B876915800A for ; Fri, 28 Jul 2023 09:53:16 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DE938E0A65; Fri, 28 Jul 2023 09:53:15 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id BB641E0A65 for ; Fri, 28 Jul 2023 09:53:15 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id A1852341550 for ; Fri, 28 Jul 2023 09:53:14 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 0E398ACD for ; Fri, 28 Jul 2023 09:53:13 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1690537975.c96acc3259ed4a4d8d3605ef27013f9cec4c1ed6.sam@gentoo> Subject: [gentoo-commits] proj/genkernel:master commit in: / X-VCS-Repository: proj/genkernel X-VCS-Files: gen_funcs.sh X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: c96acc3259ed4a4d8d3605ef27013f9cec4c1ed6 X-VCS-Branch: master Date: Fri, 28 Jul 2023 09:53:13 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: c6c0dc21-5265-48d7-b616-fc0ba7b67b99 X-Archives-Hash: 2c303f406d968b95bea0318b6b40a076 commit: c96acc3259ed4a4d8d3605ef27013f9cec4c1ed6 Author: Vladimir Vrzić gmail com> AuthorDate: Tue Apr 27 11:41:19 2021 +0000 Commit: Sam James gentoo org> CommitDate: Fri Jul 28 09:52:55 2023 +0000 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=c96acc32 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ć gmail.com> Closes: https://github.com/gentoo/genkernel/pull/22 Signed-off-by: Sam James gentoo.org> gen_funcs.sh | 26 ++++++++++++++------------ 1 file 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 }