#!/bin/sh set -e # grub-mkconfig helper script. # Copyright (C) 2010 Alexander Kurtz # # GRUB is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # GRUB is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GRUB. If not, see . # Include the GRUB helper library for grub-mkconfig. . /usr/lib/grub/grub-mkconfig_lib # We want to work in /boot/grub/ only. test -d "${GRUB_PREFIX}"; cd "${GRUB_PREFIX}" # Set the location of a possibly necessary cache file for the background image. # NOTE: This MUST BE A DOTFILE to avoid confusing it with user-defined images. BACKGROUND_CACHE=".background_cache" set_default_theme(){ # Set a monochromatic theme for Ubuntu. echo "${1}set menu_color_normal=white/black" echo "${1}set menu_color_highlight=black/light-gray" if [ -e /lib/plymouth/themes/default.grub ]; then sed "s/^/${1}/" /lib/plymouth/themes/default.grub fi } set_background_image(){ # Step #1: Search all available output modes ... local output for output in ${GRUB_TERMINAL_OUTPUT}; do if [ "x$output" = "xgfxterm" ]; then break fi done # ... and check if we are able to display a background image at all. if ! [ "x${output}" = "xgfxterm" ]; then return 1 fi # Step #2: Check if the specified background image exists. if ! [ -f "${1}" ]; then return 2 fi # 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";; *) return 3;; # Unknown image type. esac # Step #4: Check if the necessary GRUB module is available. if ! [ -f "${reader}.mod" ]; then return 4 fi # Step #5: Check if GRUB can read the background image directly. # If so, we can remove the cache file (if any). Otherwise the backgound # image needs to be cached under /boot/grub/. if is_path_readable_by_grub "${1}"; then rm --force "${BACKGROUND_CACHE}.jpeg" \ "${BACKGROUND_CACHE}.png" "${BACKGROUND_CACHE}.tga" elif cp "${1}" "${BACKGROUND_CACHE}.${reader}"; then set -- "${BACKGROUND_CACHE}.${reader}" "${2}" "${3}" else return 5 fi # Step #6: Prepare GRUB to read the background image. if ! prepare_grub_to_access_device "`${grub_probe} --target=device "${1}"`"; then return 6 fi # Step #7: Everything went fine, print out a message to stderr ... 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. # 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 "else" set_default_theme " " 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. while read checksum background; do if [ -f "${background}" ] && [ "x`sha1sum "${background}"`" = "x${checksum} ${background}" ]; then echo "Removing old background image: ${background}" >&2 rm "${background}" fi done <