Bug #351873: More livecd control, and initramfs livecd argument documentation.
[genkernel.git] / gen_configkernel.sh
index 053bd4a3a9f54b56d2be0f4fb7005669fcb5f662..6271ca03a7081afaeece4da6f1c19239bebc00b0 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
+# $Id$
 
+# Fills variable KERNEL_CONFIG
 determine_config_file() {
        if [ "${CMD_KERNEL_CONFIG}" != "" ]
        then
@@ -22,49 +24,70 @@ determine_config_file() {
        else
                gen_die 'Error: No kernel .config specified, or file not found!'
        fi
+    KERNEL_CONFIG="$(readlink -f "${KERNEL_CONFIG}")"
 }
 
 config_kernel() {
        determine_config_file
        cd "${KERNEL_DIR}" || gen_die 'Could not switch to the kernel directory!'
 
-       isTrue "${CLEAN}" && cp "${KERNEL_DIR}/.config" "${KERNEL_DIR}/.config.bak" > /dev/null 2>&1
+       # Backup current kernel .config
+       if isTrue "${MRPROPER}" || [ ! -f "${KERNEL_OUTPUTDIR}/.config" ]
+       then
+               print_info 1 "kernel: Using config from ${KERNEL_CONFIG}"
+               if [ -f "${KERNEL_OUTPUTDIR}/.config" ]
+               then
+                       NOW=`date +--%Y-%m-%d--%H-%M-%S`
+                       cp "${KERNEL_OUTPUTDIR}/.config" "${KERNEL_OUTPUTDIR}/.config${NOW}.bak" \
+                                       || gen_die "Could not backup kernel config (${KERNEL_OUTPUTDIR}/.config)"
+                       print_info 1 "        Previous config backed up to .config${NOW}.bak"
+               fi
+       fi
+
        if isTrue ${MRPROPER}
        then
                print_info 1 'kernel: >> Running mrproper...'
                compile_generic mrproper kernel
+       else
+               print_info 1 "kernel: --mrproper is disabled; not running 'make mrproper'."
        fi
 
-       # If we're not cleaning, then we don't want to try to overwrite the configs
+       # If we're not cleaning a la mrproper, then we don't want to try to overwrite the configs
        # or we might remove configurations someone is trying to test.
-
-       if isTrue "${CLEAN}"
-       then
-               print_info 1 "config: Using config from ${KERNEL_CONFIG}"
-               print_info 1 '        Previous config backed up to .config.bak'
-               cp "${KERNEL_CONFIG}" "${KERNEL_DIR}/.config" || gen_die 'Could not copy configuration file!'
+       if isTrue "${MRPROPER}" || [ ! -f "${KERNEL_OUTPUTDIR}/.config" ]
+       then
+               local message='Could not copy configuration file!'
+               if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then
+                       # Support --kernel-config=/proc/config.gz, mainly
+                       zcat "${KERNEL_CONFIG}" > "${KERNEL_OUTPUTDIR}/.config" || gen_die "${message}"
+               else
+                       cp "${KERNEL_CONFIG}" "${KERNEL_OUTPUTDIR}/.config" || gen_die "${message}"
+               fi
        fi
+
        if isTrue "${OLDCONFIG}"
        then
                print_info 1 '        >> Running oldconfig...'
                yes '' 2>/dev/null | compile_generic oldconfig kernel 2>/dev/null
+       else
+               print_info 1 "kernel: --oldconfig is disabled; not running 'make oldconfig'."
        fi
        if isTrue "${CLEAN}"
        then
                print_info 1 'kernel: >> Cleaning...'
                compile_generic clean kernel
        else
-               print_info 1 "config: --no-clean is enabled; leaving the .config alone."
+               print_info 1 "kernel: --clean is disabled; not running 'make clean'."
        fi
-       
+
        if isTrue ${MENUCONFIG}
        then
-               print_info 1 'config: >> Invoking menuconfig...'
-               compile_generic menuconfig runtask
+               print_info 1 'kernel: >> Invoking menuconfig...'
+               compile_generic menuconfig kernelruntask
                [ "$?" ] || gen_die 'Error: menuconfig failed!'
        elif isTrue ${CMD_GCONFIG}
        then
-               print_info 1 'config: >> Invoking gconfig...'
+               print_info 1 'kernel: >> Invoking gconfig...'
                compile_generic gconfig kernel
                [ "$?" ] || gen_die 'Error: gconfig failed!'
 
@@ -73,7 +96,7 @@ config_kernel() {
 
        if isTrue ${CMD_XCONFIG}
        then
-               print_info 1 'config: >> Invoking xconfig...'
+               print_info 1 'kernel: >> Invoking xconfig...'
                compile_generic xconfig kernel
                [ "$?" ] || gen_die 'Error: xconfig failed!'
        fi
@@ -83,25 +106,37 @@ config_kernel() {
        then
                # Make sure Ext2 support is on...
                sed -e 's/#\? \?CONFIG_EXT2_FS[ =].*/CONFIG_EXT2_FS=y/g' \
-                       -i ${KERNEL_DIR}/.config 
+                       -i ${KERNEL_OUTPUTDIR}/.config
        fi
 
        # Make sure lvm modules are on if --lvm
        if isTrue ${CMD_LVM}
        then
-               sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_BLK_DEV_DM is.*/CONFIG_BLK_DEV_DM=m/g'
-               sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_DM_SNAPSHOT is.*/CONFIG_DM_SNAPSHOT=m/g'
-               sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_DM_MIRROR is.*/CONFIG_DM_MIRROR=m/g'
+               sed -i ${KERNEL_OUTPUTDIR}/.config -e 's/#\? \?CONFIG_BLK_DEV_DM is.*/CONFIG_BLK_DEV_DM=m/g'
+               sed -i ${KERNEL_OUTPUTDIR}/.config -e 's/#\? \?CONFIG_DM_SNAPSHOT is.*/CONFIG_DM_SNAPSHOT=m/g'
+               sed -i ${KERNEL_OUTPUTDIR}/.config -e 's/#\? \?CONFIG_DM_MIRROR is.*/CONFIG_DM_MIRROR=m/g'
        fi
 
        # Make sure dmraid modules are on if --dmraid
        if isTrue ${CMD_DMRAID}
        then
-               sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_BLK_DEV_DM is.*/CONFIG_BLK_DEV_DM=m/g'
+               sed -i ${KERNEL_OUTPUTDIR}/.config -e 's/#\? \?CONFIG_BLK_DEV_DM is.*/CONFIG_BLK_DEV_DM=m/g'
+       fi
+
+       # Make sure iSCSI modules are enabled in the kernel, if --iscsi
+       # CONFIG_SCSI_ISCSI_ATTRS
+       # CONFIG_ISCSI_TCP
+       if isTrue ${CMD_ISCSI}
+       then
+               sed -i ${KERNEL_OUTPUTDIR}/.config -e 's/\# CONFIG_ISCSI_TCP is not set/CONFIG_ISCSI_TCP=m/g'
+               sed -i ${KERNEL_OUTPUTDIR}/.config -e 's/\# CONFIG_SCSI_ISCSI_ATTRS is not set/CONFIG_SCSI_ISCSI_ATTRS=m/g'
+
+               sed -i ${KERNEL_OUTPUTDIR}/.config -e 's/CONFIG_ISCSI_TCP=y/CONFIG_ISCSI_TCP=m/g'
+               sed -i ${KERNEL_OUTPUTDIR}/.config -e 's/CONFIG_SCSI_ISCSI_ATTRS=y/CONFIG_SCSI_ISCSI_ATTRS=m/g'
        fi
 
        if isTrue ${SPLASH}
        then
-               sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_FB_SPLASH is.*/CONFIG_FB_SPLASH=y/g'
+               sed -i ${KERNEL_OUTPUTDIR}/.config -e 's/#\? \?CONFIG_FB_SPLASH is.*/CONFIG_FB_SPLASH=y/g'
        fi
 }