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