#!/bin/bash ## COPYRIGHT 2013 : MARK E. LEE (BLUERIDER) : mlee24@binghamton.edu; mark@markelee.com ## LOG ## 1/17/2013 : Version 2 of refind_name_patch is released ## : Supports long subdirectory location for refind ## : Updates nvram when needed ## : 10% speed boost function main () { ## main insertion function declare -r refind_dir="/boot/efi/EFI/refind"; ## set the refind directory declare -r arch=$(uname -m | awk -F'_' '{if ($1 == "x86"){print $2}}') && ## get bit architecture update-efi-dir; ## updates or creates the refind directory update-efi-nvram; ## updates nvram if needed } function update-efi-dir () { ## setup the refind directory if [ ! -d $refind_dir ]; then ## check if refind directory exists echo "Couldn't find $refind_dir"; sudo mkdir $refind_dir && ## make the refind directory if needed echo "Made $refind_dir"; fi; if [ "$arch" ]; then ## check if anything was stored in $arch sudo cp -r /usr/{share/refind/*,lib/refind/*$arch*} $refind_dir/ && ## update bin and dirs echo "Updated binaries and directory files for refind at $refind_dir"; else echo "Failed to detect an x86 architecture"; exit; fi; } function update-efi-nvram () { ## update the nvram with efibootmgr declare -r ref_bin=${refind_dir/\/boot\/efi}/$(ls /usr/lib | grep $arch*.efi); ## get path of refind binary (without /boot/efi) declare -r ref_bin_escape=${ref_bin//\//\\\\}; ## insert escape characters into $ref_bin sudo modprobe efivars && ## grab the efi variables for efibootmgr sudo efibootmgr -v | grep $ref_bin_escape && ( ## check if boot entry is in nvram echo "Found boot entry, no need to update nvram"; ) || ( ## if boot entry is not in nvam; add it declare -r esp=$(mount -l | awk '/ESP/ {print $1}') && ## get ESP partition sudo efibootmgr -c -g -d ${esp:0:8} -p ${esp:8} -w -L "rEFInd" -l $ref_bin_escape && ## update nvram echo " Updated nvram with entry rEFInd to boot $ref_bin Did not copy configuration files, please move refind.conf to $refind_dir/"; ) } main; ## run the main insertion function