commit:     467c2e82e62b75b5cf9884f3d741926a65338f15
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Tue Jul 23 19:18:07 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Tue Jul 23 19:37:02 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=467c2e82

Add feature to check for free disk space early at genkernel start

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 <AT> gentoo.org>

 doc/genkernel.8.txt  |   8 +++
 gen_cmdline.sh       |  14 ++++
 gen_determineargs.sh | 191 ++++++++++++++++++++++++++-------------------------
 gen_funcs.sh         |  79 +++++++++++++++++++++
 genkernel            |   2 +
 genkernel.conf       |   6 ++
 6 files changed, 206 insertions(+), 94 deletions(-)

diff --git a/doc/genkernel.8.txt b/doc/genkernel.8.txt
index 72029d6..8650881 100644
--- a/doc/genkernel.8.txt
+++ b/doc/genkernel.8.txt
@@ -395,6 +395,14 @@ INTERNALS
 *--cachedir*=<dir>::
     Override the default cache location.
 
+*--check-free-disk-space-bootdir*=<MB>::
+    When set to a non-zero value, genkernel will check early on start for
+    specified amount of free disk space in megabyte in *BOOTDIR*.
+
+*--check-free-disk-space-kerneloutputdir*=<MB>::
+    When set to a non-zero value, genkernel will check early on start for
+    specified amount of free disk space in megabyte in *KERNEL_OUTPUTDIR*.
+
 *--*[*no-*]*clear-cachedir*::
     Clears or skips clearing all files in cache location on genkernel start.
 

diff --git a/gen_cmdline.sh b/gen_cmdline.sh
index a05e277..c93cffd 100755
--- a/gen_cmdline.sh
+++ b/gen_cmdline.sh
@@ -168,6 +168,12 @@ longusage() {
   echo "       --real-root=<foo>       Specify a default for real_root="
   echo "  Internals"
   echo "       --cachedir=<dir>        Override the default cache location"
+  echo "       --check-free-disk-space-bootdir=<MB>"
+  echo "                               Check for specified amount of free disk 
space in MB in BOOTDIR"
+  echo "                               at genkernel start"
+  echo "       --check-free-disk-space-kerneloutputdir=<MB>"
+  echo "                               Check for specified amount of free disk 
space in MB in"
+  echo "                               kernel outputdir at genkernel start"
   echo "       --clear-cachedir        Clear genkernel's cache location on 
start. Useful"
   echo "                               if you want to force rebuild of 
included tools"
   echo "                               like BusyBox, DMRAID, GnuPG, LVM, MDADM 
..."
@@ -601,6 +607,14 @@ parse_cmdline() {
                        CMD_POSTCLEAR=$(parse_optbool "$*")
                        print_info 3 "CMD_POSTCLEAR: ${CMD_POSTCLEAR}"
                        ;;
+               --check-free-disk-space-bootdir=*)
+                       CMD_CHECK_FREE_DISK_SPACE_BOOTDIR="${*#*=}"
+                       print_info 3 "CMD_CHECK_FREE_DISK_SPACE_BOOTDIR: 
${CMD_CHECK_FREE_DISK_SPACE_BOOTDIR}"
+                       ;;
+               --check-free-disk-space-kerneloutputdir=*)
+                       CMD_CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR="${*#*=}"
+                       print_info 3 
"CMD_CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR: 
${CMD_CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR}"
+                       ;;
                --color|--no-color)
                        CMD_COLOR=$(parse_optbool "$*")
                        if isTrue "${CMD_COLOR}"

