From 327b0ff6e03321f75d900b76ff7ec0ad7016bbfe Mon Sep 17 00:00:00 2001
From: "Cody A.W. Somerville" <cody.somerville@canonical.com>
Date: Fri, 17 Dec 2010 11:30:36 +0100
Subject: Fixing numbering of live kernels and initrd files when using
 syslinux.

---
 scripts/build/lb_binary_syslinux | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/scripts/build/lb_binary_syslinux b/scripts/build/lb_binary_syslinux
index 9a96c5d..46b607a 100755
--- a/scripts/build/lb_binary_syslinux
+++ b/scripts/build/lb_binary_syslinux
@@ -95,27 +95,28 @@ Syslinux_live_entry ()
 
 	case "${LB_BINARY_IMAGES}" in
 		iso*|usb*)
-			NUMBER="$(ls -1 ${KERNEL_PATH} | grep 'vmlinuz-' | wc -l)"
-
-			# Do not add numbering to filenames if first kernel/initrd
-			if [ "${NUMBER}" = "2" ]
+			if [ "${LABEL}" = "live" ]
 			then
-				NUMBER=""
+				# Do not number the default kernel / initrd files.
+				_NUMBER=""
+			else
+				# Use order of flavours in LB_LINUX_FLAVOURS for numbering.
+				_NUMBER="$(echo ${LB_LINUX_FLAVOURS} | awk -v FLAVOUR="${FLAVOUR}" 'BEGIN{RS=" "} {if($1 == FLAVOUR) print NR}')"
 			fi
 
-			# Note: ISOLINUX will not find the kernel if the name ends in ".img".
 			if [ -e ${KERNEL_PATH}/${KERNEL} ]
 			then
-				mv ${KERNEL_PATH}/${KERNEL} ${KERNEL_PATH}/vmlinuz${NUMBER}
+				# Note: ISOLINUX will not find the kernel if the name ends in ".img".
+				mv ${KERNEL_PATH}/${KERNEL} ${KERNEL_PATH}/vmlinuz${_NUMBER}
 			fi
 
 			if [ -e ${KERNEL_PATH}/${INITRD} ]
 			then
-				mv ${KERNEL_PATH}/${INITRD} ${KERNEL_PATH}/initrd${NUMBER}.img
+				mv ${KERNEL_PATH}/${INITRD} ${KERNEL_PATH}/initrd${_NUMBER}.img
 			fi
 
-			KERNEL=vmlinuz${NUMBER}
-			INITRD=initrd${NUMBER}.img
+			KERNEL=vmlinuz${_NUMBER}
+			INITRD=initrd${_NUMBER}.img
 		;;
 	esac
 
-- 
cgit v1.0