fetch_source() { # get the source according to the distro if [ "x$PACKET_MANAGER" == "xapt" ]; then pdebug "apt-ing kernel source" apt-get source linux-image-${KERNEL_VERSION} [ ! -e ksrc ] && ln -s $(ls -d linux-*/) ksrc elif [ "x$PACKET_MANAGER" == "xzypper" ]; then pdebug "zypping kernel source" zypper si kernel-source # find src directory local SOURCE_DIR=$(rpm -ql kernel-source |grep -E -o '^/.*src/linux-[^/]+/' |head -1) [ -z "${SOURCE_DIR}" ] && perror "Could not determine directory of kernel source..." ln -sf "${SOURCE_DIR}" ksrc else pdebug "Packet manager not determined!" fi } build() { local TARGET_CONFIG_FILE="openslx.config" [ -e "${TARGET_CONFIG_FILE}" ] && rm -f "${TARGET_CONFIG_FILE}" # update config and copy to ksrc pinfo "Updating kernel config..." update_config cp "${TARGET_CONFIG_FILE}" ksrc/.config # make kernel with the new config cd ksrc || perror "Could not cd to ksrc, was the kernel source fetched properly?" pinfo "Preparing kernel for new config ('make oldconfig')" yes n | make oldconfig || perror "make oldconfig failed" pinfo "Compiling kernel... (this will take some time)" make || perror "make failed" # install modules to build directory pinfo "Installing kernel modules..." make INSTALL_MOD_PATH="${MODULE_BUILD_DIR}" INSTALL_MOD_STRIP=1 modules_install || perror "make modules_install failed in ${MODULE_BUILD_DIR}" cd - 2> /dev/null # copy kernel to build cp ksrc/arch/x86/boot/bzImage "${MODULE_BUILD_DIR}/${KERNEL_TARGET_NAME}" pinfo "Kernel was successfully built at ${MODULE_BUILD_DIR}/${KERNEL_TARGET_NAME}" [ -z "${KERNEL_BUILD_DIR}" ] && KERNEL_BUILD_DIR="${MODULE_BUILD_DIR}" } post_copy() { : } # helper function to update the current kernel config with our parameters update_config() { # first we need to update the current config local BASE_CONFIG_FILE="/boot/config-$(uname -r)" [ -e "${BASE_CONFIG_FILE}" ] || perror "$BASE_CONFIG_FILE could not be found! This should not happen." # check for our wanted config parameter local OPENSLX_WANTED_CONFIG="${ROOT_DIR}/data/kernel.wanted.config" [ -e "${OPENSLX_WANTED_CONFIG}" ] || perror "$OPENSLX_WANTED_CONFIG does not exist! Please add a list of wanted kernel config parameters." # copy basic config file cp "$BASE_CONFIG_FILE" "$TARGET_CONFIG_FILE" for WANTED_CONFIG in $(cat $OPENSLX_WANTED_CONFIG|sort -u); do local CONFIG_PARAM_NAME=$(echo $WANTED_CONFIG | awk -F "=" '{print $1}') local SEARCH_RESULT=$(grep "^$CONFIG_PARAM_NAME=" "$BASE_CONFIG_FILE") #echo "Process: $SEARCH_RESULT" # analyse results if [ "x$SEARCH_RESULT" == "x" ]; then # no match, add it echo $WANTED_CONFIG >> $TARGET_CONFIG_FILE else # match, change to our setting if they differ if [ "x${SEARCH_RESULT: -1}" != "x${WANTED_CONFIG: -1}" ]; then sed -i "s/$SEARCH_RESULT/$WANTED_CONFIG/" "$TARGET_CONFIG_FILE" fi fi done }