set -e
# Generate grub.cfg by inspecting /boot contents.
# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
#
# 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 <http://www.gnu.org/licenses/>.
transform="@program_transform_name@"
grub_cfg=""
# Usage: usage
# Print the usage.
cat <<EOF
Usage: $self [OPTION]
Generate a grub config file
-o, --output=FILE output generated config to FILE [default=stdout]
-p, --prefix=DIR set the GRUB prefix directory to DIR
[default=/boot/grub]
-h, --help print this message and exit
-v, --version print the version information and exit
Report bugs to <bug-grub@gnu.org>.
EOF
}
opt=$1
shift
if test $# -eq 0; then
exit 1
fi
echo $1
}
# Check the arguments.
while test $# -gt 0
do
option=$1
shift
-h | --help)
exit 0 ;;
-v | --version)
echo "$self (${PACKAGE_NAME}) ${PACKAGE_VERSION}"
exit 0 ;;
-o | --output)
--output=*)
;;
-p | --prefix)
--prefix=*)
;;
-*)
exit 1
;;
# Explicitly ignore non-option arguments, for compatibility.
esac
done
export grub_mkdevicemap GRUB_PREFIX
if [ "x$EUID" = "x" ] ; then
fi
if [ "$EUID" != 0 ] ; then
root=f
CYGWIN*)
# Cygwin: Assume root if member of admin group
case $g in
esac
done ;;
esac
if [ $root != t ] ; then
echo "$self: You must run this as root" >&2
exit 1
fi
fi
set $grub_probe dummy
if test -f "$1"; then
:
else
echo "$1: Not found." 1>&2
exit 1
fi
if test -d $GRUB_PREFIX ; then : ; else
mkdir -p ${GRUB_PREFIX}
fi
# Device containing our userland. Typically used for root= parameter.
# Device containing our /boot partition. Usually the same as GRUB_DEVICE.
GRUB_DEVICE_BOOT_UUID="`${grub_probe} --device ${GRUB_DEVICE_BOOT} --target=fs_uuid 2> /dev/null`" || true
# Filesystem for the device containing our userland. Used for stuff like
# choosing Hurd filesystem module.
fi
# XXX: should this be deprecated at some point?
if [ "x${GRUB_TERMINAL}" != "x" ] ; then
GRUB_TERMINAL_INPUT="${GRUB_TERMINAL}"
GRUB_TERMINAL_OUTPUT="${GRUB_TERMINAL}"
fi
if [ "x${GRUB_TERMINAL_OUTPUT}" = "x" ]; then
fi
for x in ${GRUB_TERMINAL_OUTPUT}; do
if [ "x${x}" = "xgfxterm" ]; then
if [ -n "$GRUB_FONT" ] ; then
else
echo "No such font or not readable by grub: ${GRUB_FONT}" >&2
exit 1
fi
else
path="${dir}/${basename}.pf2"
else
continue
fi
if [ "${basename}" = "ascii" ] ; then
# make sure all our children behave in conformance with ascii..
export LANG=C
fi
break 2
done
done
fi
if [ -z "${GRUB_FONT_PATH}" -a -z "${GRUB_FONT_PATH_DIRECT}" ] ; then
if [ "x$termoutdefault" != "x1" ]; then
echo "No font for gfxterm found." >&2 ; exit 1
fi
fi
fi
done
for x in ${GRUB_TERMINAL_OUTPUT}; do
case "x${x}" in
xgfxterm) ;;
# make sure all our children behave in conformance with ascii..
export LANG=C;;
*) echo "Invalid output terminal \"${GRUB_TERMINAL_OUTPUT}\"" >&2 ; exit 1 ;;
esac
done
# These are defined in this script, export them here so that user can
# override them.
export GRUB_DEVICE \
GRUB_FS \
# These are optional, user-defined variables.
export GRUB_DEFAULT \
if test "x${grub_cfg}" != "x"; then
# firmware implementations (e.g. OFW or EFI).
This means that if the generated config contains a password it is readable by everyone"
fi
echo "Generating grub.cfg ..." >&2
cat << EOF
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by $self using templates
# from ${grub_mkconfig_dir} and settings from ${sysconfdir}/default/grub
#
EOF
for i in ${grub_mkconfig_dir}/* ; do
case "$i" in
# emacsen backup files. FIXME: support other editors
*~) ;;
# emacsen autosave files. FIXME: support other editors
\#*\#) ;;
*)
echo
echo "### BEGIN $i ###"
"$i"
echo "### END $i ###"
fi
;;
esac
done
if test "x${grub_cfg}" != "x" ; then
echo "Syntax errors are detected in generated GRUB config file." >&2
echo "${grub_cfg}.new file attached." >&2
else
# none of the children aborted with error, install the new grub.cfg
fi
fi
echo "done" >&2