# Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ EAPI=4 inherit eutils DESCRIPTION="rEFInd Extensible Firmware Interface boot manager binary install" HOMEPAGE="http://www.rodsbooks.com/refind/index.html" SRC_URI="mirror://sourceforge/refind/${PV}/${P}.zip" #MERGE_TYPE="binary" LICENSE="GPL-3" SLOT="0" KEYWORDS="~amd64 ~ia64 ~x86" IUSE="" RDEPEND="" DEPEND="${RDEPEND} sys-boot/efibootmgr" PROVIDE="virtual/bootloader" src_install() { einfo "Installing rEFInd on Linux" # FindLinuxESP EspLine=`df /boot/efi | grep boot` InstallPart=`echo $EspLine | cut -d " " -f 6` EspFilesystem=`grep $InstallPart /etc/mtab | cut -d " " -f 3` if [[ $EspFilesystem != 'vfat' ]] ; then eerror "/boot/efi doesn't seem to be on a VFAT filesystem. The ESP must be mounted" eerror "at /boot or /boot/efi and it must be VFAT! Aborting!" die "Unable to mount a VFAT file system at /boot or /boot/efi." fi einfo "ESP was found at $InstallPart using $EspFilesystem" # InstallOnLinux CpuType=`uname -m` if [[ $CpuType == 'x86_64' ]] ; then Platform="EFI64" elif [[ $CpuType == 'i386' || $CpuType == 'i486' || $CpuType == 'i586' || $CpuType == 'i686' ]] ; then Platform="EFI32" ewarn "CAUTION: This Linux installation uses a 32-bit kernel. 32-bit EFI-based" ewarn "computers are VERY RARE. If you've installed a 32-bit version of Linux" ewarn "on a 64-bit computer, you should manually install the 64-bit version of" ewarn "rEFInd. If you're installing on a Mac, you should do so from OS X." ewarn "Installation will now proceed presuming a 32-bit EFI." else die "Unknown CPU type '$CpuType'; aborting!" fi # CopyRefindFiles RefindDir="${S}/refind" TargetDir="/EFI/refind" exeinto ${InstallPart}/${TargetDir} if [[ $Platform == 'EFI32' ]] ; then doexe $RefindDir/refind_ia32.efi Refind="refind_ia32.efi" elif [[ $Platform == 'EFI64' ]] ; then doexe $RefindDir/refind_x64.efi Refind="refind_x64.efi" else die "Unknown platform! Aborting!" fi einfo "Copied rEFInd binary file $Refind" doins -r icons/ einfo "Copied rEFInd icons directory" doins $RefindDir/refind.conf-sample einfo "Copied sample rEFInd configuration file" } pkg_config() { InstallIt="0" Efibootmgr=`which efibootmgr 2> /dev/null` if [[ $Efibootmgr ]] ; then modprobe efivars &> /dev/null InstallDisk=`grep $InstallPart /etc/mtab | cut -d " " -f 1 | cut -c 1-8` PartNum=`grep $InstallPart /etc/mtab | cut -d " " -f 1 | cut -c 9-10` EntryFilename=$TargetDir/$Refind EfiEntryFilename=`echo ${EntryFilename//\//\\\}` EfiEntryFilename2=`echo ${EfiEntryFilename} | sed s/\\\\\\\\/\\\\\\\\\\\\\\\\/g` ExistingEntry=`$Efibootmgr -v | grep $EfiEntryFilename2` if [[ $ExistingEntry ]] ; then ExistingEntryBootNum=`echo $ExistingEntry | cut -c 5-8` FirstBoot=`$Efibootmgr | grep BootOrder | cut -c 12-15` if [[ $ExistingEntryBootNum != $FirstBoot ]] ; then einfo "An existing rEFInd boot entry exists, but isn't set as the default boot" einfo "manager. The boot order is being adjusted to make rEFInd the default boot" einfo "manager. If this is NOT what you want, you should use efibootmgr to" einfo "manually adjust your EFI's boot order." $Efibootmgr -b $ExistingEntryBootNum -B &> /dev/null InstallIt="1" fi else InstallIt="1" fi if [[ $InstallIt == "1" ]] ; then einfo "Installing rEFInd as default boot manager" $Efibootmgr -c -l $EfiEntryFilename -L rEFInd -d $InstallDisk -p $PartNum &> /dev/null fi else ewarn "ALERT: There were problems running the efibootmgr program! You may need to" ewarn "rename the $Refind binary to the default name (EFI/boot/bootx64.efi" ewarn "on x86-64 systems or EFI/boot/bootia32.efi on x86 systems) to have it run!" fi }