diff options
author | Thomas Deutschmann <whissi@gentoo.org> | 2019-07-23 21:18:07 +0200 |
---|---|---|
committer | Thomas Deutschmann <whissi@gentoo.org> | 2019-07-23 21:37:02 +0200 |
commit | 467c2e82e62b75b5cf9884f3d741926a65338f15 (patch) | |
tree | 868fc106e457fa8ce8d763ae277cdea6729702a7 /gen_funcs.sh | |
parent | genkernel: bump to v4.0.0_beta9 (diff) | |
download | genkernel-467c2e82e62b75b5cf9884f3d741926a65338f15.tar.gz genkernel-467c2e82e62b75b5cf9884f3d741926a65338f15.tar.bz2 genkernel-467c2e82e62b75b5cf9884f3d741926a65338f15.zip |
Add feature to check for free disk space early at genkernel startv4.0.0_beta9
To avoid preventable errors like running out of disk space while building
a new kernel, two new options, --check-free-disk-space-bootdir and
--check-free-disk-space-kerneloutputdir, were added.
When set, disabled by default, genkernel will check early before
starting to build kernel/initramfs for specified amount of free
disk space.
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
Diffstat (limited to 'gen_funcs.sh')
-rwxr-xr-x | gen_funcs.sh | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/gen_funcs.sh b/gen_funcs.sh index 3c91372..94bf550 100755 --- a/gen_funcs.sh +++ b/gen_funcs.sh @@ -1462,6 +1462,85 @@ rootfs_type_is() { fi } +check_disk_space_requirements() { + local number_pattern='^[1-9]{1}[0-9]+$' + local available_free_disk_space= + + # Start check for BOOTDIR + local need_to_check=yes + + if [ -z "${CHECK_FREE_DISK_SPACE_BOOTDIR}" -o "${CHECK_FREE_DISK_SPACE_BOOTDIR}" = '0' ] + then + need_to_check=no + fi + + if isTrue "${need_to_check}" && ! isTrue "${CMD_INSTALL}" + then + need_to_check=no + fi + + if isTrue "${need_to_check}" + then + if [[ ! "${CHECK_FREE_DISK_SPACE_BOOTDIR}" =~ ${number_pattern} ]] + then + 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 }') + 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}" + + available_free_disk_space=${available_free_disk_space%M} + if [ ${available_free_disk_space} -lt ${CHECK_FREE_DISK_SPACE_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!" + fi + else + print_warning 1 "Invalid df value; Skipping free disk space check for '${BOOTDIR}' ..." + fi + fi + + # Start check for kernel outputdir + need_to_check=yes + + if [ -z "${CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR}" -o "${CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR}" = '0' ] + then + need_to_check=no + fi + + if isTrue "${need_to_check}" && ! isTrue "${BUILD_KERNEL}" + then + need_to_check=no + fi + + if isTrue "${need_to_check}" + then + if [[ ! "${CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR}" =~ ${number_pattern} ]] + then + 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 }') + 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}" + + available_free_disk_space=${available_free_disk_space%M} + if [ ${available_free_disk_space} -lt ${CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR} ] + then + gen_die "${CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR} MB free disk space is required in '${BOOTDIR}' but only ${available_free_disk_space} MB is available!" + fi + else + print_warning 1 "Invalid df value; Skipping free disk space check for '${KERNEL_OUTPUTDIR}' ..." + fi + fi +} + check_distfiles() { local source_files=( $(compgen -A variable |grep '^GKPKG_.*SRCTAR$') ) |