~rodsmith/refind/master

590 by srs5694
Partial reversion of commit de2b06e, since macOS doesn't implement
1
#!/bin/bash
396 by srs5694
Added summary of Apple System Integrity Protection (SIP) status to
2
#
3
# Mac OS X script to locate and mount an EFI System Partition (ESP)
4
#
5
# Usage:
6
#
7
# ./mountesp
8
#
422 by srs5694
More documentation of copyrights and licenses.
9
# This program is copyright (c) 2015 by Roderick W. Smith
10
#
11
# This program is licensed under the terms of the GNU GPL, version 3,
12
# or (at your option) any later version.
13
# You should have received a copy of the GNU General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
396 by srs5694
Added summary of Apple System Integrity Protection (SIP) status to
15
#
16
# Revision history:
17
#
698 by Rod Smith
Fix mountesp failure on macOS 11 (Big Sur)
18
# 0.13.2  -- Fixed bug that caused failure with macOS 11.0 ("Big Sur")
396 by srs5694
Added summary of Apple System Integrity Protection (SIP) status to
19
# 0.9.3   -- Initial release (with rEFInd 0.9.3)
395 by srs5694
Added new mountesp script to help OS X users mount the ESP.
20
21
# Mount the ESP at /Volumes/ESP or determine its current mount
22
# point.
23
MountOSXESP() {
24
    # Identify the ESP. Note: This returns the FIRST ESP found;
25
    # if the system has multiple disks, this could be wrong!
698 by Rod Smith
Fix mountesp failure on macOS 11 (Big Sur)
26
    Temp=$(mount | sed -n -E "/^(\/dev\/disk.*) on \/ \(.*$/s//\1/p")
723 by Rod Smith
Code cleanup on bash scripts
27
    if [ "$Temp" ]; then
395 by srs5694
Added new mountesp script to help OS X users mount the ESP.
28
        Temp=$(diskutil list | grep " EFI " | grep -o 'disk.*' | head -n 1)
723 by Rod Smith
Code cleanup on bash scripts
29
        if [ -z "$Temp" ]; then
395 by srs5694
Added new mountesp script to help OS X users mount the ESP.
30
            echo "Warning: root device doesn't have an EFI partition"
31
        fi
32
    else
33
        echo "Warning: root device could not be found"
34
    fi
723 by Rod Smith
Code cleanup on bash scripts
35
    if [ -z "$Temp" ]; then
395 by srs5694
Added new mountesp script to help OS X users mount the ESP.
36
        Temp=$(diskutil list | sed -n -E '/^ *[0-9]+:[ ]+EFI EFI[ ]+[0-9.]+ [A-Z]+[ ]+(disk[0-9]+s[0-9]+)$/ { s//\1/p
37
                q
38
            }' )
39
723 by Rod Smith
Code cleanup on bash scripts
40
        if [ -z "$Temp" ]; then
395 by srs5694
Added new mountesp script to help OS X users mount the ESP.
41
            echo "Could not find an EFI partition. Aborting!"
42
            exit 1
43
        fi
44
    fi
723 by Rod Smith
Code cleanup on bash scripts
45
    Esp=/dev/$Temp
396 by srs5694
Added summary of Apple System Integrity Protection (SIP) status to
46
    echo "The ESP has been identified as $Esp; attempting to mount it...."
395 by srs5694
Added new mountesp script to help OS X users mount the ESP.
47
    # If the ESP is mounted, use its current mount point....
723 by Rod Smith
Code cleanup on bash scripts
48
    Temp=$(df -P | grep "$Esp ")
49
    MountPoint=$(echo "$Temp" | cut -f 6- -d ' ')
395 by srs5694
Added new mountesp script to help OS X users mount the ESP.
50
    if [[ "$MountPoint" == '' ]] ; then
396 by srs5694
Added summary of Apple System Integrity Protection (SIP) status to
51
        if [[ $UID != 0 ]] ; then
52
            echo "You must run this program as root or using sudo! Exiting!"
53
            exit 1
54
        fi
395 by srs5694
Added new mountesp script to help OS X users mount the ESP.
55
        MountPoint="/Volumes/ESP"
723 by Rod Smith
Code cleanup on bash scripts
56
        # echo "MountPoint is $MountPoint"
395 by srs5694
Added new mountesp script to help OS X users mount the ESP.
57
        mkdir /Volumes/ESP &> /dev/null
58
        # Some systems have HFS+ "ESPs." They shouldn't, but they do. If this is
59
        # detected, mount it as such and set appropriate options.
723 by Rod Smith
Code cleanup on bash scripts
60
        if  ! mount -t msdos "$Esp" $MountPoint ; then
61
            if ! mount -t hfs "$Esp" $MountPoint ; then
62
                printf "Unable to mount ESP!\n\n"
395 by srs5694
Added new mountesp script to help OS X users mount the ESP.
63
                exit 1
64
            fi
65
        fi
66
    fi
67
    echo "The ESP is mounted at $MountPoint"
68
} # MountOSXESP()
69
70
#
71
# Main part of script....
72
#
73
74
case "$OSTYPE" in
75
    darwin*)
76
            MountOSXESP
77
            ;;
78
    *)
79
            echo "This script is meant to be run under OS X *ONLY*! Exiting!"
80
            exit
81
            ;;
422 by srs5694
More documentation of copyrights and licenses.
82
esac