From 9d5bdd2cf697b4421e1cc203271a8cc7e0f0ea4d Mon Sep 17 00:00:00 2001 From: robertmh Date: Fri, 7 Aug 2009 12:05:06 +0000 Subject: [PATCH] Split in two commits. This one's the second. 2009-08-07 Robert Millan * util/grub.d/10_linux.in (test_numeric): Moved from here ... * util/grub-mkconfig_lib.in (version_test_numeric): ... to here. Update all users. * util/grub.d/10_linux.in (test_gt): Strip any basename prefix, not just "vmlinu[zx]". Moved from here ... * util/grub-mkconfig_lib.in (version_test_gt): ... to here. Update all users. * util/grub.d/10_linux.in (find_latest): Moved from here ... * util/grub-mkconfig_lib.in (version_find_latest): ... to here. Update all users. --- util/grub-mkconfig_lib.in | 51 +++++++++++++++++++++++++++++++++++++ util/grub.d/10_linux.in | 53 +-------------------------------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/util/grub-mkconfig_lib.in b/util/grub-mkconfig_lib.in index d27b72ea1..52dac00fe 100644 --- a/util/grub-mkconfig_lib.in +++ b/util/grub-mkconfig_lib.in @@ -176,3 +176,54 @@ grub_file_is_not_garbage () fi return 0 } + +version_test_numeric () +{ + local a=$1 + local cmp=$2 + local 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 +} + +version_test_gt () +{ + local a=`echo $1 | sed -e "s/[^-]*-//g"` + local b=`echo $2 | sed -e "s/[^-]*-//g"` + local 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 + version_test_numeric $a $cmp $b + return $? +} + +version_find_latest () +{ + local a="" + for i in $@ ; do + if version_test_gt "$i" "$a" ; then + a="$i" + fi + done + echo "$a" +} diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 637bf3e94..4df078e8f 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -42,57 +42,6 @@ else LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} fi -test_numeric () -{ - local a=$1 - local cmp=$2 - local 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 () -{ - local a=`echo $1 | sed -e "s/[^-]*-//g"` - local b=`echo $2 | sed -e "s/[^-]*-//g"` - local 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 - test_numeric $a $cmp $b - return $? -} - -find_latest () -{ - local a="" - for i in $@ ; do - if test_gt "$i" "$a" ; then - a="$i" - fi - done - echo "$a" -} - linux_entry () { cat << EOF @@ -117,7 +66,7 @@ list=`for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* ; do done` while [ "x$list" != "x" ] ; do - linux=`find_latest $list` + linux=`version_find_latest $list` echo "Found linux image: $linux" >&2 basename=`basename $linux` dirname=`dirname $linux` -- 2.39.5