Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Hlrln-0003jK-Ce for mharc-grub-devel@gnu.org; Wed, 09 May 2007 15:24:15 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Hlrlm-0003fx-2B for grub-devel@gnu.org; Wed, 09 May 2007 15:24:14 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Hlrll-0003f8-Ie for grub-devel@gnu.org; Wed, 09 May 2007 15:24:13 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hlrll-0003f5-Ex for grub-devel@gnu.org; Wed, 09 May 2007 15:24:13 -0400 Received: from aybabtu.com ([69.60.117.155]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HlreW-0001yI-RS for grub-devel@gnu.org; Wed, 09 May 2007 15:16:44 -0400 Received: from [192.168.10.6] (helo=aragorn) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1HlreU-0005uK-OC; Wed, 09 May 2007 21:16:43 +0200 Received: from rmh by aragorn with local (Exim 4.63) (envelope-from ) id 1Hlrfs-00081W-Mh; Wed, 09 May 2007 21:18:08 +0200 Date: Wed, 9 May 2007 21:18:08 +0200 From: Robert Millan To: grub-devel@gnu.org Message-ID: <20070509191808.GA30665@aragorn> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ikeVEW9yuYc//A+q" Content-Disposition: inline Organization: free as in freedom X-Message-Flag: Microsoft discourages use of Outlook. X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: Genre and OS details not recognized. Cc: 422580@bugs.debian.org Subject: implement proper sorting of linux images X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 May 2007 19:24:14 -0000 --ikeVEW9yuYc//A+q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Proper sorting of linux images requires more sophisticated logic than the sort command can provide. For example, we need to assert that foo.old is older than foo, but foo.bar is newer, etc. This brought me to implementing an inefficient (but simple) sorting algorithm for 10_linux.in. Seems to work for our (Debian's) needs. Do you have any comments or suggestions? -- Robert Millan My spam trap is honeypot@aybabtu.com. Note: this address is only intended for spam harvesters. Writing to it will get you added to my black list. --ikeVEW9yuYc//A+q Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="linux_sort.diff" diff -ur grub2-1.95+20070507.old/util/grub.d/10_linux.in grub2-1.95+20070507/util/grub.d/10_linux.in --- grub2-1.95+20070507.old/util/grub.d/10_linux.in 2007-05-05 12:34:05.000000000 +0200 +++ grub2-1.95+20070507/util/grub.d/10_linux.in 2007-05-09 17:22:36.000000000 +0200 @@ -23,12 +23,67 @@ OS="${GRUB_DISTRIBUTOR} GNU/Linux" fi +test_numeric () +{ + a=$1 + cmp=$2 + b=$3 + if [ "$a" = "$b" ] ; then + case $cmp in + ge|eq|le) return 0 ;; + gt|lt) return 1 ;; + esac + fi + if [ "$cmp" = "lt" ] ; then + c=$a + a=$b + b=$c + fi + if (echo $a ; echo $b) | sort -n | head -n 1 | grep -qx $b ; then + return 0 + else + return 1 + fi +} + +test_gt () +{ + a=$1 + b=$2 + cmp=gt + if [ "x$b" = "x" ] ; then + return 0 + fi + case $a:$b in + *.old:*.old) ;; + *.old:*) a=`echo -n $a | sed -e s/\.old$//g` ; cmp=gt ;; + *:*.old) b=`echo -n $b | sed -e s/\.old$//g` ; cmp=ge ;; + esac + (set -e ; test_numeric $a $cmp $b) + return $? +} + +find_latest () +{ + a="" + for i in $@ ; do + if (set -e ; test_gt "$i" "$a") ; then + a="$i" + fi + done + echo "$a" +} + +list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do + if test -e $i ; then echo -n "$i " ; fi + done` -for linux in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do +while [ "x$list" != "x" ] ; do + linux=`find_latest $list` if test -e ${linux} ; then : ; else continue fi - echo "Found linux image: $linux" >&2 + echo "Found linux image: $linux" >&2 version=`echo $linux | sed -e "s,.*/[^0-9]*-,,g"` basedir=`echo $linux | sed -e "s,/[^/]*$,,g"` cat << EOF @@ -56,4 +111,5 @@ cat << EOF } EOF + list=`echo $list | tr ' ' '\n' | grep -vx $linux | tr '\n' ' '` done --ikeVEW9yuYc//A+q--