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`