Dynamically determine the correct kernel package name
authorEvgeni Golov <evgeni@grml.org>
Wed, 8 Aug 2012 06:25:22 +0000 (08:25 +0200)
committerMichael Prokop <mika@grml.org>
Tue, 14 Aug 2012 17:05:48 +0000 (19:05 +0200)
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

index 89f0f8d..3f55747 100755 (executable)
@@ -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
 }