-
Notifications
You must be signed in to change notification settings - Fork 28
/
createRecovery.sh
63 lines (55 loc) · 2.56 KB
/
createRecovery.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
######################################
#
# Create Recovery script
#
# Usage: ./createRecovery.sh
#
# Created by Amsys
#
# Use at your own risk. Amsys will accept
# no responsibility for loss or damage
# caused by this script.
#
# The script will perform the following tasks:
#
# 1. Set the macOS installer path as a variable
# 2. Set the target disk as a variable
# 3. Download the RecoveryHDUpdate.dmg into /private/tmp
# 4. Open the disk image
# 5. Expand the enclosed "RecoveryHDUpdate.pkg" package
# 6. Eject the disk image
# 7. Create or modify the Recovery partition
#
######################################
# Set the macOS installer path as a variable
MACOS_INSTALLER="/Applications/$(ls /Applications | grep "Install macOS")" # Path to your macOS installer
echo "macOS installer is $MACOS_INSTALLER"
# Set the target disk as a variable
TARGET=$(diskutil info "$(bless --info --getBoot)" | awk -F':' '/Volume Name/ { print $2 }' | sed -e 's/^[[:space:]]*//')
echo "Target disk is $TARGET"
# Download the RecoveryHDUpdate.dmg into /private/tmp
curl http://support.apple.com/downloads/DL1464/en_US/RecoveryHDUpdate.dmg -L -o /private/tmp/RecoveryHDUpdate.dmg
echo "Downloaded RecoveryHDUpdate.dmg into /private/tmp"
# Open the disk image
hdiutil attach /private/tmp/RecoveryHDUpdate.dmg
# Expand the enclosed "RecoveryHDUpdate.pkg" package
pkgutil --expand /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update/RecoveryHDUpdate.pkg /private/tmp/recoveryupdate
echo "RecoveryHDUpdate.pkg expanded into /private/tmp/recoveryupdate"
# Eject the disk image
hdiutil eject "/Volumes/Mac OS X Lion Recovery HD Update"
if [ "$MACOS_INSTALLER" = "/Applications/Install macOS High Sierra.app" ]; then
# Create or modify the Recovery partition (10.13)
echo "Installer is macOS High Sierra"
/private/tmp/recoveryupdate/RecoveryHDUpdate.pkg/Scripts/Tools/dmtest ensureRecoveryPartition "$TARGET" "$MACOS_INSTALLER/Contents/SharedSupport/BaseSystem.dmg" 0 0 "$MACOS_INSTALLER/Contents/SharedSupport/BaseSystem.chunklist"
echo "Finished creating High Sierra Recovery HD"
else
if [ "$MACOS_INSTALLER" = "/Applications/Install macOS Sierra.app" ]; then
# Create or modify the Recovery partition (10.12)
echo "Installer is macOS Sierra"
hdiutil mount "$MACOS_INSTALLER/Contents/SharedSupport/InstallESD.dmg"
/private/tmp/recoveryupdate/RecoveryHDUpdate.pkg/Scripts/Tools/dmtest ensureRecoveryPartition "$TARGET" "/Volumes/OS X Install ESD/BaseSystem.dmg" 0 0 "/Volumes/OS X Install ESD/BaseSystem.chunklist"
hdiutil eject "/Volumes/OS X Install ESD"
echo "Finished creating Sierra Recovery HD"
fi
fi