Skip to content

Commit

Permalink
Revert grub-file usage in grub-mkconfig.
Browse files Browse the repository at this point in the history
  • Loading branch information
phcoder committed Dec 24, 2013
1 parent e5fa26e commit faf4a65
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 181 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2013-12-24 Vladimir Serbinenko <[email protected]>

Revert grub-file usage in grub-mkconfig.

2013-12-24 Vladimir Serbinenko <[email protected]>

Make newly-created files other than grub.cfg world-readable.
Expand Down
7 changes: 7 additions & 0 deletions Makefile.util.def
Original file line number Diff line number Diff line change
Expand Up @@ -439,42 +439,49 @@ script = {
name = '10_hurd';
common = util/grub.d/10_hurd.in;
installdir = grubconf;
condition = COND_HOST_HURD;
};

script = {
name = '10_kfreebsd';
common = util/grub.d/10_kfreebsd.in;
installdir = grubconf;
condition = COND_HOST_KFREEBSD;
};

script = {
name = '10_illumos';
common = util/grub.d/10_illumos.in;
installdir = grubconf;
condition = COND_HOST_ILLUMOS;
};

script = {
name = '10_netbsd';
common = util/grub.d/10_netbsd.in;
installdir = grubconf;
condition = COND_HOST_NETBSD;
};

script = {
name = '10_linux';
common = util/grub.d/10_linux.in;
installdir = grubconf;
condition = COND_HOST_LINUX;
};

script = {
name = '10_xnu';
common = util/grub.d/10_xnu.in;
installdir = grubconf;
condition = COND_HOST_XNU;
};

script = {
name = '20_linux_xen';
common = util/grub.d/20_linux_xen.in;
installdir = grubconf;
condition = COND_HOST_LINUX;
};

script = {
Expand Down
6 changes: 6 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,13 @@ AM_CONDITIONAL([COND_arm_efi], [test x$target_cpu = xarm -a x$platform = xefi])
AM_CONDITIONAL([COND_arm64], [test x$target_cpu = xarm64 ])
AM_CONDITIONAL([COND_arm64_efi], [test x$target_cpu = xarm64 -a x$platform = xefi])

AM_CONDITIONAL([COND_HOST_HURD], [test x$host_kernel = xhurd])
AM_CONDITIONAL([COND_HOST_LINUX], [test x$host_kernel = xlinux])
AM_CONDITIONAL([COND_HOST_NETBSD], [test x$host_kernel = xnetbsd])
AM_CONDITIONAL([COND_HOST_WINDOWS], [test x$host_kernel = xwindows])
AM_CONDITIONAL([COND_HOST_KFREEBSD], [test x$host_kernel = xkfreebsd])
AM_CONDITIONAL([COND_HOST_XNU], [test x$host_kernel = xxnu])
AM_CONDITIONAL([COND_HOST_ILLUMOS], [test x$host_kernel = xillumos])

AM_CONDITIONAL([COND_MAN_PAGES], [test x$cross_compiling = xno -a x$HELP2MAN != x])
AM_CONDITIONAL([COND_GRUB_EMU_USB], [test x$enable_grub_emu_usb = xyes])
Expand Down
55 changes: 8 additions & 47 deletions util/grub-mkconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ usage () {
gettext "Generate a grub config file"; echo
echo
print_option_help "-o, --output=$(gettext FILE)" "$(gettext "output generated config to FILE [default=stdout]")"
print_option_help "-r, --root-directory=$(gettext DIR)" "$(gettext "use DIR as root directory [default=/]")"
print_option_help "-h, --help" "$(gettext "print this message and exit")"
print_option_help "-v, --version" "$(gettext "print the version information and exit")"
echo
Expand All @@ -73,8 +72,6 @@ argument () {
echo $1
}

GRUB_ROOT=

# Check the arguments.
while test $# -gt 0
do
Expand All @@ -93,11 +90,6 @@ do
--output=*)
grub_cfg=`echo "$option" | sed 's/--output=//'`
;;
-r | --root-directory)
GRUB_ROOT=`argument $option "$@"`; shift;;
--root-directory=*)
GRUB_ROOT=`echo "$option" | sed 's/--output=//'`
;;
-*)
gettext_printf "Unrecognized option \`%s'\n" "$option" 1>&2
usage
Expand Down Expand Up @@ -137,19 +129,19 @@ else
fi

