supermin: Die with an error if no kernels found (RHBZ#539746).
[libguestfs.git] / appliance / libguestfs-supermin-helper.in
index 87fb688..4d8fd04 100755 (executable)
@@ -29,17 +29,29 @@ sourcedir=$(cd "$1" > /dev/null; pwd)
 kernel="$2"
 initrd="$3"
 
-# Look for the kernel first.  This is very unsophisticated: We
-# just look for any kernel named vmlinuz-*.$host_cpu which has a
-# corresponding /lib/modules/*.$host_cpu directory.
+# Kernel:
+# Look for the most recent kernel named vmlinuz-*.<arch>* which has a
+# corresponding directory in /lib/modules/. If the architecture is x86, look
+# for any x86 kernel.
+#
+# RHEL 5 didn't append the arch to the kernel name, so look for kernels
+# without arch second.
+
+arch=$(echo "@host_cpu@" | sed 's/^i.86$/i?86/')
+kernels=$(ls -1dvr /boot/vmlinuz-*.$arch* 2>/dev/null | grep -v xen; ls -1dvr /boot/vmlinuz-* 2>/dev/null | grep -v xen)
+
+if [ -z "$kernels" ]; then
+    echo "$0: failed to find a suitable kernel in /boot directory" >&2
+    exit 1
+fi
 
-for f in /boot/vmlinuz-*.@host_cpu@; do
+for f in $kernels; do
     b=$(basename "$f")
     b=$(echo "$b" | sed 's,vmlinuz-,,')
     modpath="/lib/modules/$b"
     if [ -d "$modpath" ]; then
-       ln -sf "$f" "$kernel"
-       break
+        ln -sf "$f" "$kernel"
+        break
     fi
     modpath=
 done
@@ -77,4 +89,4 @@ find "$modpath" \( -not -name '*.ko' $whitelist \) -a -print0 |
   ls -1df $(
       cat "$sourcedir"/initramfs.@REPO@.@host_cpu@.supermin.hostfiles
     ) 2>/dev/null |
-  cpio --quiet -o -H newc ) >> "$initrd"
+  cpio -C 65536 --quiet -o -H newc ) >> "$initrd"