summaryrefslogtreecommitdiffstats
path: root/core/modules/vbox/module.build
blob: 0f62eab465a6062ee61d8d9022346dcb8d568351 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash

patch_vbox_scripts() {
	# Patching virtualbox utility scripts to include openslx-busybox binary paths. Strange sed-ing, as the openslx
	# binary paths need to be at the end of PATH to not impede with system binaries. 
	# It seems sufficient to patch just VBox, as eg. vboxmanage, vboxheadless etc. are just links to VBox.
	# If only vboxmanage, vboxheadless or such should be patched (and not the base script VBox) just use a list
	# in the loop (eg. 'for i in virtualbox vboxmanage vboxheadless; do'). These links will be replaced by patched
	# 'real' files. Of course it will not make sense if VBox is included in the list, then.
	# Patched files will be saved with extension .original.

	pinfo "Patching virtual box scripts to include openslx (busybox)-paths ..."
	for i in VBox; do
		pinfo "Patching virtual box script $i ..."
		SCRIPTPATH=$(grep -m 1 PATH "${MODULE_BUILD_DIR}/usr/bin/$i"|sed 's/"//g')		# assume first hit is real path
		sed -i "-i.original" "/^PATH=/c ${SCRIPTPATH}:/opt/openslx/bin:/opt/openslx/sbin"\
		       	"${MODULE_BUILD_DIR}/usr/bin/$i"						# append openslx paths
	done

	# due to problems with group membership of kdm-spawned processes we need to
	# patch ${MODULE_BUILD_DIR}/usr/share/virtualbox/VBoxCreateUSBNode.sh:
	sed -i "s/0750/0755/g" "${MODULE_BUILD_DIR}/usr/share/virtualbox/VBoxCreateUSBNode.sh"
	sed -i "s/0660/0666/g" "${MODULE_BUILD_DIR}/usr/share/virtualbox/VBoxCreateUSBNode.sh"
}

extract_extpack() {
	pinfo "Unpacking Extension Pack ..."
	mkdir -p "${MODULE_BUILD_DIR}/usr/lib/virtualbox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack"
	cp    "${MODULE_WORK_DIR}"/src/vbox/extpack/[EP][xX][tE]* "${MODULE_BUILD_DIR}"/usr/lib/virtualbox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack
	if [ x${AMD64_X86} == "xamd64" ]; then
		pinfo "Unpacking 64bit branch of Extension Pack ..."
		cp -r "${MODULE_WORK_DIR}/src/vbox/extpack/linux.amd64" "${MODULE_BUILD_DIR}/usr/lib/virtualbox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack"
	else	# then we assume 32bit x86...
		pinfo "Unpacking32bit branch of Extension Pack ..."
		cp -r "${MODULE_WORK_DIR}/src/vbox/extpack/linux.x86" "${MODULE_BUILD_DIR}/usr/lib/virtualbox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack"
	fi
}