# Device containing our userland. Typically used for root= parameter.
GRUB_DEVICE="`${grub_probe} --target=device "$GRUB_ROOT"/`"
GRUB_DEVICE="`${grub_probe} --target=device /`"
GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true

# Device containing our /boot partition. Usually the same as GRUB_DEVICE.
GRUB_DEVICE_BOOT="`${grub_probe} --target=device "$GRUB_ROOT"/boot`"
GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
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.
GRUB_FS="`${grub_probe} --device ${GRUB_DEVICE} --target=fs 2> /dev/null || echo unknown`"

if [ x"$GRUB_FS" = x ] || [ x"$GRUB_FS" = xunknown ]; then
GRUB_FS="$(stat -f --printf=%T "$GRUB_ROOT"/ || echo unknown)"
if [ x"$GRUB_FS" = xunknown ]; then
GRUB_FS="$(stat -f --printf=%T / || echo unknown)"
fi

if test -f ${sysconfdir}/default/grub ; then
Expand Down Expand Up @@ -186,7 +178,6 @@ if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub
# These are defined in this script, export them here so that user can
# override them.
export GRUB_DEVICE \
GRUB_ROOT \
GRUB_DEVICE_UUID \
GRUB_DEVICE_BOOT \
GRUB_DEVICE_BOOT_UUID \
Expand Down Expand Up @@ -256,46 +247,16 @@ EOF

for i in "${grub_mkconfig_dir}"/* ; do
case "$i" in
"${grub_mkconfig_dir}"/00_header \
| "${grub_mkconfig_dir}"/30_os-prober \
| "${grub_mkconfig_dir}"/40_custom \
| "${grub_mkconfig_dir}"/41_custom)
if test -x "$i" ; then
echo
echo "### BEGIN $i ###"
"$i"
echo "### END $i ###"
fi
;;
# emacsen backup files. FIXME: support other editors
*~) ;;
# emacsen autosave files. FIXME: support other editors
*/\#*\#) ;;
*)
if grub_file_is_not_garbage "$i" && test -x "$i" ; then
for platform in x86 i386-xen-pae x86_64-xen mips mipsel sparc64 powerpc ia64 arm arm64; do

GRUB_PLATFORM=$platform
export GRUB_PLATFORM
buf="$($i)"
if [ x"$buf" != x ]; then
echo
echo "### BEGIN $i ($platform) ###"
case x$platform in
xx86)
echo "if [ x\"\$grub_platform\" != xxen \\( x\"\$grub_cpu\" = xi386 -o x\"\$grub_cpu\" = xx86_64 -o x\"\$grub_platform\" = x \\) ]; then" ;;
xi386-xen-pae)
echo "if [ x\"\$grub_cpu-\$grub_platform\" = xi386-xen -o x\"\$grub_cpu-\$grub_platform\" = x- ]; then" ;;
xx86_64-xen)
echo "if [ x\"\$grub_cpu-\$grub_platform\" = xx86_64-xen -o x\"\$grub_cpu-\$grub_platform\" = x- ]; then" ;;
*)
echo "if [ x\"\$grub_cpu\" = x$platform -o x\"\$grub_platform\" = x ]; then" ;;
esac
echo "$buf"
echo "fi"
echo "### END $i ($platform) ###"
fi
done
echo
echo "### BEGIN $i ###"
"$i"
echo "### END $i ###"
fi
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion util/grub.d/00_header.in
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ if [ "x$gfxterm" = x1 ]; then
if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT}"` ; then
EOF
else
for dir in "${pkgdatadir}" "`echo "$GRUB_ROOT"'/@bootdirname@/@grubdirname@' | sed "s,//*,/,g"`" "`echo "$GRUB_ROOT"'/usr/share/grub' | sed "s,//*,/,g"`" ; do
for dir in "${pkgdatadir}" "`echo '/@bootdirname@/@grubdirname@' | sed "s,//*,/,g"`" /usr/share/grub ; do
for basename in unicode unifont ascii; do
path="${dir}/${basename}.pf2"
if is_path_readable_by_grub "${path}" > /dev/null ; then
Expand Down
26 changes: 8 additions & 18 deletions util/grub.d/10_hurd.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ prefix="@prefix@"
exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@"

