vds89

05_debian_theme

Jan 2nd, 2023
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. #!/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_lib
  22.  
  23. # We want to work in /boot/grub/ only.
  24. test -d /boot/grub; cd /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_theme(){
  31. case $GRUB_DISTRIBUTOR in
  32. Tanglu|Ubuntu|Kubuntu)
  33. # Set a monochromatic theme for Tanglu/Ubuntu.
  34. echo "${1}set menu_color_normal=white/black"
  35. echo "${1}set menu_color_highlight=black/light-gray"
  36.  
  37. if [ -e /usr/share/plymouth/themes/default.grub ]; then
  38. sed "s/^/${1}/" /usr/share/plymouth/themes/default.grub
  39. fi
  40. # For plymouth backward compatibility. Can be removed
  41. # after xenial.
  42. if [ -e /lib/plymouth/themes/default.grub ]; then
  43. sed "s/^/${1}/" /lib/plymouth/themes/default.grub
  44. fi
  45. ;;
  46. *)
  47. # Set the traditional Debian blue theme.
  48. echo "${1}set menu_color_normal=cyan/blue"
  49. echo "${1}set menu_color_highlight=white/blue"
  50. ;;
  51. esac
  52. }
  53.  
  54. module_available(){
  55. local module
  56. for module in "${1}.mod" */"${1}.mod"; do
  57. if [ -f "${module}" ]; then
  58. return 0
  59. fi
  60. done
  61. return 1
  62. }
  63.  
  64. set_background_image(){
  65. # Step #1: Search all available output modes ...
  66. local output
  67. for output in ${GRUB_TERMINAL_OUTPUT}; do
  68. if [ "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 ! [ "x${output}" = "xgfxterm" ]; then
  75. return 1
  76. fi
  77.  
  78. # Step #2: Check if the specified background image exists.
  79. if ! [ -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_available "${reader}"; then
  94. return 4
  95. fi
  96.  
  97. # Step #5: Check if GRUB can read the background image directly.
  98. # If so, we can remove the cache file (if any). Otherwise the background
  99. # image needs to be cached under /boot/grub/.
  100. if is_path_readable_by_grub "${1}"; then
  101. rm --force "${BACKGROUND_CACHE}.jpeg" \
  102. "${BACKGROUND_CACHE}.png" "${BACKGROUND_CACHE}.tga"
  103. elif cp "${1}" "${BACKGROUND_CACHE}.${reader}"; then
  104. set -- "${BACKGROUND_CACHE}.${reader}" "${2}" "${3}"
  105. else
  106. return 5
  107. fi
  108.  
  109. # Step #6: Prepare GRUB to read the background image.
  110. if ! prepare_grub_to_access_device "`${grub_probe} --target=device "${1}"`"; then
  111. return 6
  112. fi
  113.  
  114. # Step #7: Everything went fine, print out a message to stderr ...
  115. echo "Found background image: ${1}" >&2
  116.  
  117. # ... and write our configuration snippet to stdout. Use the colors
  118. # desktop-base specified. If we're using a user-defined background, use
  119. # the default colors since we've got no idea how the image looks like.
  120. # If loading the background image fails, use the default theme.
  121. echo "insmod ${reader}"
  122. echo "if background_image `make_system_path_relative_to_its_root "${1}"`; then"
  123. if [ -n "${2}" ]; then
  124. echo " set color_normal=${2}"
  125. fi
  126. if [ -n "${3}" ]; then
  127. echo " set color_highlight=${3}"
  128. fi
  129. if [ -z "${2}" ] && [ -z "${3}" ]; then
  130. echo " true"
  131. fi
  132. echo "else"
  133. set_default_theme " "
  134. echo "fi"
  135. }
  136.  
  137. # Earlier versions of grub-pc copied the default background image to /boot/grub
  138. # during postinst. Remove those obsolete images if they haven't been touched by
  139. # the user. They are still available under /usr/share/images/desktop-base/ if
  140. # desktop-base is installed.
  141. while read checksum background; do
  142. if [ -f "${background}" ] && [ "x`sha1sum "${background}"`" = "x${checksum} ${background}" ]; then
  143. echo "Removing old background image: ${background}" >&2
  144. rm "${background}"
  145. fi
  146. done <<EOF
  147. 648ee65dd0c157a69b019a5372cbcfea4fc754a5 debian-blueish-wallpaper-640x480.png
  148. 0431e97a6c661084c59676c4baeeb8c2f602edb8 debian-blueish-wallpaper-640x480.png
  149. 968ecf6696c5638cfe80e8e70aba239526270864 debian-blueish-wallpaper-640x480.tga
  150. 11143e8c92a073401de0b0fd42d0c052af4ccd9b moreblue-orbit-grub.png
  151. d00d5e505ab63f2d53fa880bfac447e2d3bb197c moreblue-orbit-grub.png
  152. f5b12c1009ec0a3b029185f6b66cd0d7e5611019 moreblue-orbit-grub.png
  153. EOF
  154.  
  155. # Include the configuration of desktop-base if available.
  156. if [ -f "/usr/share/desktop-base/grub_background.sh" ]; then
  157. . "/usr/share/desktop-base/grub_background.sh"
  158. fi
  159.  
  160. # First check whether the user has specified a background image explicitly.
  161. # If so, try to use it. Don't try the other possibilities in that case
  162. # (#608263).
  163. if [ -n "${GRUB_BACKGROUND+x}" ]; then
  164. set_background_image "${GRUB_BACKGROUND}" || set_default_theme
  165. exit 0
  166. fi
  167.  
  168. # Next search for pictures the user put into /boot/grub/ and use the first one.
  169. for background in *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG *.tga *.TGA; do
  170. if set_background_image "${background}"; then
  171. exit 0
  172. fi
  173. done
  174.  
  175. # Next try to use the background image and colors specified by desktop-base.
  176. if set_background_image "${WALLPAPER}" "${COLOR_NORMAL}" "${COLOR_HIGHLIGHT}"; then
  177. exit 0
  178. fi
  179.  
  180. # If we haven't found a background image yet, use the default from desktop-base.
  181. case $GRUB_DISTRIBUTOR in
  182. Ubuntu|Kubuntu)
  183. ;;
  184. Tanglu)
  185. if set_background_image "/usr/share/images/grub/grub.png"; then
  186. exit 0
  187. fi
  188. ;;
  189. *)
  190. if set_background_image "/usr/share/images/desktop-base/desktop-grub.png"; then
  191. exit 0
  192. fi
  193. ;;
  194. esac
  195.  
  196. # Finally, if all of the above fails, use the default theme.
  197. set_default_theme
Advertisement
Add Comment
Please, Sign In to add comment