summaryrefslogtreecommitdiffstats
path: root/remote/modules/kernel/kernel.build
blob: 0248a9808dfdb706919da12132527d05e49c5fa0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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 --no-refresh install -y 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
}