From 91e39fcde40898c7b5f4d5a96e042ab02ea40af3 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Wed, 8 Aug 2012 08:25:22 +0200 Subject: [PATCH] Dynamically determine the correct kernel package name Dynamically determine the correct kernel package name by checking if the package exists. This allows bootstrapping from a Debian ISO which, depending on the release, only contains the linux-image-2.6-$ARCH or the linux-image-$ARCH meta-package. Thanks to Ulrich Dangel for the initial patch and the great discussion! Closes: issue1206 --- chroot-script | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/chroot-script b/chroot-script index 89f0f8d..3f55747 100755 --- a/chroot-script +++ b/chroot-script @@ -249,21 +249,47 @@ extrapackages() { } # }}} -# install kernel packages {{{ -kernel() { +# check if the specified Debian package exists +package_exists() { + output=$(apt-cache show "$1" 2>/dev/null) + [ -n "$output" ] + return $? +} + + +# determine the kernel version postfix +get_kernel_version() { # do not override $KERNEL if set via config file - if [ -z "$KERNEL" ] ; then - if [ "$ARCH" = 'i386' ] ; then - KERNEL='2.6-686' - elif [ "$ARCH" = 'amd64' ] ; then - KERNEL='2.6-amd64' - fi + if [ -n "$KERNEL" ] ; then + echo "$KERNEL" + return 0 fi - if [ -n "$KERNEL" ] ; then - $APTUPDATE + case $ARCH in + i386) KARCH=i686 ;; + amd64) KARCH=amd64 ;; + *) + echo "Only i386 and amd64 are currently supported" >&2 + return 1 + esac + + for KPREFIX in "" "2.6-" ; do # iterate through the kernel prefixes, + # currently "" and "2.6-" + if package_exists linux-image-${KPREFIX}${KARCH} ; then + echo ${KPREFIX}${KARCH} + return 0 + fi + + done +} + +# install kernel packages {{{ +kernel() { + $APTUPDATE + KVER=$(get_kernel_version) + if [ -n "$KVER" ] ; then # note: install busybox to be able to debug initramfs - KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL busybox firmware-linux" + KERNELPACKAGES="linux-image-$KVER linux-headers-$KVER busybox firmware-linux" DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $KERNELPACKAGES fi } -- 2.1.4