Hi everybody, assuming upstream agrees on my suggestion[1], I think the attached patch should fix all the remaining issues with unusual filenames, automatic deletion of obsolete images and lacking customizability of GRUB's menu colors. What do you think?
Best regards Alexander Kurtz [1] https://lists.gnu.org/archive/html/grub-devel/2011-05/msg00050.html
diff -Naur old/debian/grub.d/05_debian_theme new/debian/grub.d/05_debian_theme --- old/debian/grub.d/05_debian_theme 2011-05-29 21:32:45.000000000 +0200 +++ new/debian/grub.d/05_debian_theme 2011-05-25 17:43:50.000000000 +0200 @@ -2,7 +2,7 @@ set -e # grub-mkconfig helper script. -# Copyright (C) 2010 Alexander Kurtz <kurtz.a...@googlemail.com> +# Copyright (C) 2011 Alexander Kurtz <kurtz.a...@googlemail.com> # # GRUB is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,17 +27,36 @@ # NOTE: This MUST BE A DOTFILE to avoid confusing it with user-defined images. BACKGROUND_CACHE=".background_cache" -set_default_theme(){ - # Set the traditional Debian blue theme. - echo "${1}set menu_color_normal=cyan/blue" - echo "${1}set menu_color_highlight=white/blue" +# Usage: set_variable <variable> <value> +# Print out a statement setting $variable to $value if both are non-empty. +set_variable(){ + if [ -n "${1}" ] && [ -n "${2}" ]; then + echo "set ${1}=${2}" + fi +} + +# Usage: set_custom_colors [<color_normal>] [<color_highlight>] [<menu_color_normal>] [<menu_color_highlight>] +# Set the colors in GRUB; take user customizations into account. +set_custom_colors(){ + set_variable color_normal "${GRUB_COLOR_NORMAL:-${1}}" + set_variable color_highlight "${GRUB_COLOR_HIGHLIGHT:-${2}}" + set_variable menu_color_normal "${GRUB_MENU_COLOR_NORMAL:-${3}}" + set_variable menu_color_highlight "${GRUB_MENU_COLOR_HIGHLIGHT:-${4}}" +} + +# Usage: set_default_colors +# Set the traditional Debian blue theme. +set_default_colors(){ + set_custom_colors "" "" "cyan/blue" "white/blue" } +# Usage: <background image> [<color_normal>] [<color_highlight>] [<menu_color_normal>] [<menu_color_highlight>] +# Set the background image and colors if possible. set_background_image(){ # Step #1: Search all available output modes ... local output for output in ${GRUB_TERMINAL_OUTPUT}; do - if [ "x$output" = "xgfxterm" ]; then + if [ "x${output}" = "xgfxterm" ]; then break fi done @@ -55,9 +74,9 @@ # Step #3: Search the correct GRUB module for our background image. local reader case "${1}" in - *.jpg|*.JPG|*.jpeg|*.JPEG) reader="jpeg";; - *.png|*.PNG) reader="png";; - *.tga|*.TGA) reader="tga";; + *.[jJ][pP][gG]|*.[jJ][pP][eE][gG]) reader="jpeg";; + *.[pP][nN][gG]) reader="png";; + *.[tT][gG][aA]) reader="tga";; *) return 3;; # Unknown image type. esac @@ -73,7 +92,7 @@ rm --force "${BACKGROUND_CACHE}.jpeg" \ "${BACKGROUND_CACHE}.png" "${BACKGROUND_CACHE}.tga" elif cp "${1}" "${BACKGROUND_CACHE}.${reader}"; then - set -- "${BACKGROUND_CACHE}.${reader}" "${2}" "${3}" + set -- "${BACKGROUND_CACHE}.${reader}" "${2}" "${3}" "${4}" "${5}" else return 5 fi @@ -87,33 +106,24 @@ echo "Found background image: ${1}" >&2 # ... and write our configuration snippet to stdout. Use the colors - # desktop-base specified. If we're using a user-defined background, use - # the default colors since we've got no idea how the image looks like. + # which were supplied as arguments if available, else let GRUB decide. # If loading the background image fails, use the default theme. echo "insmod ${reader}" - echo "if background_image `make_system_path_relative_to_its_root "${1}"`; then" - if [ -n "${2}" ]; then - echo " set color_normal=${2}" - fi - if [ -n "${3}" ]; then - echo " set color_highlight=${3}" - fi - if [ -z "${2}" ] && [ -z "${3}" ]; then - echo " true" - fi + echo "if background_image '`make_system_path_relative_to_its_root "${1}" | sed "s/'/'\\\\\\\\''/g"`'; then" + set_custom_colors "${2}" "${3}" "${4}" "${5}" | sed "s/^/ /g" + echo " true" echo "else" - set_default_theme " " + set_default_colors | sed "s/^/ /g" echo "fi" } # Earlier versions of grub-pc copied the default background image to /boot/grub -# during postinst. Remove those obsolete images if they haven't been touched by -# the user. They are still available under /usr/share/images/desktop-base/ if -# desktop-base is installed. +# during postinst. Warn about those obsolete images if they haven't been touched +# by the user (SHA1), since they may prevent the default theme from being used. while read checksum background; do if [ -f "${background}" ] && [ "x`sha1sum "${background}"`" = "x${checksum} ${background}" ]; then - echo "Removing old background image: ${background}" >&2 - rm "${background}" + grub_warn "Obsolete image in ${GRUB_PREFIX}: ${background}" + grub_warn "This file may prevent desktop-base's default theme from being used." fi done <<EOF 648ee65dd0c157a69b019a5372cbcfea4fc754a5 debian-blueish-wallpaper-640x480.png @@ -133,12 +143,12 @@ # If so, try to use it. Don't try the other possibilities in that case # (#608263). if [ -n "${GRUB_BACKGROUND+x}" ]; then - set_background_image "${GRUB_BACKGROUND}" || set_default_theme + set_background_image "${GRUB_BACKGROUND}" || set_default_colors exit 0 fi # Next search for pictures the user put into /boot/grub/ and use the first one. -for background in *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG *.tga *.TGA; do +for background in *; do if set_background_image "${background}"; then exit 0 fi @@ -155,4 +165,4 @@ fi # Finally, if all of the above fails, use the default theme. -set_default_theme +set_default_colors
signature.asc
Description: This is a digitally signed message part