Merge remote-tracking branch 'flapflap/de-network_configuration'
[tails-test.git] / config / chroot_local-hooks / 50-virtualbox
blob937c00c270be7644690f5ccf3b7a7c35852bfd52
1 #!/bin/sh
3 set -e
5 echo "Building VirtualBox guest modules"
7 hw_arch="`dpkg --print-architecture`"
8 if [ "$hw_arch" != i386 -a "$hw_arch" != amd64 ]; then
9 exit 0
12 available_gcc_version=4.7
13 wanted_gcc_version=4.8
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}
24 # Create and install fake GCC package
25 apt-get install --yes equivs
26 cat > /root/gcc-${wanted_gcc_version}.control << EOF
27 Section: devel
28 Priority: optional
29 Homepage: https://tails.boum.org/
30 Standards-Version: 3.6.2
32 Package: gcc-${wanted_gcc_version}
33 Maintainer: Tails developers <amnesia@boum.org>
34 Architecture: all
35 Description: (Fake) GNU C compiler
36 Work around the fact that our Linux headers depend on gcc-${wanted_gcc_version},
37 which is unavailable on Wheezy.
38 EOF
39 cd /root ; equivs-build /root/gcc-${wanted_gcc_version}.control
40 dpkg -i gcc-${wanted_gcc_version}_1.0_all.deb
41 ln -sf /usr/bin/gcc-${available_gcc_version} /usr/bin/gcc-${wanted_gcc_version}
42 rm /root/gcc-${wanted_gcc_version}.control /root/gcc-${wanted_gcc_version}_1.0_all.deb
44 # Versions of the module prior to 4.2 do not built on 3.8 and later [Debian #704130].
45 # Install version from Wheezy backports.
46 apt-get install --yes virtualbox-guest-utils virtualbox-guest-dkms virtualbox-guest-x11
48 # Have the modules built for every installed kernel
49 for KERNEL in /boot/vmlinuz-* ; do
50 KERNEL_VERSION="$(basename ${KERNEL} | sed -e 's|vmlinuz-||')"
51 MODULES_VERSION="$(dpkg-query -W -f='${Version\n}' virtualbox-guest-dkms)"
53 # Installing the headers should trigger the building of the modules for that kernel
54 apt-get install --yes linux-headers-$KERNEL_VERSION
55 # Only build and install if it was not done already
56 if [ ! "$(dkms status -k $KERNEL_VERSION -m virtualbox-guest -v $MODULES_VERSION)" ]; then
57 dkms build -k $KERNEL_VERSION -m virtualbox-guest -v $MODULES_VERSION
58 dkms install -k $KERNEL_VERSION -m virtualbox-guest -v $MODULES_VERSION
61 done
63 # clean the build directory
64 rm -r /var/lib/dkms/virtualbox-guest/
66 # virtualbox-guest-dkms's postrm script deletes any previously
67 # built binary module; let's delete it before the package gets purged.
68 rm /var/lib/dpkg/info/virtualbox-guest-dkms.prerm
70 # Also copy the udev rules installed by virtualbox-guest-dkms to enable guest
71 # additions by default.
72 cp -a /lib/udev/rules.d/60-virtualbox-guest-dkms.rules /etc/udev/rules.d/
74 # remove temporary workaround
75 rm /usr/bin/gcc-${wanted_gcc_version}