genkernel: Add --kconfig to set specific kernel config options
[genkernel.git] / gen_package.sh
index 3b0c046e754fe8976fcef51e1c6997a444d17bb5..ed7a5f4d9a43baf9e0e206e0556da16377a34d62 100755 (executable)
@@ -1,4 +1,5 @@
 #!/bin/bash
+# $Id$
 
 gen_minkernpackage() {
        print_info 1 'Creating minimal kernel package'
@@ -19,7 +20,7 @@ gen_minkernpackage() {
                then
                        gen_die "Cannot locate kernel binary"
                fi
-               cd "${KERNEL_DIR}"
+               cd "${KERNEL_OUTPUTDIR}"
                cp "${tmp_kernel_binary}" "${TEMP}/minkernpackage/kernel-${KV}" || gen_die 'Could not the copy kernel for the min kernel package!'
                cp ".config" "${TEMP}/minkernpackage/config-${ARCH}-${KV}" || gen_die 'Could not the copy kernel config for the min kernel package!'
                if isTrue "${GENZIMAGE}"
@@ -27,20 +28,20 @@ gen_minkernpackage() {
                        cp "${tmp_kernel_binary2}" "${TEMP}/minkernpackage/kernelz-${KV}" || gen_die "Could not copy the kernelz for the min kernel package"
                fi
        fi
-       
+
        if ! isTrue "${INTEGRATED_INITRAMFS}"
        then
-               [ "${BUILD_RAMDISK}" -ne 0 ] && { cp "${TMPDIR}/initramfs-${KV}" "${TEMP}/minkernpackage/initramfs-${ARCH}-${KV}" || gen_die 'Could not copy the initramfs for the kernel package!'; }
+               [ "${BUILD_RAMDISK}" != '0' ] && { cp "${TMPDIR}/initramfs-${KV}" "${TEMP}/minkernpackage/initramfs-${ARCH}-${KV}" || gen_die 'Could not copy the initramfs for the kernel package!'; }
        fi
 
        if [ "${KERNCACHE}" != "" ]
        then
                /bin/tar -xj -C ${TEMP}/minkernpackage -f ${KERNCACHE} System.map-${ARCH}-${KV}
        else
-               cp "${KERNEL_DIR}/System.map" "${TEMP}/minkernpackage/System.map-${ARCH}-${KV}" || gen_die 'Could not copy System.map for the kernel package!';
+               cp "${KERNEL_OUTPUTDIR}/System.map" "${TEMP}/minkernpackage/System.map-${ARCH}-${KV}" || gen_die 'Could not copy System.map for the kernel package!';
        fi
-       
-       cd "${TEMP}/minkernpackage" 
+
+       cd "${TEMP}/minkernpackage"
        /bin/tar -jcpf ${MINKERNPACKAGE} * || gen_die 'Could not compress the kernel package!'
        cd "${TEMP}" && rm -rf "${TEMP}/minkernpackage" > /dev/null 2>&1
 }
@@ -74,36 +75,42 @@ gen_kerncache()
                gen_die "Cannot locate kernel binary"
        fi
 
-       cd "${KERNEL_DIR}"
+       cd "${KERNEL_OUTPUTDIR}"
        cp "${tmp_kernel_binary}" "${TEMP}/kerncache/kernel-${ARCH}-${KV}" || gen_die 'Could not the copy kernel for the kernel package!'
-       cp "${KERNEL_DIR}/.config" "${TEMP}/kerncache/config-${ARCH}-${KV}"
-       cp "${KERNEL_CONFIG}" "${TEMP}/kerncache/config-${ARCH}-${KV}.orig"
-       cp "${KERNEL_DIR}/System.map" "${TEMP}/kerncache/System.map-${ARCH}-${KV}"
+       cp "${KERNEL_OUTPUTDIR}/.config" "${TEMP}/kerncache/config-${ARCH}-${KV}"
+
+       if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then
+               # Support --kernel-config=/proc/config.gz, mainly
+               zcat "${KERNEL_CONFIG}" > "${TEMP}/kerncache/config-${ARCH}-${KV}.orig"
+       else
+               cp "${KERNEL_CONFIG}" "${TEMP}/kerncache/config-${ARCH}-${KV}.orig"
+       fi
+       cp "${KERNEL_OUTPUTDIR}/System.map" "${TEMP}/kerncache/System.map-${ARCH}-${KV}"
        if isTrue "${GENZIMAGE}"
        then
                cp "${tmp_kernel_binary2}" "${TEMP}/kerncache/kernelz-${ARCH}-${KV}" || gen_die "Could not copy the kernelz for the kernel package"
        fi
-       
+
        echo "VERSION = ${VER}" > "${TEMP}/kerncache/kerncache.config"
        echo "PATCHLEVEL = ${PAT}" >> "${TEMP}/kerncache/kerncache.config"
        echo "SUBLEVEL = ${SUB}" >> "${TEMP}/kerncache/kerncache.config"
        echo "EXTRAVERSION = ${EXV}" >> "${TEMP}/kerncache/kerncache.config"
-       
+
        mkdir -p "${TEMP}/kerncache/lib/modules/"
-       
+
        if [ -d ${INSTALL_MOD_PATH}/lib/modules/${KV} ]
        then
            cp -r "${INSTALL_MOD_PATH}/lib/modules/${KV}" "${TEMP}/kerncache/lib/modules"
        fi
-       
-       cd "${TEMP}/kerncache" 
+
+       cd "${TEMP}/kerncache"
        /bin/tar -jcpf ${KERNCACHE} * || gen_die 'Could not compress the kernel package!'
        cd "${TEMP}" && rm -rf "${TEMP}/kerncache" > /dev/null 2>&1
 }
 
 gen_kerncache_extract_kernel()
 {
-       /bin/tar -f ${KERNCACHE} -C ${TEMP} -xj 
+       /bin/tar -f ${KERNCACHE} -C ${TEMP} -xj
        copy_image_with_preserve "kernel" \
                "${TEMP}/kernel-${ARCH}-${KV}" \
                "kernel-${KNAME}-${ARCH}-${KV}"
@@ -114,7 +121,7 @@ gen_kerncache_extract_kernel()
                        "${TEMP}/kernelz-${ARCH}-${KV}" \
                        "kernelz-${KNAME}-${ARCH}-${KV}"
        fi
-    
+
        copy_image_with_preserve "System.map" \
                "${TEMP}/System.map-${ARCH}-${KV}" \
                "System.map-${KNAME}-${ARCH}-${KV}"
@@ -122,7 +129,7 @@ gen_kerncache_extract_kernel()
 
 gen_kerncache_extract_modules()
 {
-        if [ -e "${KERNCACHE}" ] 
+        if [ -e "${KERNCACHE}" ]
        then
                print_info 1 'Extracting kerncache kernel modules'
                if [ "${INSTALL_MOD_PATH}" != '' ]
@@ -136,7 +143,7 @@ gen_kerncache_extract_modules()
 
 gen_kerncache_extract_config()
 {
-       if [ -e "${KERNCACHE}" ] 
+       if [ -e "${KERNCACHE}" ]
        then
                print_info 1 'Extracting kerncache config to /etc/kernels'
                mkdir -p /etc/kernels
@@ -155,15 +162,15 @@ gen_kerncache_is_valid()
                # Can make this more secure ....
 
                /bin/tar -xj -f ${KERNCACHE} -C ${TEMP}
-               if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e ${TEMP}/kernel-${ARCH}-${KV} ] 
-               then 
+               if [ -e ${TEMP}/config-${ARCH}-${KV} -a -e ${TEMP}/kernel-${ARCH}-${KV} ]
+               then
                        print_info 1 'Valid kernel cache found; no sources will be used'
                        KERNCACHE_IS_VALID=1
                fi
        else
-               if [ -e "${KERNCACHE}" ] 
+               if [ -e "${KERNCACHE}" ]
                then
-                       KERNEL_CONFIG="/${KERNEL_DIR}/.config"
+                       KERNEL_CONFIG="/${KERNEL_OUTPUTDIR}/.config"
                        if [ "${CMD_KERNEL_CONFIG}" != '' ]
                        then
                                KERNEL_CONFIG="${CMD_KERNEL_CONFIG}"
@@ -179,10 +186,18 @@ gen_kerncache_is_valid()
                                else
                                        test1=$(grep -v "^#" ${TEMP}/config-${ARCH}-${KV} | md5sum | cut -d " " -f 1)
                                fi
-                               test2=$(grep -v "^#" ${KERNEL_CONFIG} | md5sum | cut -d " " -f 1)
+
+                               if [[ "$(file --brief --mime-type "${KERNEL_CONFIG}")" == application/x-gzip ]]; then
+                                       # Support --kernel-config=/proc/config.gz, mainly
+                                       local CONFGREP=zgrep
+                               else
+                                       local CONFGREP=grep
+                               fi
+                               test2=$("${CONFGREP}" -v "^#" ${KERNEL_CONFIG} | md5sum | cut -d " " -f 1)
+
+
                                if [ "${test1}" == "${test2}" ]
                                then
-       
                                        echo
                                        print_info 1 "No kernel configuration change, skipping kernel build..."
                                        echo
@@ -191,6 +206,6 @@ gen_kerncache_is_valid()
                        fi
                fi
        fi
-       export KERNCACHE_IS_VALID       
+       export KERNCACHE_IS_VALID
        return 1
 }