Advertisement
Guest User

grub-mkconfig

a guest
Mar 23rd, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.08 KB | None | 0 0
  1. #! /bin/sh
  2. set -e
  3.  
  4. # Generate grub.cfg by inspecting /boot contents.
  5. # Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
  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. prefix="/usr"
  21. exec_prefix="/usr"
  22. datarootdir="/usr/share"
  23.  
  24. prefix="/usr"
  25. exec_prefix="/usr"
  26. sbindir="${exec_prefix}/sbin"
  27. bindir="${exec_prefix}/bin"
  28. sysconfdir="/etc"
  29. PACKAGE_NAME=GRUB
  30. PACKAGE_VERSION=2.02~beta2-22+deb8u1
  31. host_os=linux-gnu
  32. datadir="${datarootdir}"
  33. if [ "x$pkgdatadir" = x ]; then
  34. pkgdatadir="${datadir}/grub"
  35. fi
  36. grub_cfg=""
  37. grub_mkconfig_dir="${sysconfdir}"/grub.d
  38.  
  39. self=`basename $0`
  40.  
  41. grub_probe="${sbindir}/grub-probe"
  42. grub_file="${bindir}/grub-file"
  43. grub_editenv="${bindir}/grub-editenv"
  44. grub_script_check="${bindir}/grub-script-check"
  45.  
  46. export TEXTDOMAIN=grub
  47. export TEXTDOMAINDIR="${datarootdir}/locale"
  48.  
  49. . "${pkgdatadir}/grub-mkconfig_lib"
  50.  
  51. # Usage: usage
  52. # Print the usage.
  53. usage () {
  54. gettext_printf "Usage: %s [OPTION]\n" "$self"
  55. gettext "Generate a grub config file"; echo
  56. echo
  57. print_option_help "-o, --output=$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")"
  58. print_option_help "-h, --help" "$(gettext "print this message and exit")"
  59. print_option_help "-v, --version" "$(gettext "print the version information and exit")"
  60. echo
  61. gettext "Report bugs to <bug-grub@gnu.org>."; echo
  62. }
  63.  
  64. argument () {
  65. opt=$1
  66. shift
  67.  
  68. if test $# -eq 0; then
  69. gettext_printf "%s: option requires an argument -- \`%s'\n" "$self" "$opt" 1>&2
  70. exit 1
  71. fi
  72. echo $1
  73. }
  74.  
  75. # Check the arguments.
  76. while test $# -gt 0
  77. do
  78. option=$1
  79. shift
  80.  
  81. case "$option" in
  82. -h | --help)
  83. usage
  84. exit 0 ;;
  85. -v | --version)
  86. echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
  87. exit 0 ;;
  88. -o | --output)
  89. grub_cfg=`argument $option "$@"`; shift;;
  90. --output=*)
  91. grub_cfg=`echo "$option" | sed 's/--output=//'`
  92. ;;
  93. -*)
  94. gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
  95. usage
  96. exit 1
  97. ;;
  98. # Explicitly ignore non-option arguments, for compatibility.
  99. esac
  100. done
  101.  
  102. if fgrep -qs '${GRUB_PREFIX}/video.lst' "${grub_mkconfig_dir}/00_header"; then
  103. echo "GRUB >= 2.00 has been unpacked but not yet configured." >&2
  104. echo "grub-mkconfig will not work until the upgrade is complete." >&2
  105. echo "It should run later as part of configuring the new GRUB packages." >&2
  106. exit 0
  107. fi
  108.  
  109. if [ "x$EUID" = "x" ] ; then
  110. EUID=`id -u`
  111. fi
  112.  
  113. if [ "$EUID" != 0 ] ; then
  114. root=f
  115. case "`uname 2>/dev/null`" in
  116. CYGWIN*)
  117. # Cygwin: Assume root if member of admin group
  118. for g in `id -G 2>/dev/null` ; do
  119. case $g in
  120. 0|544) root=t ;;
  121. esac
  122. done ;;
  123. esac
  124. if [ $root != t ] ; then
  125. gettext_printf "%s: You must run this as root\n" "$self" >&2
  126. exit 1
  127. fi
  128. fi
  129.  
  130. set $grub_probe dummy
  131. if test -f "$1"; then
  132. :
  133. else
  134. gettext_printf "%s: Not found.\n" "$1" 1>&2
  135. exit 1
  136. fi
  137.  
  138. # Device containing our userland. Typically used for root= parameter.
  139. GRUB_DEVICE="`${grub_probe} --target=device /`"
  140. GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
  141.  
  142. # Device containing our /boot partition. Usually the same as GRUB_DEVICE.
  143. GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
  144. GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
  145.  
  146. # Filesystem for the device containing our userland. Used for stuff like
  147. # choosing Hurd filesystem module.
  148. GRUB_FS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`"
  149.  
  150. if [ x"$GRUB_FS" = xunknown ]; then
  151. GRUB_FS="$(stat -f --printf=%T / || echo unknown)"
  152. fi
  153.  
  154. if test -f ${sysconfdir}/default/grub ; then
  155. . ${sysconfdir}/default/grub
  156. fi
  157. for x in ${sysconfdir}/default/grub.d/*.cfg ; do
  158. if [ -e "${x}" ]; then
  159. . "${x}"
  160. fi
  161. done
  162.  
  163. # XXX: should this be deprecated at some point?
  164. if [ "x${GRUB_TERMINAL}" != "x" ] ; then
  165. GRUB_TERMINAL_INPUT="${GRUB_TERMINAL}"
  166. GRUB_TERMINAL_OUTPUT="${GRUB_TERMINAL}"
  167. fi
  168.  
  169. termoutdefault=0
  170. if [ "x${GRUB_TERMINAL_OUTPUT}" = "x" ]; then
  171. GRUB_TERMINAL_OUTPUT=gfxterm;
  172. termoutdefault=1;
  173. fi
  174.  
  175. for x in ${GRUB_TERMINAL_OUTPUT}; do
  176. case "x${x}" in
  177. xgfxterm) ;;
  178. xconsole | xserial | xofconsole | xvga_text)
  179. # make sure all our children behave in conformance with ascii..
  180. export LANG=C;;
  181. *) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
  182. esac
  183. done
  184.  
  185. GRUB_ACTUAL_DEFAULT="$GRUB_DEFAULT"
  186.  
  187. if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
  188.  
  189. if [ "x${GRUB_RECOVERY_TITLE}" = "x" ]; then
  190. GRUB_RECOVERY_TITLE="recovery mode"
  191. fi
  192.  
  193.  
  194. # These are defined in this script, export them here so that user can
  195. # override them.
  196. export GRUB_DEVICE \
  197. GRUB_DEVICE_UUID \
  198. GRUB_DEVICE_BOOT \
  199. GRUB_DEVICE_BOOT_UUID \
  200. GRUB_FS \
  201. GRUB_FONT \
  202. GRUB_PRELOAD_MODULES \
  203. GRUB_ACTUAL_DEFAULT
  204.  
  205. # These are optional, user-defined variables.
  206. export GRUB_DEFAULT \
  207. GRUB_HIDDEN_TIMEOUT \
  208. GRUB_HIDDEN_TIMEOUT_QUIET \
  209. GRUB_TIMEOUT \
  210. GRUB_TIMEOUT_STYLE \
  211. GRUB_DEFAULT_BUTTON \
  212. GRUB_HIDDEN_TIMEOUT_BUTTON \
  213. GRUB_TIMEOUT_BUTTON \
  214. GRUB_TIMEOUT_STYLE_BUTTON \
  215. GRUB_BUTTON_CMOS_ADDRESS \
  216. GRUB_BUTTON_CMOS_CLEAN \
  217. GRUB_DISTRIBUTOR \
  218. GRUB_CMDLINE_LINUX \
  219. GRUB_CMDLINE_LINUX_DEFAULT \
  220. GRUB_CMDLINE_XEN \
  221. GRUB_CMDLINE_XEN_DEFAULT \
  222. GRUB_CMDLINE_LINUX_XEN_REPLACE \
  223. GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT \
  224. GRUB_CMDLINE_NETBSD \
  225. GRUB_CMDLINE_NETBSD_DEFAULT \
  226. GRUB_CMDLINE_GNUMACH \
  227. GRUB_TERMINAL_INPUT \
  228. GRUB_TERMINAL_OUTPUT \
  229. GRUB_SERIAL_COMMAND \
  230. GRUB_DISABLE_LINUX_UUID \
  231. GRUB_DISABLE_RECOVERY \
  232. GRUB_VIDEO_BACKEND \
  233. GRUB_GFXMODE \
  234. GRUB_BACKGROUND \
  235. GRUB_THEME \
  236. GRUB_GFXPAYLOAD_LINUX \
  237. GRUB_DISABLE_OS_PROBER \
  238. GRUB_INIT_TUNE \
  239. GRUB_SAVEDEFAULT \
  240. GRUB_ENABLE_CRYPTODISK \
  241. GRUB_BADRAM \
  242. GRUB_OS_PROBER_SKIP_LIST \
  243. GRUB_DISABLE_SUBMENU \
  244. GRUB_RECORDFAIL_TIMEOUT \
  245. GRUB_RECOVERY_TITLE
  246.  
  247. if test "x${grub_cfg}" != "x"; then
  248. rm -f "${grub_cfg}.new"
  249. oldumask=$(umask); umask 077
  250. exec > "${grub_cfg}.new"
  251. umask $oldumask
  252. fi
  253. gettext "Generating grub configuration file ..." >&2
  254. echo >&2
  255.  
  256. cat << EOF
  257. #
  258. # DO NOT EDIT THIS FILE
  259. #
  260. # It is automatically generated by $self using templates
  261. # from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub
  262. #
  263. EOF
  264.  
  265.  
  266. for i in "${grub_mkconfig_dir}"/* ; do
  267. case "$i" in
  268. # emacsen backup files. FIXME: support other editors
  269. *~) ;;
  270. # emacsen autosave files. FIXME: support other editors
  271. */\#*\#) ;;
  272. *)
  273. if grub_file_is_not_garbage "$i" && test -x "$i" ; then
  274. echo
  275. echo "### BEGIN $i ###"
  276. "$i"
  277. echo "### END $i ###"
  278. fi
  279. ;;
  280. esac
  281. done
  282.  
  283. if [ "x${grub_cfg}" != "x" ] && ! grep "^password" ${grub_cfg}.new >/dev/null; then
  284. chmod 444 ${grub_cfg}.new || true
  285. fi
  286.  
  287. if test "x${grub_cfg}" != "x" ; then
  288. if ! ${grub_script_check} ${grub_cfg}.new; then
  289. # TRANSLATORS: %s is replaced by filename
  290. gettext_printf "Syntax errors are detected in generated GRUB config file.
  291. Ensure that there are no errors in /etc/default/grub
  292. and /etc/grub.d/* files or please file a bug report with
  293. %s file attached." "${grub_cfg}.new" >&2
  294. echo >&2
  295. else
  296. # none of the children aborted with error, install the new grub.cfg
  297. mv -f ${grub_cfg}.new ${grub_cfg}
  298. fi
  299. fi
  300.  
  301. gettext "done" >&2
  302. echo >&2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement