add debirf files
[libguestfs.git] / appliance / debian / modules / install_kernel
1 #!/bin/bash -e
2
3 # debirf module: install-kernel
4 # install a kernel package, indicated by the expected environment
5 # variables:
6 #  DEBIRF_PATH
7 #  DEBIRF_ROOT
8 #  DEBIRF_KERNEL_PACKAGE
9 #
10 # *** REQUIRED MODULE ***
11 # WARNING: this module is necessary for proper functioning of debirf.
12 #
13 # The debirf scripts were written by
14 # Jameson Rollins <jrollins@fifthhorseman.net>
15 # and
16 # Daniel Kahn Gillmor <dkg-debian.org@fifthhorseman.net>.
17 #
18 # They are Copyright 2007, and are all released under the GPL,
19 # version 3 or later.
20
21 # clear out old modules if they exist, to avoid confusion
22 rm -rf "$DEBIRF_ROOT/lib/modules"
23
24 # download/copy in kernel package
25 if [ -z "$DEBIRF_KERNEL_PACKAGE" ] ; then
26     # determine kernel to install. assume arch of build host.
27
28     # determine kernel arch.  need everything after the kernel version
29     # and debian version
30     if [ -z "$DEBIRF_KERNEL_ARCH" ]; then
31         KARCH=$(uname -r | cut -d- -f3-)
32     else
33         KARCH="$DEBIRF_KERNEL_ARCH"
34     fi
35
36     # determine the full kernel version from the dependency of the
37     # generic 2.6-ARCH package in the debirf root (since it may be
38     # different than what is installed on the build host)
39     KNAME=$(debirf_exec apt-cache show linux-image-2.6-"$KARCH" | grep '^Depends: ' | sed 's/^Depends: //')
40
41     # download only the desired kernel package directly into the apt
42     # cache for dpkg extraction
43     debirf_exec sh -c "cd /var/cache/apt/archives/ && aptitude download \"$KNAME\""
44 else
45     # install kernel deb if given at command line
46     debirf_exec sh -c "cd /var/cache/apt/archives/ && aptitude download \"$DEBIRF_KERNEL_PACKAGE\""
47 fi
48
49 KPKG=$(basename "$DEBIRF_ROOT"/var/cache/apt/archives/linux-image-2.6.*)
50
51 echo "extracting kernel package $KPKG..."
52 debirf_exec dpkg --extract /var/cache/apt/archives/"$KPKG" /
53
54 # install the module init tools, since they are needed for depmod
55 debirf_exec apt-get --assume-yes install module-init-tools
56
57 # depmod to create module list
58 KVERS=$(ls -1 -t "$DEBIRF_ROOT/lib/modules" | head -n1)
59 echo "generating modules.dep..."
60 debirf_exec depmod -a "$KVERS"
61
62 # extract kernel and debian stock initrd from the build root:
63 mv "$DEBIRF_ROOT"/boot/vmlinu* "$DEBIRF_BUILDD"
64
65 # remove kernel symlinks
66 if [ -L "$DEBIRF_ROOT"/vmlinuz ] ; then
67     rm "$DEBIRF_BUILDD"/vmlinuz
68 fi