]> code.delx.au - refind/blobdiff - install.sh
Misc. small changes.
[refind] / install.sh
index 1037bea7692354b3411d1efcb8bdd8f4f0ee4cdc..c70c80352bb1ee1dc5fd9fccf7e0e56afdfd3259 100755 (executable)
@@ -17,7 +17,9 @@
 #
 # Revision history:
 #
-# 0.3.2 -- Initial version
+# 0.3.3.1 -- Fixed OS X 10.7 bug; also works as make target
+# 0.3.2.1 -- Check for presence of source files; aborts if not present
+# 0.3.2   -- Initial version
 #
 # Note: install.sh version numbers match those of the rEFInd package
 # with which they first appeared.
@@ -28,16 +30,49 @@ TargetDir=/EFI/refind
 # Functions used by both OS X and Linux....
 #
 
+# Abort if the rEFInd files can't be found.
+# Also sets $ConfFile to point to the configuration file, and
+# $IconsDir to point to the icons directory
+CheckForFiles() {
+   # Note: This check is satisfied if EITHER the 32- or the 64-bit version
+   # is found, even on the wrong platform. This is because the platform
+   # hasn't yet been determined. This could obviously be improved, but it
+   # would mean restructuring lots more code....
+   if [[ ! -f $RefindDir/refind_ia32.efi && ! -f $RefindDir/refind_x64.efi ]] ; then
+      echo "The rEFInd binary file is missing! Aborting installation!"
+      exit 1
+   fi
+
+   if [[ -f $RefindDir/refind.conf-sample ]] ; then
+      ConfFile=$RefindDir/refind.conf-sample
+   elif [[ -f $ThisDir/refind.conf-sample ]] ; then
+      ConfFile=$ThisDir/refind.conf-sample
+   else
+      echo "The sample configuration file is missing! Aborting installation!"
+      exit 1
+   fi
+
+   if [[ -d $RefindDir/icons ]] ; then
+      IconsDir=$RefindDir/icons
+   elif [[ -d $ThisDir/icons ]] ; then
+      IconsDir=$ThisDir/icons
+   else
+      echo "The icons directory is missing! Aborting installation!"
+   fi
+} # CheckForFiles()
+
+# Copy the rEFInd files to the ESP or OS X root partition.
+# Sets Problems=1 if any critical commands fail.
 CopyRefindFiles() {
    mkdir -p $InstallPart/$TargetDir &> /dev/null
    if [[ $Platform == 'EFI32' ]] ; then
-      cp $SourceDir/refind_ia32.efi $InstallPart/$TargetDir
+      cp $RefindDir/refind_ia32.efi $InstallPart/$TargetDir
       if [[ $? != 0 ]] ; then
          Problems=1
       fi
       Refind="refind_ia32.efi"
    elif [[ $Platform == 'EFI64' ]] ; then
-      cp $SourceDir/refind_x64.efi $InstallPart/$TargetDir
+      cp $RefindDir/refind_x64.efi $InstallPart/$TargetDir
       if [[ $? != 0 ]] ; then
          Problems=1
       fi
@@ -53,7 +88,7 @@ CopyRefindFiles() {
       mv -f $InstallPart/$TargetDir/icons $InstallPart/$TargetDir/icons-backup
       echo "Notice: Backed up existing icons directory as icons-backup."
    fi
-   cp -r $SourceDir/icons $InstallPart/$TargetDir
+   cp -r $IconsDir $InstallPart/$TargetDir
    if [[ $? != 0 ]] ; then
       Problems=1
    fi
@@ -61,7 +96,7 @@ CopyRefindFiles() {
       echo "Existing refind.conf file found; copying sample file as refind.conf-sample"
       echo "to avoid collision."
       echo ""
-      cp -f $SourceDir/refind.conf-sample $InstallPart/$TargetDir
+      cp -f $ConfFile $InstallPart/$TargetDir
       if [[ $? != 0 ]] ; then
          Problems=1
       fi
@@ -69,7 +104,7 @@ CopyRefindFiles() {
       echo "Copying sample configuration file as refind.conf; edit this file to configure"
       echo "rEFInd."
       echo ""
-      cp -f $SourceDir/refind.conf-sample $InstallPart/$TargetDir/refind.conf
+      cp -f $ConfFile $InstallPart/$TargetDir/refind.conf
       if [[ $? != 0 ]] ; then
          Problems=1
       fi
@@ -105,6 +140,8 @@ MountOSXESP() {
    fi
 } # MountOSXESP()
 
+# Control the OS X installation.
+# Sets Problems=1 if problems found during the installation.
 InstallOnOSX() {
    echo "Installing rEFInd on OS X...."
    if [[ $1 == 'esp' || $1 == 'ESP' ]] ; then
@@ -135,6 +172,9 @@ InstallOnOSX() {
 # Now a series of Linux support functions....
 #
 
+# Identifies the ESP's location (/boot or /boot/efi); aborts if
+# the ESP isn't mounted at either location.
+# Sets InstallPart to the ESP mount point.
 FindLinuxESP() {
    EspLine=`df /boot/efi | grep boot`
    InstallPart=`echo $EspLine | cut -d " " -f 6`
@@ -147,6 +187,8 @@ FindLinuxESP() {
    echo "ESP was found at $InstallPart using $EspFilesystem"
 } # MountLinuxESP
 
+# Uses efibootmgr to add an entry for rEFInd to the EFI's NVRAM.
+# If this fails, sets Problems=1
 AddBootEntry() {
    Efibootmgr=`which efibootmgr 2> /dev/null`
    if [[ $Efibootmgr ]] ; then
@@ -182,6 +224,8 @@ AddBootEntry() {
    fi
 } # AddBootEntry()
 
+# Controls rEFInd installation under Linux.
+# Sets Problems=1 if something goes wrong.
 InstallOnLinux() {
    echo "Installing rEFInd on Linux...."
    FindLinuxESP
@@ -213,10 +257,17 @@ InstallOnLinux() {
    AddBootEntry
 } # InstallOnLinux()
 
-# The main part of the script; just checks the OS and calls a
-# function for installing on that platform....
+#
+# The main part of the script. Sets a few environment variables,
+# performs a few startup checks, and then calls functions to
+# install under OS X or Linux, depending on the detected platform.
+#
 
-ThisScript=`readlink -f $0`
+OSName=`uname -s`
+ThisDir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+RefindDir="$ThisDir/refind"
+ThisScript="$ThisDir/`basename $0`"
+CheckForFiles
 if [[ `whoami` != "root" ]] ; then
    echo "Not running as root; attempting to elevate privileges via sudo...."
    sudo $ThisScript $1
@@ -227,8 +278,6 @@ if [[ `whoami` != "root" ]] ; then
       exit 0
    fi
 fi
-OSName=`uname -s`
-SourceDir=`dirname $ThisScript`/refind
 if [[ $OSName == 'Darwin' ]] ; then
    InstallOnOSX $1
 elif [[ $OSName == 'Linux' ]] ; then