source: src-sh/pc-extractoverlay/ports-overlay/usr/local/sbin/grub-mkconfig @ 9b5efbf5

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 9b5efbf5 was 9b5efbf5, checked in by Kris Moore <kris@…>, 18 months ago

Add modified sbin/grub-mkconfig, which will ensure that our grub.cfg
gets copied back to the primary BE snapshot, this means if you boot
a BE, and do some BE operations, your next GRUB boot will reflect the
changes

  • Property mode set to 100755
File size: 7.7 KB
RevLine 
[9b5efbf5]1#! /bin/sh
2set -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
20transform="s,x,x,"
21prefix="/usr/local"
22exec_prefix="${prefix}"
23datarootdir="${prefix}/share"
24
25prefix="/usr/local"
26exec_prefix="${prefix}"
27sbindir="${exec_prefix}/sbin"
28bindir="${exec_prefix}/bin"
29sysconfdir="${prefix}/etc"
30PACKAGE_NAME=GRUB
31PACKAGE_VERSION=2.00
32host_os=freebsd9.1
33datadir="${datarootdir}"
34if [ "x$pkgdatadir" = x ]; then
35    pkgdatadir="${datadir}/grub"
36fi
37grub_cfg=""
38grub_mkconfig_dir="${sysconfdir}"/grub.d
39
40self=`basename $0`
41
42grub_probe="${sbindir}/`echo grub-probe | sed "${transform}"`"
43grub_editenv="${bindir}/`echo grub-editenv | sed "${transform}"`"
44grub_script_check="${bindir}/`echo grub-script-check | sed "${transform}"`"
45
46export TEXTDOMAIN=grub
47export TEXTDOMAINDIR="/usr/local/share/locale"
48
49. "${pkgdatadir}/grub-mkconfig_lib"
50
51# Usage: usage
52# Print the usage.
53usage () {
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
64argument () {
65  opt=$1
66  shift
67
68  if test $# -eq 0; then
69      gettext_printf "%s: option requires an argument -- \`%s'\n" "$0" "$opt" 1>&2
70      exit 1
71  fi
72  echo $1
73}
74
75# Check the arguments.
76while test $# -gt 0
77do
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
100done
101
102if [ "x$EUID" = "x" ] ; then
103  EUID=`id -u`
104fi
105
106if [ "$EUID" != 0 ] ; then
107  root=f
108  case "`uname 2>/dev/null`" in
109    CYGWIN*)
110      # Cygwin: Assume root if member of admin group
111      for g in `id -G 2>/dev/null` ; do
112        case $g in
113          0|544) root=t ;;
114        esac
115      done ;;
116  esac
117  if [ $root != t ] ; then
118    gettext_printf "%s: You must run this as root\n" "$self" >&2
119    exit 1
120  fi
121fi
122
123set $grub_probe dummy
124if test -f "$1"; then
125    :
126else
127    gettext_print "%s: Not found.\n" "$1" 1>&2
128    exit 1
129fi
130
131# Device containing our userland.  Typically used for root= parameter.
132GRUB_DEVICE="`${grub_probe} --target=device /`"
133GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
134
135# Device containing our /boot partition.  Usually the same as GRUB_DEVICE.
136GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
137GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
138
139# Filesystem for the device containing our userland.  Used for stuff like
140# choosing Hurd filesystem module.
141GRUB_FS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`"
142
143if test -f ${sysconfdir}/default/grub ; then
144  . ${sysconfdir}/default/grub
145fi
146
147# XXX: should this be deprecated at some point?
148if [ "x${GRUB_TERMINAL}" != "x" ] ; then
149  GRUB_TERMINAL_INPUT="${GRUB_TERMINAL}"
150  GRUB_TERMINAL_OUTPUT="${GRUB_TERMINAL}"
151fi
152
153termoutdefault=0
154if [ "x${GRUB_TERMINAL_OUTPUT}" = "x" ]; then
155    GRUB_TERMINAL_OUTPUT=gfxterm;
156    termoutdefault=1;
157fi
158
159for x in ${GRUB_TERMINAL_OUTPUT}; do
160    case "x${x}" in
161        xgfxterm) ;;
162        xconsole | xserial | xofconsole)
163            # make sure all our children behave in conformance with ascii..
164            export LANG=C;;
165        *) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
166    esac
167done
168
169GRUB_ACTUAL_DEFAULT="$GRUB_DEFAULT"
170
171if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
172
173
174# These are defined in this script, export them here so that user can
175# override them.
176export GRUB_DEVICE \
177  GRUB_DEVICE_UUID \
178  GRUB_DEVICE_BOOT \
179  GRUB_DEVICE_BOOT_UUID \
180  GRUB_FS \
181  GRUB_FONT \
182  GRUB_PRELOAD_MODULES \
183  GRUB_ACTUAL_DEFAULT
184
185# These are optional, user-defined variables.
186export GRUB_DEFAULT \
187  GRUB_HIDDEN_TIMEOUT \
188  GRUB_HIDDEN_TIMEOUT_QUIET \
189  GRUB_TIMEOUT \
190  GRUB_DEFAULT_BUTTON \
191  GRUB_HIDDEN_TIMEOUT_BUTTON \
192  GRUB_TIMEOUT_BUTTON \
193  GRUB_BUTTON_CMOS_ADDRESS \
194  GRUB_BUTTON_CMOS_CLEAN \
195  GRUB_DISTRIBUTOR \
196  GRUB_CMDLINE_LINUX \
197  GRUB_CMDLINE_LINUX_DEFAULT \
198  GRUB_CMDLINE_XEN \
199  GRUB_CMDLINE_XEN_DEFAULT \
200  GRUB_CMDLINE_LINUX_XEN_REPLACE \
201  GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT \
202  GRUB_CMDLINE_NETBSD \
203  GRUB_CMDLINE_NETBSD_DEFAULT \
204  GRUB_CMDLINE_GNUMACH \
205  GRUB_TERMINAL_INPUT \
206  GRUB_TERMINAL_OUTPUT \
207  GRUB_SERIAL_COMMAND \
208  GRUB_DISABLE_LINUX_UUID \
209  GRUB_DISABLE_RECOVERY \
210  GRUB_VIDEO_BACKEND \
211  GRUB_GFXMODE \
212  GRUB_BACKGROUND \
213  GRUB_THEME \
214  GRUB_GFXPAYLOAD_LINUX \
215  GRUB_DISABLE_OS_PROBER \
216  GRUB_INIT_TUNE \
217  GRUB_SAVEDEFAULT \
218  GRUB_ENABLE_CRYPTODISK \
219  GRUB_BADRAM
220
221if test "x${grub_cfg}" != "x"; then
222  rm -f "${grub_cfg}.new"
223  oldumask=$(umask); umask 077
224  exec > "${grub_cfg}.new"
225  umask $oldumask
226fi
227gettext "Generating grub.cfg ..." >&2
228echo >&2
229
230cat << EOF
231#
232# DO NOT EDIT THIS FILE
233#
234# It is automatically generated by $self using templates
235# from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub
236#
237EOF
238
239for i in ${grub_mkconfig_dir}/* ; do
240  case "$i" in
241    # emacsen backup files. FIXME: support other editors
242    *~) ;;
243    # emacsen autosave files. FIXME: support other editors
244    \#*\#) ;;
245    *)
246      if grub_file_is_not_garbage "$i" && test -x "$i" ; then
247        echo
248        echo "### BEGIN $i ###"
249        "$i"
250        echo "### END $i ###"
251      fi
252    ;;
253  esac
254done
255
256if test "x${grub_cfg}" != "x" ; then
257  if ! ${grub_script_check} ${grub_cfg}.new; then
258    # TRANSLATORS: %s is replaced by filename
259    gettext_printf "Syntax errors are detected in generated GRUB config file.
260Ensure that there are no errors in /etc/default/grub
261and /etc/grub.d/* files or please file a bug report with
262%s file attached." "${grub_cfg}.new" >&2
263  else
264    # none of the children aborted with error, install the new grub.cfg
265    mv -f ${grub_cfg}.new ${grub_cfg}
266  fi
267fi
268
269# KPM 6-24-2013
270# If doing a real grub.cfg update, make sure that our config gets
271# copied to the /default/ ZFS BE
272check_grub_zfs_be()
273{
274  if [ "$grub_cfg" = "/boot/grub/grub.cfg" ] ; then
275    dTank=`beadm list -a 2>/dev/null | grep '/ROOT/default' | awk '{print $1}'`
276    if ! mount | grep -q "$dTank on / ("; then
277       echo -e "Copying grub.cfg to $dTank...\c" >&2
278       fMnt="/mnt.$$"
279       mkdir $fMnt
280       if ! mount -t zfs ${dTank} $fMnt ; then
281          echo "Failed to mount ${dTank}" >&2
282          return
283       else
284         cp ${grub_cfg} ${fMnt}/boot/grub/grub.cfg
285         echo -e "done" >&2
286         umount ${fMnt} >/dev/null
287         rmdir ${fMnt} >/dev/null
288       fi
289    fi
290  fi
291
292}
293gettext "done" >&2
294echo >&2
295
296# Check if we need to copy this cfg to the original BE
297check_grub_zfs_be
298
Note: See TracBrowser for help on using the repository browser.