diff --git a/gen_determineargs.sh b/gen_determineargs.sh
index eb0cd74..69a6ee7 100755
--- a/gen_determineargs.sh
+++ b/gen_determineargs.sh
@@ -95,100 +95,103 @@ determine_real_args() {
 
        print_info 4 "Resolving config file, command line, and arch default 
settings."
 
-       #                               Dest / Config File   Command Line       
              Arch Default
-       #                               ------------------   ------------       
              ------------
-       set_config_with_override STRING TMPDIR                   CMD_TMPDIR     
              "/var/tmp/genkernel"
-       set_config_with_override STRING LOGFILE                  CMD_LOGFILE    
              "/var/log/genkernel.conf"
-       set_config_with_override STRING KERNEL_DIR               CMD_KERNEL_DIR 
              "${DEFAULT_KERNEL_SOURCE}"
-       set_config_with_override BOOL   KERNEL_SOURCES           
CMD_KERNEL_SOURCES           "yes"
-       set_config_with_override STRING KNAME                    CMD_KERNNAME   
              "genkernel"
-
-       set_config_with_override STRING COMPRESS_INITRD          
CMD_COMPRESS_INITRD          "$DEFAULT_COMPRESS_INITRD"
-       set_config_with_override STRING COMPRESS_INITRD_TYPE     
CMD_COMPRESS_INITRD_TYPE     "$DEFAULT_COMPRESS_INITRD_TYPE"
-       set_config_with_override STRING MAKEOPTS                 CMD_MAKEOPTS   
              "$DEFAULT_MAKEOPTS"
-       set_config_with_override STRING NICE                     CMD_NICE       
              "10"
-       set_config_with_override STRING KERNEL_MAKE              
CMD_KERNEL_MAKE              "$DEFAULT_KERNEL_MAKE"
-       set_config_with_override STRING UTILS_CFLAGS             
CMD_UTILS_CFLAGS             "$DEFAULT_UTILS_CFLAGS"
-       set_config_with_override STRING UTILS_MAKE               CMD_UTILS_MAKE 
              "$DEFAULT_UTILS_MAKE"
-       set_config_with_override STRING KERNEL_CC                CMD_KERNEL_CC  
              "$DEFAULT_KERNEL_CC"
-       set_config_with_override STRING KERNEL_LD                CMD_KERNEL_LD  
              "$DEFAULT_KERNEL_LD"
-       set_config_with_override STRING KERNEL_AS                CMD_KERNEL_AS  
              "$DEFAULT_KERNEL_AS"
-       set_config_with_override STRING UTILS_CC                 CMD_UTILS_CC   
              "$DEFAULT_UTILS_CC"
-       set_config_with_override STRING UTILS_LD                 CMD_UTILS_LD   
              "$DEFAULT_UTILS_LD"
-       set_config_with_override STRING UTILS_AS                 CMD_UTILS_AS   
              "$DEFAULT_UTILS_AS"
-
-       set_config_with_override STRING CROSS_COMPILE            
CMD_CROSS_COMPILE
-       set_config_with_override STRING BOOTDIR                  CMD_BOOTDIR    
              "/boot"
-       set_config_with_override STRING KERNEL_OUTPUTDIR         
CMD_KERNEL_OUTPUTDIR         "${KERNEL_DIR}"
-       set_config_with_override STRING KERNEL_LOCALVERSION      
CMD_KERNEL_LOCALVERSION
-       set_config_with_override STRING MODPROBEDIR              
CMD_MODPROBEDIR              "/etc/modprobe.d"
-
-       set_config_with_override BOOL   SPLASH                   CMD_SPLASH     
              "no"
-       set_config_with_override BOOL   CLEAR_CACHEDIR           
CMD_CLEAR_CACHEDIR           "no"
-       set_config_with_override BOOL   POSTCLEAR                CMD_POSTCLEAR  
              "no"
-       set_config_with_override BOOL   MRPROPER                 CMD_MRPROPER   
              "yes"
-       set_config_with_override BOOL   MENUCONFIG               CMD_MENUCONFIG 
              "no"
-       set_config_with_override BOOL   GCONFIG                  CMD_GCONFIG    
              "no"
-       set_config_with_override BOOL   NCONFIG                  CMD_NCONFIG    
              "no"
-       set_config_with_override BOOL   XCONFIG                  CMD_XCONFIG    
              "no"
-       set_config_with_override BOOL   CLEAN                    CMD_CLEAN      
              "yes"
-
-       set_config_with_override STRING MINKERNPACKAGE           
CMD_MINKERNPACKAGE
-       set_config_with_override STRING MODULESPACKAGE           
CMD_MODULESPACKAGE
-       set_config_with_override BOOL   MODULEREBUILD            
CMD_MODULEREBUILD            "yes"
-       set_config_with_override STRING KERNCACHE                CMD_KERNCACHE
-       set_config_with_override BOOL   RAMDISKMODULES           
CMD_RAMDISKMODULES           "yes"
-       set_config_with_override BOOL   ALLRAMDISKMODULES        
CMD_ALLRAMDISKMODULES        "no"
-       set_config_with_override STRING INITRAMFS_OVERLAY        
CMD_INITRAMFS_OVERLAY
-       set_config_with_override BOOL   MOUNTBOOT                CMD_MOUNTBOOT  
              "yes"
-       set_config_with_override BOOL   BUILD_STATIC             CMD_STATIC     
              "no"
-       set_config_with_override BOOL   SAVE_CONFIG              
CMD_SAVE_CONFIG              "yes"
-       set_config_with_override BOOL   SYMLINK                  CMD_SYMLINK    
              "no"
-       set_config_with_override STRING INSTALL_MOD_PATH         
CMD_INSTALL_MOD_PATH
-       set_config_with_override BOOL   OLDCONFIG                CMD_OLDCONFIG  
              "yes"
-       set_config_with_override BOOL   SANDBOX                  CMD_SANDBOX    
              "yes"
-       set_config_with_override BOOL   SSH                      CMD_SSH        
              "no"
-       set_config_with_override STRING SSH_AUTHORIZED_KEYS_FILE 
CMD_SSH_AUTHORIZED_KEYS_FILE "/etc/dropbear/authorized_keys"
-       set_config_with_override STRING SSH_HOST_KEYS            
CMD_SSH_HOST_KEYS            "create"
-       set_config_with_override BOOL   STRACE                   CMD_STRACE     
              "no"
-       set_config_with_override BOOL   BCACHE                   CMD_BCACHE     
              "no"
-       set_config_with_override BOOL   LVM                      CMD_LVM        
              "no"
-       set_config_with_override BOOL   DMRAID                   CMD_DMRAID     
              "no"
-       set_config_with_override BOOL   ISCSI                    CMD_ISCSI      
              "no"
-       set_config_with_override BOOL   HYPERV                   CMD_HYPERV     
              "no"
-       set_config_with_override STRING BOOTLOADER               CMD_BOOTLOADER 
              "no"
-       set_config_with_override BOOL   BUSYBOX                  CMD_BUSYBOX    
              "yes"
-       set_config_with_override STRING BUSYBOX_CONFIG           
CMD_BUSYBOX_CONFIG
-       set_config_with_override BOOL   NFS                      CMD_NFS        
              "yes"
-       set_config_with_override STRING MICROCODE                CMD_MICROCODE  
              "all"
-       set_config_with_override BOOL   MICROCODE_INITRAMFS      
CMD_MICROCODE_INITRAMFS      "yes"
-       set_config_with_override BOOL   UNIONFS                  CMD_UNIONFS    
              "no"
-       set_config_with_override BOOL   NETBOOT                  CMD_NETBOOT    
              "no"
-       set_config_with_override STRING REAL_ROOT                CMD_REAL_ROOT
-       set_config_with_override BOOL   DISKLABEL                CMD_DISKLABEL  
              "yes"
-       set_config_with_override BOOL   LUKS                     CMD_LUKS       
              "no"
-       set_config_with_override BOOL   GPG                      CMD_GPG        
              "no"
-       set_config_with_override BOOL   MDADM                    CMD_MDADM      
              "no"
-       set_config_with_override STRING MDADM_CONFIG             
CMD_MDADM_CONFIG
-       set_config_with_override BOOL   E2FSPROGS                CMD_E2FSPROGS  
              "no"
-       set_config_with_override BOOL   XFSPROGS                 CMD_XFSPROGS   
              "no"
-       set_config_with_override BOOL   ZFS                      CMD_ZFS        
              "$(rootfs_type_is zfs)"
-       set_config_with_override BOOL   BTRFS                    CMD_BTRFS      
              "$(rootfs_type_is btrfs)"
-       set_config_with_override BOOL   VIRTIO                   CMD_VIRTIO     
              "no"
-       set_config_with_override BOOL   MULTIPATH                CMD_MULTIPATH  
              "no"
-       set_config_with_override BOOL   FIRMWARE                 CMD_FIRMWARE   
              "no"
-       set_config_with_override STRING FIRMWARE_DIR             
CMD_FIRMWARE_DIR             "/lib/firmware"
-       set_config_with_override STRING FIRMWARE_FILES           
CMD_FIRMWARE_FILES
-       set_config_with_override BOOL   FIRMWARE_INSTALL         
CMD_FIRMWARE_INSTALL         "no"
-       set_config_with_override BOOL   INTEGRATED_INITRAMFS     
CMD_INTEGRATED_INITRAMFS     "no"
-       set_config_with_override BOOL   WRAP_INITRD              
CMD_WRAP_INITRD              "no"
-       set_config_with_override BOOL   GENZIMAGE                CMD_GENZIMAGE  
              "no"
-       set_config_with_override BOOL   KEYMAP                   CMD_KEYMAP     
              "yes"
-       set_config_with_override BOOL   DOKEYMAPAUTO             
CMD_DOKEYMAPAUTO             "no"
-       set_config_with_override STRING BUSYBOX_CONFIG           
CMD_BUSYBOX_CONFIG
-       set_config_with_override STRING STRIP_TYPE               CMD_STRIP_TYPE 
              "modules"
-       set_config_with_override BOOL   INSTALL                  CMD_INSTALL    
              "yes"
-       set_config_with_override BOOL   CLEANUP                  CMD_CLEANUP    
              "yes"
+       #                               Dest / Config File                    
Command Line                              Arch Default
+       #                               ------------------                    
------------                              ------------
+       set_config_with_override STRING TMPDIR                                
CMD_TMPDIR                                "/var/tmp/genkernel"
+       set_config_with_override STRING LOGFILE                               
CMD_LOGFILE                               "/var/log/genkernel.conf"
+       set_config_with_override STRING KERNEL_DIR                            
CMD_KERNEL_DIR                            "${DEFAULT_KERNEL_SOURCE}"
+       set_config_with_override BOOL   KERNEL_SOURCES                        
CMD_KERNEL_SOURCES                        "yes"
+       set_config_with_override STRING KNAME                                 
CMD_KERNNAME                              "genkernel"
+
+       set_config_with_override STRING CHECK_FREE_DISK_SPACE_BOOTDIR         
CMD_CHECK_FREE_DISK_SPACE_BOOTDIR
+       set_config_with_override STRING CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR 
CMD_CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR
+
+       set_config_with_override STRING COMPRESS_INITRD                       
CMD_COMPRESS_INITRD                       "$DEFAULT_COMPRESS_INITRD"
+       set_config_with_override STRING COMPRESS_INITRD_TYPE                  
CMD_COMPRESS_INITRD_TYPE                  "$DEFAULT_COMPRESS_INITRD_TYPE"
+       set_config_with_override STRING MAKEOPTS                              
CMD_MAKEOPTS                              "$DEFAULT_MAKEOPTS"
+       set_config_with_override STRING NICE                                  
CMD_NICE                                  "10"
+       set_config_with_override STRING KERNEL_MAKE                           
CMD_KERNEL_MAKE                           "$DEFAULT_KERNEL_MAKE"
+       set_config_with_override STRING UTILS_CFLAGS                          
CMD_UTILS_CFLAGS                          "$DEFAULT_UTILS_CFLAGS"
+       set_config_with_override STRING UTILS_MAKE                            
CMD_UTILS_MAKE                            "$DEFAULT_UTILS_MAKE"
+       set_config_with_override STRING KERNEL_CC                             
CMD_KERNEL_CC                             "$DEFAULT_KERNEL_CC"
+       set_config_with_override STRING KERNEL_LD                             
CMD_KERNEL_LD                             "$DEFAULT_KERNEL_LD"
+       set_config_with_override STRING KERNEL_AS                             
CMD_KERNEL_AS                             "$DEFAULT_KERNEL_AS"
+       set_config_with_override STRING UTILS_CC                              
CMD_UTILS_CC                              "$DEFAULT_UTILS_CC"
+       set_config_with_override STRING UTILS_LD                              
CMD_UTILS_LD                              "$DEFAULT_UTILS_LD"
+       set_config_with_override STRING UTILS_AS                              
CMD_UTILS_AS                              "$DEFAULT_UTILS_AS"
+
+       set_config_with_override STRING CROSS_COMPILE                         
CMD_CROSS_COMPILE
+       set_config_with_override STRING BOOTDIR                               
CMD_BOOTDIR                               "/boot"
+       set_config_with_override STRING KERNEL_OUTPUTDIR                      
CMD_KERNEL_OUTPUTDIR                      "${KERNEL_DIR}"
+       set_config_with_override STRING KERNEL_LOCALVERSION                   
CMD_KERNEL_LOCALVERSION
+       set_config_with_override STRING MODPROBEDIR                           
CMD_MODPROBEDIR                           "/etc/modprobe.d"
+
+       set_config_with_override BOOL   SPLASH                                
CMD_SPLASH                                "no"
+       set_config_with_override BOOL   CLEAR_CACHEDIR                        
CMD_CLEAR_CACHEDIR                        "no"
+       set_config_with_override BOOL   POSTCLEAR                             
CMD_POSTCLEAR                             "no"
+       set_config_with_override BOOL   MRPROPER                              
CMD_MRPROPER                              "yes"
+       set_config_with_override BOOL   MENUCONFIG                            
CMD_MENUCONFIG                            "no"
+       set_config_with_override BOOL   GCONFIG                               
CMD_GCONFIG                               "no"
+       set_config_with_override BOOL   NCONFIG                               
CMD_NCONFIG                               "no"
+       set_config_with_override BOOL   XCONFIG                               
CMD_XCONFIG                               "no"
+       set_config_with_override BOOL   CLEAN                                 
CMD_CLEAN                                 "yes"
+
+       set_config_with_override STRING MINKERNPACKAGE                        
CMD_MINKERNPACKAGE
+       set_config_with_override STRING MODULESPACKAGE                        
CMD_MODULESPACKAGE
+       set_config_with_override BOOL   MODULEREBUILD                         
CMD_MODULEREBUILD                         "yes"
+       set_config_with_override STRING KERNCACHE                             
CMD_KERNCACHE
+       set_config_with_override BOOL   RAMDISKMODULES                        
CMD_RAMDISKMODULES                        "yes"
+       set_config_with_override BOOL   ALLRAMDISKMODULES                     
CMD_ALLRAMDISKMODULES                     "no"
+       set_config_with_override STRING INITRAMFS_OVERLAY                     
CMD_INITRAMFS_OVERLAY
+       set_config_with_override BOOL   MOUNTBOOT                             
CMD_MOUNTBOOT                             "yes"
+       set_config_with_override BOOL   BUILD_STATIC                          
CMD_STATIC                                "no"
+       set_config_with_override BOOL   SAVE_CONFIG                           
CMD_SAVE_CONFIG                           "yes"
+       set_config_with_override BOOL   SYMLINK                               
CMD_SYMLINK                               "no"
+       set_config_with_override STRING INSTALL_MOD_PATH                      
CMD_INSTALL_MOD_PATH
+       set_config_with_override BOOL   OLDCONFIG                             
CMD_OLDCONFIG                             "yes"
+       set_config_with_override BOOL   SANDBOX                               
CMD_SANDBOX                               "yes"
+       set_config_with_override BOOL   SSH                                   
CMD_SSH                                   "no"
+       set_config_with_override STRING SSH_AUTHORIZED_KEYS_FILE              
CMD_SSH_AUTHORIZED_KEYS_FILE              "/etc/dropbear/authorized_keys"
+       set_config_with_override STRING SSH_HOST_KEYS                         
CMD_SSH_HOST_KEYS                         "create"
+       set_config_with_override BOOL   STRACE                                
CMD_STRACE                                "no"
+       set_config_with_override BOOL   BCACHE                                
CMD_BCACHE                                "no"
+       set_config_with_override BOOL   LVM                                   
CMD_LVM                                   "no"
+       set_config_with_override BOOL   DMRAID                                
CMD_DMRAID                                "no"
+       set_config_with_override BOOL   ISCSI                                 
CMD_ISCSI                                 "no"
+       set_config_with_override BOOL   HYPERV                                
CMD_HYPERV                                "no"
+       set_config_with_override STRING BOOTLOADER                            
CMD_BOOTLOADER                            "no"
+       set_config_with_override BOOL   BUSYBOX                               
CMD_BUSYBOX                               "yes"
+       set_config_with_override STRING BUSYBOX_CONFIG                        
CMD_BUSYBOX_CONFIG
+       set_config_with_override BOOL   NFS                                   
CMD_NFS                                   "yes"
+       set_config_with_override STRING MICROCODE                             
CMD_MICROCODE                             "all"
+       set_config_with_override BOOL   MICROCODE_INITRAMFS                   
CMD_MICROCODE_INITRAMFS                   "yes"
+       set_config_with_override BOOL   UNIONFS                               
CMD_UNIONFS                               "no"
+       set_config_with_override BOOL   NETBOOT                               
CMD_NETBOOT                               "no"
+       set_config_with_override STRING REAL_ROOT                             
CMD_REAL_ROOT
+       set_config_with_override BOOL   DISKLABEL                             
CMD_DISKLABEL                             "yes"
+       set_config_with_override BOOL   LUKS                                  
CMD_LUKS                                  "no"
+       set_config_with_override BOOL   GPG                                   
CMD_GPG                                   "no"
+       set_config_with_override BOOL   MDADM                                 
CMD_MDADM                                 "no"
+       set_config_with_override STRING MDADM_CONFIG                          
CMD_MDADM_CONFIG
+       set_config_with_override BOOL   E2FSPROGS                             
CMD_E2FSPROGS                             "no"
+       set_config_with_override BOOL   XFSPROGS                              
CMD_XFSPROGS                              "no"
+       set_config_with_override BOOL   ZFS                                   
CMD_ZFS                                   "$(rootfs_type_is zfs)"
+       set_config_with_override BOOL   BTRFS                                 
CMD_BTRFS                                 "$(rootfs_type_is btrfs)"
+       set_config_with_override BOOL   VIRTIO                                
CMD_VIRTIO                                "no"
+       set_config_with_override BOOL   MULTIPATH                             
CMD_MULTIPATH                             "no"
+       set_config_with_override BOOL   FIRMWARE                              
CMD_FIRMWARE                              "no"
+       set_config_with_override STRING FIRMWARE_DIR                          
CMD_FIRMWARE_DIR                          "/lib/firmware"
+       set_config_with_override STRING FIRMWARE_FILES                        
CMD_FIRMWARE_FILES
+       set_config_with_override BOOL   FIRMWARE_INSTALL                      
CMD_FIRMWARE_INSTALL                      "no"
+       set_config_with_override BOOL   INTEGRATED_INITRAMFS                  
CMD_INTEGRATED_INITRAMFS                  "no"
+       set_config_with_override BOOL   WRAP_INITRD                           
CMD_WRAP_INITRD                           "no"
+       set_config_with_override BOOL   GENZIMAGE                             
CMD_GENZIMAGE                             "no"
+       set_config_with_override BOOL   KEYMAP                                
CMD_KEYMAP                                "yes"
+       set_config_with_override BOOL   DOKEYMAPAUTO                          
CMD_DOKEYMAPAUTO                          "no"
+       set_config_with_override STRING BUSYBOX_CONFIG                        
CMD_BUSYBOX_CONFIG
+       set_config_with_override STRING STRIP_TYPE                            
CMD_STRIP_TYPE                            "modules"
+       set_config_with_override BOOL   INSTALL                               
CMD_INSTALL                               "yes"
+       set_config_with_override BOOL   CLEANUP                               
CMD_CLEANUP                               "yes"
 
        local can_write_log=no
        if [ -w "${LOGFILE}" ]

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$') )
 

diff --git a/genkernel b/genkernel
index d5e9b06..0368acd 100755
--- a/genkernel
+++ b/genkernel
@@ -197,6 +197,8 @@ fi
 
 isTrue "${CMD_INSTALL}" && make_bootdir_writable
 
+check_disk_space_requirements
+
 if isTrue "${BUILD_KERNEL}" && ! isTrue "${KERNCACHE_IS_VALID}"
 then
        print_info 1 '' 1 0

diff --git a/genkernel.conf b/genkernel.conf
index b2af4de..0c1a2e7 100644
--- a/genkernel.conf
+++ b/genkernel.conf
@@ -52,6 +52,12 @@ NOCOLOR="false"
 # Clear all tmp files and caches after genkernel has run
 #POSTCLEAR="no"
 
+# Check for x MB free disk space in BOOTDIR
+#CHECK_FREE_DISK_SPACE_BOOTDIR=0
+
+# Check for x MB free disk space in kernel outputdir
+#CHECK_FREE_DISK_SPACE_KERNELOUTPUTDIR=0
+
 # Genkernel uses an independent configuration for MAKEOPTS, and does not source
 # /etc/portage/make.conf . You can override the default setting by uncommenting
 # and tweaking the following line. Default setting is set up by

Reply via email to