if [ x$GRUB_PLATFORM = xx86 ]; then
check=--is-x86-multiboot
elif [ x$GRUB_PLATFORM = xi386-xen-pae ]; then
check=--is-i386-xen-pae-domu
elif [ x$GRUB_PLATFORM = xx86_64-xen ]; then
check=--is-x86_64-xen-domu
else
exit 0
fi

export TEXTDOMAIN=@PACKAGE@
export TEXTDOMAINDIR="@localedir@"

Expand All @@ -50,11 +40,11 @@ all_of_them=true

# FIXME: add l4 here?
kernel=
for i in "$GRUB_ROOT"/boot/gnumach* ; do
if test -f "$i" && "${grub_file}" $check "$i" ; then
basename=`basename "$i"`
dirname=`dirname "$i"`
rel_dirname=`make_system_path_relative_to_its_root "$dirname"`
for i in /boot/gnumach* ; do
if test -e $i ; then
basename=`basename $i`
dirname=`dirname $i`
rel_dirname=`make_system_path_relative_to_its_root $dirname`
gettext_printf "Found GNU Mach: %s" "$i" >&2
echo >&2
kernels="${kernels} ${rel_dirname}/${basename}"
Expand All @@ -68,8 +58,8 @@ case "${GRUB_FS}" in
*) hurd_fs="${GRUB_FS}fs" ;;
esac

for i in "$GRUB_ROOT"/hurd/${hurd_fs}.static "$GRUB_ROOT"/hurd/exec ; do
if test -f "$i" ; then
for i in /hurd/${hurd_fs}.static /hurd/exec ; do
if test -e "$i" ; then
gettext_printf "Found Hurd module: %s" "$i" >&2
echo >&2
at_least_one=true
Expand All @@ -83,7 +73,7 @@ if ${at_least_one} ; then : ; else
exit 0
fi

if ${all_of_them} && test -f "$GRUB_ROOT"/lib/ld.so.1 ; then : ; else
if ${all_of_them} && test -e /lib/ld.so.1 ; then : ; else
gettext "Some Hurd stuff found, but not enough to boot." >&2
echo >&2
exit 1
Expand Down
17 changes: 1 addition & 16 deletions util/grub.d/10_illumos.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ export TEXTDOMAINDIR="@localedir@"

CLASS="--class os"

if [ x$GRUB_PLATFORM = xx86 ]; then
check=--is-x86-multiboot
elif [ x$GRUB_PLATFORM = xi386-xen-pae ]; then
check=--is-i386-xen-pae-domu
elif [ x$GRUB_PLATFORM = xx86_64-xen ]; then
check=--is-x86_64-xen-domu
else
exit 0
fi

if ! test -f "$GRUB_ROOT"/platform/i86pc/kernel || ! "${grub_file}" $check "$GRUB_ROOT"/platform/i86pc/kernel; then
exit 0
fi


case "${GRUB_DISTRIBUTOR}" in
*)
OS="Illumos"
Expand All @@ -60,7 +45,7 @@ message="$(gettext_printf "Loading kernel of Illumos ...")"
else
ISADIR=
fi
zfs-bootfs $($grub_mkrelpath "$GRUB_ROOT"/) ZFS_BOOTFS
zfs-bootfs $($grub_mkrelpath /) ZFS_BOOTFS
echo '$(echo "$message" | grub_quote)'
multiboot $($grub_mkrelpath /platform/i86pc/kernel)/\$ISADIR/unix /platform/i86pc/kernel/\$ISADIR/unix -B \$ZFS_BOOTFS,console=text
module $($grub_mkrelpath /platform/i86pc)/\$ISADIR/boot_archive /platform/i86pc/\$ISADIR/boot_archive
Expand Down
30 changes: 10 additions & 20 deletions util/grub.d/10_kfreebsd.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ export TEXTDOMAINDIR="@localedir@"

CLASS="--class os"