build_modules() {
	pinfo "Recompiling VirtualBox kernel modules ..."
	# Set some variables to use/patch VBox scripts
	local MODULE_SRC="${MODULE_BUILD_DIR}/usr/share/virtualbox/src/vboxhost"
	local BUILDINTMP="$MODULE_SRC/build_in_tmp"
	local BUILDSUBDIR="modules"

	# Some Vars for VBs kernel module makefiles
	MODULE_DIR_ALT="$MODULE_DIR"	# save usual MODULE_DIR
	export KERN_DIR="${MODULE_WORK_DIR}/../kernel/build/lib/modules/$(ls ${MODULE_WORK_DIR}/../kernel/build/lib/modules/)/build/"
	pinfo "Using Kernel dir $KERN_DIR"
	# export MODULE_DIR="${MODULE_WORK_DIR}/../kernel/build/lib/modules/$(ls ${MODULE_WORK_DIR}/../kernel/build/lib/modules/)/kernel/misc"
	export MODULE_DIR="${MODULE_WORK_DIR}/build/lib/modules/vbox"

	pinfo "Recompiling VirtualBox kernel module vboxdrv ..."
	if ! $BUILDINTMP \
		--save-module-symvers /tmp/vboxdrv-Module.symvers \
		--module-source "$MODULE_SRC/vboxdrv" \
		--no-print-directory install;
	then
		perror "[vbox]: Error compiling VirtualBox kernel module vboxdrv"
	fi
	pinfo "Recompiling VirtualBox kernel module vboxnetflt ..."
	if ! $BUILDINTMP \
		--use-module-symvers /tmp/vboxdrv-Module.symvers \
		--module-source "$MODULE_SRC/vboxnetflt" \
		--no-print-directory install;
	then
		perror "[vbox]: Error compiling VirtualBox kernel module vboxnetflt"
	fi
	pinfo "Recompiling VirtualBox kernel module vboxnetadp ..."
	if ! $BUILDINTMP \
		--use-module-symvers /tmp/vboxdrv-Module.symvers \
		--module-source "$MODULE_SRC/vboxnetadp" \
		--no-print-directory install;
	then
		perror "[vbox]: Error compiling VirtualBox kernel module vboxnetadp"
	fi
	pinfo "Recompiling VirtualBox kernel module vboxpci ..."
	if ! $BUILDINTMP \
		--use-module-symvers /tmp/vboxdrv-Module.symvers \
		--module-source "$MODULE_SRC/vboxpci" \
		--no-print-directory install;
	then
		perror "[vbox]: Error compiling VirtualBox kernel module vboxpci"
	fi
	pinfo "Compiled successfully the VirtualBox kernel modules."
	export MODULE_DIR="$MODULE_DIR_ALT"	# re-set MODULE_DIR
}


fetch_source() {
	if [ -z "$REQUIRED_VBOXBASEURL" -o -z "$REQUIRED_VBOXEXTURL" ]; then
		perror "Virtualbox download URLs not set - please write a module.conf-file for your linux flavour."
	fi

	mkdir -p "src/vbox"
	cd src/vbox
	# pinfo "Downloading $REQUIRED_VBOXBASEURL"
	download "$REQUIRED_VBOXBASEURL"
	# pinfo "Downloading $REQUIRED_VBOXEXTURL"
	download_untar "$REQUIRED_VBOXEXTURL" "extpack" "vbox_extpack.tar.gz"
	cd -
}


build() {
	case "$PACKET_HANDLER" in
		rpm)
			pinfo "Unpacking rpm ..."
			cd build || perror "Cannot cd to build directory!"
 			rpm2cpio ../src/vbox/$(basename "$REQUIRED_VBOXBASEURL")|cpio -idmv || perror "Could not unpack rpm-archive!"
			# it seems that sometimes directories from rpm will be created with 700-permissions,
			# if that directory is not explicitly mentioned to create. So eg. usr, etc will carry the
			# permissions 700, which is no fun. So we search for these directories and correct them.
			find .  -type d -perm 700 -exec chmod 755 {} \; 
			;;
		dpkg )
			pinfo "Unpacking deb ..."
			cd build || perror "Cannot cd to build directory!"
			dpkg -x ../src/vbox/$(basename "$REQUIRED_VBOXBASEURL") . || perror "Could not unpack deb-archive!"
			# VirtualBox needs to be suid-root:
			for i in VBoxHeadless VBoxNetAdpCtl VBoxNetDHCP VBoxSDL VBoxVolInfo VirtualBox VBoxNetAdpCtl; do
				chmod u+s ${MODULE_BUILD_DIR}/usr/lib/virtualbox/$i || pwarning "(Debian/Ubuntu) Could not suid $i executable!"
			done
			;;
		*) perror "Unknown Distribution: $SYS_DISTRIBUTION - Please specify its packet manager in remote/setup_target" ;;
	esac

	build_modules
	patch_vbox_scripts
	extract_extpack

	COPYLIST="list_dpkg_output"
	[ -e "$COPYLIST" ] && rm "$COPYLIST"
	list_packet_files >> "$COPYLIST"
	tarcopy "$(cat "$COPYLIST" | sort -u)" "${MODULE_BUILD_DIR}"
}

post_copy() {
	# clean a bit, as sometimes there are residual files in /tmp/vbox.*/
	rm -rf /tmp/vbox.*/
}