#!/bin/bash ## COPYRIGHT 2013 : MARK E. LEE (BLUERIDER) : mlee24@binghamton.edu; mark@markelee.com ## LOG ## 1/16/2013 : updates nvram and specfied efi directory ($efi_dir); can also generate $efi_dir ## 1/16/2013 : depends on awk and bash ## 1/16/2013 : $efi_dir must possessess only 4 directories ## 1/16/2013 : currently doesn't copy config files function main () { ## main insertion function declare -r efi_dir="/boot/efi/EFI/refind"; ## set the refind directory ## convert efi_dir to efibootmgr format declare -r refind_efi=$(echo ${efi_dir/\/boot\/efi/} | awk -F'/' '{OFS= "\\"; print ($1,$2,$3)}') update-efi-dir; ## updates or creates the refind directory ## only run update-efi-nvram if necessary, needs to detect if $refind_efi\\$ref_bin was already set in nvram # update-efi-nvram; ## updates nvram if needed } function update-efi-dir () { ## setup the refind directory if [ ! -d $efi_dir ]; then ## check if refind directory exists echo "Couldn't find $efi_dir"; sudo mkdir $efi_dir && ## make the refind directory if needed echo "Made $efi_dir"; fi; declare -r arch=$(uname -m | awk -F'_' '{if ($1 == "x86"){print $2}}') && ## get bit architecture if [ "$arch" ]; then ## check if anything was stored in $arch sudo cp -r /usr/{share/refind,lib/refind/*$arch*} $efi_dir/ && ## update bin and dirs echo "Updated binaries and directory files for refind at $efi_dir"; else echo "Failed to detect an x86 architecture"; exit; fi; declare -r ref_bin=$(ls $efi_dir | grep $arch*.efi); ## get the name of the refind binary } function update-efi-nvram () { ## update the nvram with efibootmgr sudo modprobe efivars && ## grab the efi variables for efibootmgr declare -r esp=$(mount -l | awk '/ESP/ {print $1}') && ## get ESP partition declare -r efiDisk=${esp:0:8} && ## get ESP disk declare -r efiPart=${esp:8} && ## get ESP partition number ## update the nvram with entry "rEFInd" sudo efibootmgr -c -g -d $efiDisk -p $efiPart -w -L "rEFInd" -l "$refind_efi\\$ref_bin" && echo "Updated nvram with entry rEFInd to boot $refind_efi\$ref_bin.efi"; echo "Did not copy configuration files, please move refind.conf to $efi_dir/"; } main; ## run the main insertion function