| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | set -e |
| 3 | |
| 4 | # grub-mkconfig helper script. |
| 5 | # Copyright (C) 2010 Alexander Kurtz <[email protected]> |
| 6 | # |
| 7 | # GRUB is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation, either version 3 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # GRUB is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with GRUB. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | # Include the GRUB helper library for grub-mkconfig. |
| 21 | . /usr/share/grub/grub-mkconfig_libscip-shell source . . `/usr/share/grub/grub-mkconfig_lib`. |
| 22 | |
| 23 | # We want to work in /boot/grub/ only. |
| 24 | testscip-shell system . . test. -d /boot/grubscip-shell filesystem . . `/boot/grub`.; cd /boot/grubscip-shell filesystem . . `/boot/grub`. |
| 25 | |
| 26 | # Set the location of a possibly necessary cache file for the background image. |
| 27 | # NOTE: This MUST BE A DOTFILE to avoid confusing it with user-defined images. |
| 28 | BACKGROUND_CACHE=".background_cache" |
| 29 | |
| 30 | set_default_themescip-shell shell grub2 2.14-2 set_default_theme().(){ |
| 31 | case $GRUB_DISTRIBUTOR in |
| 32 | Ubuntu|Kubuntu) |
| 33 | # Set a monochromatic theme for Ubuntu. |
| 34 | echoscip-shell system . . echo. "${1}set menu_color_normal=white/black" |
| 35 | echoscip-shell system . . echo. "${1}set menu_color_highlight=black/light-gray" |
| 36 | |
| 37 | if [scip-shell system . . `[`. -e /usr/share/plymouth/themes/default.grubscip-shell filesystem . . `/usr/share/plymouth/themes/default.grub`. ]; then |
| 38 | sedscip-shell system . . sed. "s/^/${1}/" /usr/share/plymouth/themes/default.grubscip-shell filesystem . . `/usr/share/plymouth/themes/default.grub`. |
| 39 | fi |
| 40 | # For plymouth backward compatibility. Can be removed |
| 41 | # after xenial. |
| 42 | if [scip-shell system . . `[`. -e /lib/plymouth/themes/default.grubscip-shell filesystem . . `/lib/plymouth/themes/default.grub`. ]; then |
| 43 | sedscip-shell system . . sed. "s/^/${1}/" /lib/plymouth/themes/default.grubscip-shell filesystem . . `/lib/plymouth/themes/default.grub`. |
| 44 | fi |
| 45 | ;; |
| 46 | *) |
| 47 | # Set the traditional Debian blue theme. |
| 48 | echoscip-shell system . . echo. "${1}set menu_color_normal=cyan/blue" |
| 49 | echoscip-shell system . . echo. "${1}set menu_color_highlight=white/blue" |
| 50 | ;; |
| 51 | esac |
| 52 | } |
| 53 | |
| 54 | module_availablescip-shell shell grub2 2.14-2 module_available().(){ |
| 55 | local module |
| 56 | for module in "${1}.mod" */"${1}.mod"; do |
| 57 | if [scip-shell system . . `[`. -f "${module}" ]; then |
| 58 | return 0 |
| 59 | fi |
| 60 | done |
| 61 | return 1 |
| 62 | } |
| 63 | |
| 64 | set_background_imagescip-shell shell grub2 2.14-2 set_background_image().(){ |
| 65 | # Step #1: Search all available output modes ... |
| 66 | local output |
| 67 | for output in ${GRUB_TERMINAL_OUTPUT}; do |
| 68 | if [scip-shell system . . `[`. "x$output" = "xgfxterm" ]; then |
| 69 | break |
| 70 | fi |
| 71 | done |
| 72 | |
| 73 | # ... and check if we are able to display a background image at all. |
| 74 | if ! [scip-shell system . . `[`. "x${output}" = "xgfxterm" ]; then |
| 75 | return 1 |
| 76 | fi |
| 77 | |
| 78 | # Step #2: Check if the specified background image exists. |
| 79 | if ! [scip-shell system . . `[`. -f "${1}" ]; then |
| 80 | return 2 |
| 81 | fi |
| 82 | |
| 83 | # Step #3: Search the correct GRUB module for our background image. |
| 84 | local reader |
| 85 | case "${1}" in |
| 86 | *.jpg|*.JPG|*.jpeg|*.JPEG) reader="jpeg";; |
| 87 | *.png|*.PNG) reader="png";; |
| 88 | *.tga|*.TGA) reader="tga";; |
| 89 | *) return 3;; # Unknown image type. |
| 90 | esac |
| 91 | |
| 92 | # Step #4: Check if the necessary GRUB module is available. |
| 93 | if ! module_availablescip-shell shell grub2 2.14-2 module_available(). "${reader}"; then |
| 94 | return 4 |
| 95 | fi |
| 96 | |
| 97 | # Step #5: Check if GRUB can read the background image directly and |
| 98 | # it is in the same filesystem as /boot/grub. |
| 99 | # If so, we can remove the cache file (if any). Otherwise the background |
| 100 | # image needs to be cached under /boot/grub/. |
| 101 | if is_path_readable_by_grub "${1}" && |
| 102 | [scip-shell system . . `[`. "`${grub_probe} --target=device "${1}"`" = "`${grub_probe} --target=device .`" ]; then |
| 103 | rmscip-shell system . . rm. --force "${BACKGROUND_CACHE}.jpeg" \ |
| 104 | "${BACKGROUND_CACHE}.png" "${BACKGROUND_CACHE}.tga" |
| 105 | elif cpscip-shell system . . cp. "${1}" "${BACKGROUND_CACHE}.${reader}"; then |
| 106 | set -- "${BACKGROUND_CACHE}.${reader}" "${2}" "${3}" |
| 107 | else |
| 108 | return 5 |
| 109 | fi |
| 110 | |
| 111 | # Step #6: Prepare GRUB to read the background image. |
| 112 | if ! prepare_grub_to_access_device "`${grub_probe} --target=device "${1}"`"; then |
| 113 | return 6 |
| 114 | fi |
| 115 | |
| 116 | # Step #7: Everything went fine, print out a message to stderr ... |
| 117 | echoscip-shell system . . echo. "Found background image: ${1}" >&2 |
| 118 | |
| 119 | # ... and write our configuration snippet to stdout. Use the colors |
| 120 | # desktop-base specified. If we're using a user-defined background, use |
| 121 | # the default colors since we've got no idea how the image looks like. |
| 122 | # If loading the background image fails, use the default theme. |
| 123 | echoscip-shell system . . echo. "insmod ${reader}" |
| 124 | echoscip-shell system . . echo. "if background_image \"`make_system_path_relative_to_its_root "${1}"`\"; then" |
| 125 | if [scip-shell system . . `[`. -n "${2}" ]; then |
| 126 | echoscip-shell system . . echo. " set color_normal=${2}" |
| 127 | fi |
| 128 | if [scip-shell system . . `[`. -n "${3}" ]; then |
| 129 | echoscip-shell system . . echo. " set color_highlight=${3}" |
| 130 | fi |
| 131 | if [scip-shell system . . `[`. -z "${2}" ] && [scip-shell system . . `[`. -z "${3}" ]; then |
| 132 | echoscip-shell system . . echo. " true" |
| 133 | fi |
| 134 | echoscip-shell system . . echo. "else" |
| 135 | set_default_themescip-shell shell grub2 2.14-2 set_default_theme(). " " |
| 136 | echoscip-shell system . . echo. "fi" |
| 137 | } |
| 138 | |
| 139 | # Earlier versions of grub-pc copied the default background image to /boot/grub |
| 140 | # during postinst. Remove those obsolete images if they haven't been touched by |
| 141 | # the user. They are still available under /usr/share/images/desktop-base/ if |
| 142 | # desktop-base is installed. |
| 143 | while read checksum background; do |
| 144 | if [scip-shell system . . `[`. -f "${background}" ] && [scip-shell system . . `[`. "x`sha1sumscip-shell system . . sha1sum. "${background}"`" = "x${checksum} ${background}" ]; then |
| 145 | echoscip-shell system . . echo. "Removing old background image: ${background}" >&2 |
| 146 | rmscip-shell system . . rm. "${background}" |
| 147 | fi |
| 148 | done <<EOF |
| 149 | 648ee65dd0c157a69b019a5372cbcfea4fc754a5 debian-blueish-wallpaper-640x480.png |
| 150 | 0431e97a6c661084c59676c4baeeb8c2f602edb8 debian-blueish-wallpaper-640x480.png |
| 151 | 968ecf6696c5638cfe80e8e70aba239526270864 debian-blueish-wallpaper-640x480.tga |
| 152 | 11143e8c92a073401de0b0fd42d0c052af4ccd9b moreblue-orbit-grub.png |
| 153 | d00d5e505ab63f2d53fa880bfac447e2d3bb197c moreblue-orbit-grub.png |
| 154 | f5b12c1009ec0a3b029185f6b66cd0d7e5611019 moreblue-orbit-grub.png |
| 155 | EOF |
| 156 | |
| 157 | # Include the configuration of desktop-base if available. |
| 158 | if [scip-shell system . . `[`. -f "/usr/share/desktop-base/grub_background.shscip-shell filesystem . . `/usr/share/desktop-base/grub_background.sh`." ]; then |
| 159 | . "/usr/share/desktop-base/grub_background.shscip-shell source . . `/usr/share/desktop-base/grub_background.sh`." |
| 160 | fi |
| 161 | |
| 162 | # First check whether the user has specified a background image explicitly. |
| 163 | # If so, try to use it. Don't try the other possibilities in that case |
| 164 | # (#608263). |
| 165 | if [scip-shell system . . `[`. -n "${GRUB_BACKGROUND+x}" ]; then |
| 166 | set_background_imagescip-shell shell grub2 2.14-2 set_background_image(). "${GRUB_BACKGROUND}" || set_default_themescip-shell shell grub2 2.14-2 set_default_theme(). |
| 167 | exit 0 |
| 168 | fi |
| 169 | |
| 170 | # Next search for pictures the user put into /boot/grub/ and use the first one. |
| 171 | for background in *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG *.tga *.TGA; do |
| 172 | if set_background_imagescip-shell shell grub2 2.14-2 set_background_image(). "${background}"; then |
| 173 | exit 0 |
| 174 | fi |
| 175 | done |
| 176 | |
| 177 | # Next try to use the background image and colors specified by desktop-base. |
| 178 | if set_background_imagescip-shell shell grub2 2.14-2 set_background_image(). "${WALLPAPER}" "${COLOR_NORMAL}" "${COLOR_HIGHLIGHT}"; then |
| 179 | exit 0 |
| 180 | fi |
| 181 | |
| 182 | # If we haven't found a background image yet, use the default from desktop-base. |
| 183 | case $GRUB_DISTRIBUTOR in |
| 184 | Ubuntu|Kubuntu) |
| 185 | ;; |
| 186 | *) |
| 187 | if set_background_imagescip-shell shell grub2 2.14-2 set_background_image(). "/usr/share/images/desktop-base/desktop-grub.pngscip-shell filesystem . . `/usr/share/images/desktop-base/desktop-grub.png`."; then |
| 188 | exit 0 |
| 189 | fi |
| 190 | ;; |
| 191 | esac |
| 192 | |
| 193 | # Finally, if all of the above fails, use the default theme. |
| 194 | set_default_themescip-shell shell grub2 2.14-2 set_default_theme(). |