if [ x$GRUB_PLATFORM = xx86 ]; then
check=--is-x86-kfreebsd
elif [ x$GRUB_PLATFORM = xi386-xen-pae ]; then
check=--is-i386-xen-pae-domu
elif [ x$GRUB_PLATFORM = xx86_64-xen ]; then
check=--is-x86_64-xen-domu
else
exit 0
fi

case "${GRUB_DISTRIBUTOR}" in
Debian)
OS="${GRUB_DISTRIBUTOR} GNU/kFreeBSD"
Expand Down Expand Up @@ -132,10 +122,10 @@ EOF
zfs)
load_kfreebsd_module opensolaris false

ls "$GRUB_ROOT/boot/zfs/zpool.cache" > /dev/null
ls "/boot/zfs/zpool.cache" > /dev/null
printf '%s\n' "${prepare_boot_cache}"
sed "s/^/$submenu_indentation/" << EOF
kfreebsd_module $(make_system_path_relative_to_its_root $GRUB_ROOT/boot)/zfs/zpool.cache type=/boot/zfs/zpool.cache
kfreebsd_module $(make_system_path_relative_to_its_root /boot)/zfs/zpool.cache type=/boot/zfs/zpool.cache
EOF
;;
esac
Expand All @@ -153,8 +143,8 @@ EOF
EOF
}

list=`for i in $GRUB_ROOT/boot/kfreebsd-* $GRUB_ROOT/boot/kernel/kernel ; do
if grub_file_is_not_garbage "$i" && ${grub_file} $check "$i"; then echo -n "$i " ; fi
list=`for i in /boot/kfreebsd-* /boot/kernel/kernel ; do
if grub_file_is_not_garbage "$i" ; then echo -n "$i " ; fi
done`
prepare_boot_cache=
boot_device_id=
Expand All @@ -173,8 +163,8 @@ while [ "x$list" != "x" ] ; do
dirname=`dirname $kfreebsd`
rel_dirname=`make_system_path_relative_to_its_root $dirname`

if [ -f "$GRUB_ROOT"/boot/device.hints ] ; then
devices="$GRUB_ROOT"/boot/device.hints
if [ -f /boot/device.hints ] ; then
devices=/boot/device.hints
devices_basename=`basename $devices`
devices_dirname=`dirname $devices`
devices_rel_dirname=`make_system_path_relative_to_its_root $devices_dirname`
Expand All @@ -191,14 +181,14 @@ while [ "x$list" != "x" ] ; do
# zpool name
kfreebsd_device=$(${grub_probe} -t fs_label --device ${GRUB_DEVICE})
# filesystem name (empty string for the main filesystem)
kfreebsd_device="${kfreebsd_device}$(${grub_mkrelpath} "$GRUB_ROOT"/ | sed -e "s,/*@$,,")"
kfreebsd_device="${kfreebsd_device}$(${grub_mkrelpath} / | sed -e "s,/*@$,,")"
;;
*)
kfreebsd_device=${kfreebsd_fs}id/${GRUB_DEVICE_UUID}
# Debian GNU/kFreeBSD can't remount root if it's supplied as UUID but
# as an UUID
if [ "x${GRUB_DISTRIBUTOR}" = "xDebian" ] \
&& ! (cat "$GRUB_ROOT"/etc/fstab | awk '!/^[[:space:]]*#/ && $2=="/" { print $1; }' \
&& ! (cat /etc/fstab | awk '!/^[[:space:]]*#/ && $2=="/" { print $1; }' \
| grep "${kfreebsd_fs}id/${GRUB_DEVICE_UUID}" > /dev/null); then
kfreebsd_device=${GRUB_DEVICE}
fi
Expand All @@ -209,8 +199,8 @@ while [ "x$list" != "x" ] ; do
alt_version=`echo $version | sed -e "s,\.old$,,g"`

module_dir=
for i in "$GRUB_ROOT/lib/modules/${version}" "$GRUB_ROOT/lib/modules/${alt_version}" \
"$GRUB_ROOT/boot/kernel"; do
for i in "/lib/modules/${version}" "/lib/modules/${alt_version}" \
"/boot/kernel"; do
if test -e "$i" ; then
module_dir="$i"
break
Expand Down
Loading

0 comments on commit faf4a65

Please sign in to comment.