| 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@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 | KARCH=$(uname -r | cut -d- -f3-) |
|---|
| 31 | |
|---|
| 32 | # determine the full kernel version from the dependency of the |
|---|
| 33 | # generic 2.6-ARCH package in the debirf root (since it may be |
|---|
| 34 | # different than what is installed on the build host) |
|---|
| 35 | KNAME=$(debirf_exec apt-cache show linux-image-"$KARCH" | grep '^Depends: ' | sed 's/^Depends: //' | tr ',' '\n' | tr -d ' ' | grep ^linux-image | sort -r | head -n1) |
|---|
| 36 | |
|---|
| 37 | # download only the desired kernel package directly into the apt |
|---|
| 38 | # cache for dpkg extraction |
|---|
| 39 | debirf_exec sh -c "cd /var/cache/apt/archives/ && aptitude download \"$KNAME\"" |
|---|
| 40 | |
|---|
| 41 | else |
|---|
| 42 | # install kernel deb if given at command line |
|---|
| 43 | cp "$DEBIRF_KERNEL_PACKAGE" "$DEBIRF_ROOT"/var/cache/apt/archives/ |
|---|
| 44 | fi |
|---|
| 45 | |
|---|
| 46 | KPKG=$(basename "$DEBIRF_ROOT"/var/cache/apt/archives/linux-image-2.6.*) |
|---|
| 47 | |
|---|
| 48 | echo "extracting kernel package $KPKG..." |
|---|
| 49 | debirf_exec dpkg --extract /var/cache/apt/archives/"$KPKG" / |
|---|
| 50 | |
|---|
| 51 | # install the module init tools, since they are needed for depmod |
|---|
| 52 | debirf_exec apt-get --assume-yes install module-init-tools |
|---|
| 53 | |
|---|
| 54 | # depmod to create module list |
|---|
| 55 | KVERS=$(ls -1 -t "$DEBIRF_ROOT/lib/modules" | head -n1) |
|---|
| 56 | echo "generating modules.dep..." |
|---|
| 57 | debirf_exec depmod -a "$KVERS" |
|---|
| 58 | |
|---|
| 59 | # extract kernel and debian stock initrd from the build root: |
|---|
| 60 | mv "$DEBIRF_ROOT"/boot/vmlinu* "$DEBIRF_BUILDD" |
|---|
| 61 | |
|---|
| 62 | # remove kernel symlinks |
|---|
| 63 | if [ -L "$DEBIRF_ROOT"/vmlinuz ] ; then |
|---|
| 64 | rm "$DEBIRF_BUILDD"/vmlinuz |
|---|
| 65 | fi |
|---|