--- /usr/portage/sys-boot/grub/grub-0.97-r5.ebuild 2008-04-07 10:38:48.000000000 +0200 +++ /usr/portage/sys-boot/grub/grub-0.97-r5.ebuild 2008-04-21 16:20:05.000000000 +0200 @@ -142,6 +142,7 @@ src_install() { setup_boot_dir() { local boot_dir=$1 local dir=${boot_dir} + local instcfg="${ROOT}"/etc/grub.install [[ ! -e ${dir} ]] && die "${dir} does not exist!" [[ ! -L ${dir}/boot ]] && ln -s . "${dir}/boot" @@ -154,18 +155,12 @@ setup_boot_dir() { if [[ ! -e ${dir}/grub.conf ]] && [[ -e ${dir}/menu.lst ]] ; then mv -f "${dir}"/menu.lst "${dir}"/grub.conf ewarn - ewarn "*** IMPORTANT NOTE: menu.lst has been renamed to grub.conf" + ewarn "menu.lst has been renamed to grub.conf" ewarn fi if [[ -e ${dir}/stage2 ]] ; then mv "${dir}"/stage2{,.old} - ewarn "*** IMPORTANT NOTE: you must run grub and install" - ewarn "the new version's stage1 to your MBR. Until you do," - ewarn "stage1 and stage2 will still be the old version, but" - ewarn "later stages will be the new version, which could" - ewarn "cause problems such as an unbootable system." - ebeep fi einfo "Copying files from /lib/grub and /usr/lib/grub to ${dir}" @@ -173,13 +168,76 @@ setup_boot_dir() { [[ -f ${x} ]] && cp -p "${x}" "${dir}"/ done - if [[ -e ${dir}/grub.conf ]] ; then - egrep \ - -v '^[[:space:]]*(#|$|default|fallback|initrd|password|splashimage|timeout|title)' \ - "${dir}"/grub.conf | \ + if [[ ! -e ${instcfg} ]] ; then + cat > "${instcfg}" <<-EOF + # Commands to be used to install grub. + # These commands will be executed whenever grub is updated. + # You can also run them manually using emerge --config grub. + # See "info grub" or http://www.gnu.org/software/grub/ + + # Take the first partition on the first drive as the boot partition + #root (hd0,0) + + # Install grub into the MBR of the first hard disk drive: + #setup (hd0) + + # Install grub into the first partition of the first hard disk: + #setup (hd0,0) + EOF + + if [[ -e ${dir}/grub.conf ]] && \ + egrep '^(setup|install)' "${dir}"/grub.conf >/dev/null; then + echo >> ${instcfg} + echo "# Entries automatically copied from your grub.conf:" >> ${instcfg} + + # from each menu entry containing either an install + # or a setup command, take the title as a comment, + # and include all commands between title and + # install/setup. + # No perl to keep dependencies down, sorry. + sed -n '/^root\|^map/{x;/^# title/!{x;p;x};x}; + H + /^title/{s/^/# /;h;d} + /^install\|^setup/{x;p;s/.*/# continued/;x}' \ + "${dir}"/grub.conf >> "${instcfg}" + elog + elog "Commands for automatic installation of grub have been extracted from" + elog "your grub.conf and saved in /etc/grub.install." + elog "Please review that file." + elog + fi + fi + + if egrep '^(setup|install)' "${instcfg}" >/dev/null; then + einfo "Reinstalling grub with commands from ${instcfg}" + egrep '^[^#]' "${instcfg}" | \ /sbin/grub --batch \ --device-map="${dir}"/device.map \ - > /dev/null + >"${T}"/grubinstall.out 2>&1 + local grub_res=$? + if [[ $grub_res != 0 ]] || egrep 'Error' "${T}"/grubinstall.out >/dev/null; then + eerror + eerror "Grub failed to install automatically!" + eerror "Please instal it manually" + eerror + while read grub_res; do + elog "${grub_res}" + done < "${T}"/grubinstall.out + else + cat "${T}"/grubinstall.out + fi + echo + else + ewarn "There are no commands in ${instcfg} to install grub automatically." + ewarn "Therefore you need to either install grub manually, or edit this" + ewarn "file and run emerge --config =${PF} afterwards." + if [[ -e ${dir}/stage2.old ]] ; then + ewarn "" + ewarn "*** IMPORTANT NOTE: you must install the new version" + ewarn "to your system. Until you do, conflicting versions" + ewarn "might cause problems such as an unbootable system." + ebeep + fi fi # the grub default commands silently piss themselves if @@ -198,7 +256,7 @@ pkg_postinst() { pkg_config() { local dir - einfo "Enter the directory where you want to setup grub:" - read dir + read -p "Enter the directory where you want to setup grub [/boot]: " dir + [[ -z $dir ]] && dir=/boot setup_boot_dir "${dir}" }