grub-static-0.97-r10.ebuild 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. # Copyright 1999-2012 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # XXX: we need to review menu.lst vs grub.conf handling. We've been converting
  4. # all systems to grub.conf (and symlinking menu.lst to grub.conf), but
  5. # we never updated any of the source code (it still all wants menu.lst),
  6. # and there is no indication that upstream is making the transition.
  7. inherit eutils mount-boot toolchain-funcs linux-info
  8. PATCHVER="1.9" # Not used, just for tracking with main grub
  9. DESCRIPTION="GNU GRUB Legacy boot loader (static build)"
  10. HOMEPAGE="https://www.gnu.org/software/grub/"
  11. SRC_URI="mirror://gentoo/${PF}.tar.bz2"
  12. LICENSE="GPL-2"
  13. SLOT="0"
  14. KEYWORDS="-* amd64 ~x86"
  15. IUSE=""
  16. DEPEND="!<sys-boot/grub-2"
  17. RDEPEND="${DEPEND}"
  18. # These are already stripped since we use a binpkg.
  19. QA_PRESTRIPPED="/sbin/grub /bin/mbchk"
  20. pkg_setup() {
  21. local arch="$(tc-arch)"
  22. case ${arch} in
  23. amd64)
  24. CONFIG_CHECK='~IA32_EMULATION'
  25. WARNING_IA32_EMULATION="You will NOT be able to run grub unless you have IA32_EMULATION set!"
  26. check_extra_config
  27. ;;
  28. esac
  29. }
  30. src_install() {
  31. cp -a "${WORKDIR}"/* "${D}"/
  32. if [[ -z "${I_KNOW_WHAT_I_AM_DOING}" ]]; then
  33. run_test_grub "${D}"/sbin/grub && einfo "New grub can run on your system, good!"
  34. fi
  35. }
  36. run_test_grub() {
  37. local grub="$1"
  38. local version="$(${grub} \
  39. --read-only --no-pager --no-floppy --no-curses \
  40. --no-config-file --batch --version)"
  41. local error="grub test-run failed"
  42. use amd64 && error="${error} Is IA32_EMULATION set?"
  43. [ "${version/${PV}}" != "${version}" ] || die "${error}"
  44. return 0
  45. }
  46. #
  47. # Below this point, everything is also used in grub-static!
  48. # Please keep in sync!
  49. #
  50. setup_boot_dir() {
  51. local boot_dir=$1
  52. local dir=${boot_dir}
  53. if [[ -z "${I_KNOW_WHAT_I_AM_DOING}" ]]; then
  54. run_test_grub /sbin/grub
  55. fi
  56. mkdir -p "${dir}"
  57. [[ ! -L ${dir}/boot ]] && ln -s . "${dir}/boot"
  58. dir="${dir}/grub"
  59. if [[ ! -e ${dir} ]] ; then
  60. mkdir "${dir}" || die "${dir} does not exist!"
  61. fi
  62. # change menu.lst to grub.conf
  63. if [[ ! -e ${dir}/grub.conf ]] && [[ -e ${dir}/menu.lst ]] ; then
  64. mv -f "${dir}"/menu.lst "${dir}"/grub.conf
  65. ewarn
  66. ewarn "*** IMPORTANT NOTE: menu.lst has been renamed to grub.conf"
  67. ewarn
  68. fi
  69. if [[ ! -e ${dir}/menu.lst ]]; then
  70. einfo "Linking from new grub.conf name to menu.lst"
  71. ln -snf grub.conf "${dir}"/menu.lst
  72. fi
  73. if [[ -e ${dir}/stage2 ]] ; then
  74. mv "${dir}"/stage2{,.old}
  75. ewarn "*** IMPORTANT NOTE: you must run grub and install"
  76. ewarn "the new version's stage1 to your MBR. Until you do,"
  77. ewarn "stage1 and stage2 will still be the old version, but"
  78. ewarn "later stages will be the new version, which could"
  79. ewarn "cause problems such as an unbootable system."
  80. ewarn "This means you must use either grub-install or perform"
  81. ewarn "root/setup manually! For more help, see the handbook:"
  82. ewarn "https://www.gentoo.org/doc/en/handbook/handbook-${ARCH}.xml?part=1&chap=10#grub-install-auto"
  83. ebeep
  84. fi
  85. einfo "Copying files from /lib/grub, /usr/lib/grub and /usr/share/grub to ${dir}"
  86. for x in \
  87. "${ROOT}"/lib*/grub/*/* \
  88. "${ROOT}"/usr/lib*/grub/*/* \
  89. "${ROOT}"/usr/share/grub/* ; do
  90. [[ -f ${x} ]] && cp -p "${x}" "${dir}"/
  91. done
  92. if [[ ! -e ${dir}/grub.conf ]] ; then
  93. s="${ROOT}/usr/share/doc/${PF}/grub.conf.gentoo"
  94. [[ -e "${s}" ]] && cat "${s}" >${dir}/grub.conf
  95. [[ -e "${s}.gz" ]] && zcat "${s}.gz" >${dir}/grub.conf
  96. [[ -e "${s}.bz2" ]] && bzcat "${s}.bz2" >${dir}/grub.conf
  97. fi
  98. # Per bug 218599, we support grub.conf.install for users that want to run a
  99. # specific set of Grub setup commands rather than the default ones.
  100. grub_config=${dir}/grub.conf.install
  101. [[ -e ${grub_config} ]] || grub_config=${dir}/grub.conf
  102. if [[ -e ${grub_config} ]] ; then
  103. local tmp="${TMPDIR}/${P}-setup_boot_dir-$$"
  104. egrep \
  105. -v '^[[:space:]]*(#|$|default|fallback|initrd|password|splashimage|timeout|title)' \
  106. "${grub_config}" >"${tmp}"
  107. # Do NOT fail here, only warn.
  108. /sbin/grub --batch \
  109. --device-map="${dir}"/device.map \
  110. >/dev/null <"${tmp}"
  111. rc=$?
  112. [[ $rc -ne 0 ]] && ewarn "Grub failed to run!"
  113. fi
  114. # the grub default commands silently piss themselves if
  115. # the default file does not exist ahead of time
  116. if [[ ! -e ${dir}/default ]] ; then
  117. # This may fail, don't worry about it.
  118. grub-set-default --root-directory="${boot_dir}" default
  119. :
  120. fi
  121. einfo "Grub has been installed to ${boot_dir} successfully."
  122. }
  123. pkg_postinst() {
  124. mount-boot_pkg_postinst
  125. if [[ -n ${DONT_MOUNT_BOOT} ]]; then
  126. elog "WARNING: you have DONT_MOUNT_BOOT in effect, so you must apply"
  127. elog "the following instructions for your /boot!"
  128. elog "Neglecting to do so may cause your system to fail to boot!"
  129. elog
  130. else
  131. setup_boot_dir "${ROOT}"/boot
  132. # Trailing output because if this is run from pkg_postinst, it gets mixed into
  133. # the other output.
  134. einfo ""
  135. fi
  136. elog "To interactively install grub files to another device such as a USB"
  137. elog "stick, just run the following and specify the directory as prompted:"
  138. elog " emerge --config =${PF}"
  139. elog "Alternately, you can export GRUB_ALT_INSTALLDIR=/path/to/use to tell"
  140. elog "grub where to install in a non-interactive way."
  141. }
  142. pkg_config() {
  143. local dir
  144. if [ ! -d "${GRUB_ALT_INSTALLDIR}" ]; then
  145. einfo "Enter the directory where you want to setup grub:"
  146. read dir
  147. else
  148. dir="${GRUB_ALT_INSTALLDIR}"
  149. fi
  150. setup_boot_dir "${dir}"
  151. }