]> code.delx.au - refind/blobdiff - mvrefind
Fixed bug that caused mvrefind to fail to move bootmgfw.efi in some
[refind] / mvrefind
index 6b16a1a0eaf9ba8db570e903416e3396dff16878..0c0bf1523d47e641090730b53b4bf0027e10620b 100755 (executable)
--- a/mvrefind
+++ b/mvrefind
@@ -1,7 +1,15 @@
 #!/bin/bash
 #
-# Linux script to move an existing rEFInd installation from one directory to another
+# Linux script to move an existing rEFInd installation from one directory to
+# another
 #
+# copyright (c) 2013-2015 by Roderick W. Smith
+#
+# This program is licensed under the terms of the GNU GPL, version 3,
+# or (at your option) any later version.
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
 # Usage:
 #
 # ./mvrefind /path/to/source /path/to/destination
 #
 # Revision history:
 #
-# 0.9.3   -- Renamed from mvrefind.sh to mvrefind
+# 0.10.2  -- Fixed bug in moving bootmgfw.efi in some situations
+# 0.10.1  -- Generalized to support ARM64 (aka AARCH64, aa64)
+# 0.10.0  -- Renamed from mvrefind.sh to mvrefind
 # 0.6.3   -- Initial release
 #
 # Note: mvrefind version numbers match those of the rEFInd package
 # with which they first appeared.
 
 RootDir="/"
-SourceX64="refind_x64.efi"
-TargetX64=$SourceX64
-SourceIA32="refind_ia32.efi"
-TargetIA32=$SourceIA32
 SourceShim="shim.efi"
 TargetShim=$SourceShim
 SourceDir=`readlink -f ${1}`
@@ -76,14 +82,34 @@ FindLinuxESP() {
    fi
 } # FindLinuxESP
 
+DeterminePlatform() {
+    CpuType=`uname -m`
+    case "$CpuType" in
+    aarch64)
+        Platform="aa64"
+        ;;
+    x86_64)
+        Platform="x64"
+        ;;
+    i?86)
+        Platform="ia32"
+        ;;
+    *)
+        echo "Unsupported CPU type; aborting!"
+        exit 1
+    esac
+    Source="refind_$Platform.efi"
+    Target=$Source
+}
+
 # Adjust filename variables appropriately for their locations and detected
 # presence (or lack thereof) of shim installation
 AdjustFilenames() {
-   if [[ -f $SourceDir/grubx64.efi ]] ; then
-      SourceX64="grubx64.efi"
-      TargetX64=$SourceX64
+   if [[ -f $SourceDir/grub$Platform.efi ]] ; then
+      Source="grub$Platform.efi"
+      Target=$Source
       if [[ $EspSourceDir == "/efi/boot" ]] ; then
-         SourceShim="bootx64.efi"
+         SourceShim="boot$Platform.efi"
       elif [[ $EspSourceDir == "/efi/microsoft/boot" ]] ; then
          SourceShim="bootmgfw.efi"
       fi
@@ -91,23 +117,21 @@ AdjustFilenames() {
       SourceShim="none"
       TargetShim="none"
       if [[ $EspSourceDir == "/efi/boot" ]] ; then
-         SourceX64="bootx64.efi"
-         SourceIA32="bootia32.efi"
+         Source="boot$Platform.efi"
       elif [[ $EspSourceDir == "/efi/microsoft/boot" ]] ; then
-         SourceX64="bootmgfw.efi"
+         Source="bootmgfw.efi"
       fi
    fi
 
    if [[ $EspTargetDir == "/efi/boot" ]] ; then
       if [[ $TargetShim == "none" ]] ; then
-         TargetX64="bootx64.efi"
-         TargetIA32="bootia32.efi"
+         Target="boot$Platform.efi"
       else
-         TargetShim="bootx64.efi"
+         TargetShim="boot$Platform.efi"
       fi
    elif [[ $EspTargetDir == "/efi/microsoft/boot" ]] ; then
       if [[ $TargetShim == "none" ]] ; then
-         TargetX64="bootmgfw.efi"
+         Target="bootmgfw.efi"
       else
          TargetShim="bootmgfw.efi"
       fi
@@ -117,7 +141,7 @@ AdjustFilenames() {
 # Checks for the presence of necessary files, including both boot loaders
 # and support utilities (efibootmgr, etc.)
 CheckForFiles() {
-   if [[ (! -f $SourceDir/$SourceX64 && ! -f $SourceDir/$SourceIA32) ||
+   if [[ (! -f $SourceDir/$Source) ||
          ($SourceShim != "none" && ! -f $SourceDir/SourceShim) ||
          ! -f $SourceDir/refind.conf ]] ; then
       echo "There doesn't seem to be a rEFInd installation at $SourceDir!"
@@ -166,7 +190,7 @@ MoveFiles() {
    fi
 
    if [[ $EspTargetDir == "/efi/microsoft/boot" && -d $TargetDir ]] ; then
-      mv -n $EspTargetDir/bootmgfw.efi $InstallDir/EFI/Microsoft/
+      mv -n $TargetDir/bootmgfw.efi $InstallDir/EFI/Microsoft/
    fi
 
    mkdir -p $TargetDir
@@ -174,8 +198,7 @@ MoveFiles() {
    mv $SourceDir/icons-backup $TargetDir/ 2> /dev/null
    mv $SourceDir/drivers_* $TargetDir/ 2> /dev/null
    mv $SourceDir/keys $TargetDir 2> /dev/null
-   mv $SourceDir/$SourceX64 $TargetDir/$TargetX64 2> /dev/null
-   mv $SourceDir/$SourceIA32 $TargetDir/$TargetIA32 2> /dev/null
+   mv $SourceDir/$Source $TargetDir/$Target 2> /dev/null
    mv $SourceDir/$SourceShim $TargetDir/$TargetShim 2> /dev/null
    mv $SourceDir/refind.conf* $TargetDir/ 2> /dev/null
    rmdir $SourceDir 2> /dev/null
@@ -201,12 +224,7 @@ AddNvramEntry() {
    if [[ $TargetShim != "none" ]] ; then
       EntryFilename=$EspTargetDir/$TargetShim
    else
-      CpuType=`uname -m`
-      if [[ $CpuType == 'x86_64' ]] ; then
-         EntryFilename=$EspTargetDir/$TargetX64
-      else
-         EntryFilename=$EspTargetDir/$TargetIA32
-      fi
+      EntryFilename=$EspTargetDir/$Target
    fi # if/else
 
    EfiEntryFilename=`echo ${EntryFilename//\//\\\}`
@@ -258,6 +276,7 @@ if [[ `whoami` != "root" ]] ; then
 fi
 
 FindLinuxESP
+DeterminePlatform
 AdjustFilenames
 CheckForFiles
 MoveFiles