5 echo "Building VirtualBox guest modules"
7 hw_arch
="`dpkg --print-architecture`"
8 if [ "$hw_arch" != i386
-a "$hw_arch" != amd64
]; then
12 available_gcc_version
=4.4
13 wanted_gcc_version
=4.6
15 # the -dkms package must be installed *after* dkms to be properly registered
16 apt-get
install --yes build-essential dkms dpatch
18 # temporary workaround: pretend the "wanted" GCC is available, so that
19 # the modules can build.
20 # /usr/src/linux-headers-3.*-common/scripts/gcc-version.sh
21 # is the one who says they should be run using that version.
22 apt-get
install --yes gcc-
${available_gcc_version}
23 ln -s /usr
/bin
/gcc-
${available_gcc_version} /usr
/bin
/gcc-
${wanted_gcc_version}
25 # At this time of the build, we've got a recent enough X.Org installed,
26 # so we can install the X11 tools eventually.
28 /usr
/share
/amnesia
/packages
/virtualbox-guest-utils_
*.deb \
29 /usr
/share
/amnesia
/packages
/virtualbox-guest-x11_
*.deb
31 # Have the modules built for every installed kernel
32 for KERNEL
in /boot
/vmlinuz-
* ; do
33 KERNEL_VERSION
="$(basename ${KERNEL} | sed -e 's|vmlinuz-||')"
34 VERSION_SCHEME
="[[:digit:]]\+\(\.[[:digit:]]\+\)*-[[:digit:]]\+"
35 KERNEL_ARCH
="$(echo ${KERNEL_VERSION} | sed -e "s|
${VERSION_SCHEME}-||
")"
37 # dkms uses uname to find out what kernel to build modules for.
38 # So, after installing dkms, but before installing
39 # virtualbox-guest-dkms, we divert uname to a fake one that
40 # emulates 'uname -r' by reporting the kernel version found in /boot rather
41 # than the build system's one.
43 mv /bin
/uname
/bin
/uname.$$
44 cat > /bin
/uname
<<EOF
46 echo "$KERNEL_VERSION"
50 # Install the headers for the kernel we are build modules for
51 apt-get
install --yes linux-headers-$
(uname
-r)
53 # Have the modules automagically built by dkms for all kernels.
54 dpkg
--install /usr
/share
/amnesia
/packages
/virtualbox-guest-dkms_
*.deb
55 apt-get
-f install --yes
57 # Revert to the real uname.
58 mv /bin
/uname.$$
/bin
/uname
61 # clean the build directory
62 rm -r /var
/lib
/dkms
/virtualbox-guest
/
64 # virtualbox-guest-dkms's postrm script deletes any previously
65 # built binary module; let's delete it before purging the package.
66 rm /var
/lib
/dpkg
/info
/virtualbox-guest-dkms.prerm
68 # remove temporary workaround
69 rm /usr
/bin
/gcc-
${wanted_gcc_version}