-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPatchUSB.sh
executable file
·289 lines (218 loc) · 8.63 KB
/
PatchUSB.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/bin/bash
#
# PatchUSB.sh
# Mini Monterey
#
# Created by Ben Sova on 6/9/21.
#
# Credit to some of the great people that
# are working to make macOS run smoothly
# on unsupported Macs
#
## MARK: Fun stuff
[ $UID = 0 ] || exec sudo "$0" "$@"
error() {
echo
echo "$1" 1>&2
exit 1
}
echo "Welcome to Mini Monterey's PatchUSB.sh!"
echo 'This script is in alpha stages right now, but more will come in the future.'
echo
# MARK: Detect USB and Payloads
echo 'Detecting Installer USB at /Volumes/Install macOS 12 Beta...'
if [[ -d '/Volumes/Install macOS 12 Beta/Install macOS 12 Beta.app' ]]; then
INSTALLER='/Volumes/Install macOS 12 Beta'
APPPATH="$INSTALLER/Install macOS 12 Beta.app"
else
echo 'Installer USB was not detected.'
echo 'Please be sure to not rename the USB'
error 'Error 2x1: Installer Not Found'
fi
echo 'Installer USB Detected!'
echo
echo 'Detecting patches at script directory...'
PATCHES="$(dirname $0)"
if [[ ! -d "$PATCHES/InstallerPatches" ]]; then
echo 'The patches for Mini Monterey could not be found.'
echo "Theres really no logical explaination for this..."
error "Error 2x1 The Patches Weren't Found"
fi
echo
# MARK: Verifying thing
if [[ ! "$1" == "--no-setvars" ]]; then
MOUNTEDPARTITION=`mount | fgrep "$INSTALLER" | awk '{print $1}'`
if [[ -z "$MOUNTEDPARTITION" ]]; then
echo Failed to find the partition that
echo "$INSTALLER"
echo is mounted from.
exit 1
fi
DEVICE=`echo -n $MOUNTEDPARTITION | sed -e 's/s[0-9]*$//'`
PARTITION=`echo -n $MOUNTEDPARTITION | sed -e 's/^.*disk[0-9]*s//'`
echo "$INSTALLER found on device $MOUNTEDPARTITION"
if [[ "x$PARTITION" = "x1" ]]; then
error 'This drive is not formatted with a GUID Partition Map'
fi
fi
# MARK: Patch Boot PLIST
echo 'Patching Boot PLIST...'
# Apparently running CP then CAT is better than MV
# but I guess there is some sort of permissions trick
# that makes this better.
if [[ ! -e "$INSTALLER/Library/Preferences/SystemConfiguration/com.apple.Boot.plist.stock" ]]; then
cp "$INSTALLER/Library/Preferences/SystemConfiguration/com.apple.Boot.plist" "$INSTALLER/Library/Preferences/SystemConfiguration/com.apple.Boot.plist.stock" || error 'Error 2x2 Unable backup boot plist.'
fi
cat "$PATCHES/InstallerPatches/com.apple.Boot.plist" > "$INSTALLER/Library/Preferences/SystemConfiguration/com.apple.Boot.plist" || error 'Error 2x2 Unable replace boot plist.'
echo 'Patched Boot PLIST'
echo
# MARK: Adding Kexts to Installer USB
echo 'Add Patches.'
cp -rf "$PATCHES/KextPatches" "$INSTALLER" || error 'Error 2x2 Unable to add patched kexts to installer.'
cp -rf "$PATCHES/SystemPatches" "$INSTALLER" || error 'Error 2x2 Unable to add system patches to installer.'
echo 'Added Patches.'
echo
# MARK: Add BarryKN Hax Tool
echo 'Adding Installer Override...'
rm -rf "$INSTALLER/InstallerHax" > /dev/null
mkdir "$INSTALLER/InstallerHax" || error 'Error 2x2 Somehow unable to make Installer Override folder.'
cp -rf "$PATCHES/InstallerHax/Hax3-BarryKN/HaxDoNotSeal.dylib" "$INSTALLER/InstallerHax/NoSeal.dylib" || error 'Error 2x2 Unable to add Installer Override to the USB.'
cp -rf "$PATCHES/InstallerHax/Hax3-BarryKN/HaxSeal.dylib" "$INSTALLER/InstallerHax/YesSeal.dylib" || error 'Error 2x2 Unable to add BarryKN Hax to the USB.'
cp -rf "$PATCHES/InstallerHax/Hax3-BarryKN/HaxSealNoAPFSROMCheck.dylib" "$INSTALLER/InstallerHax/YesSealNoAPFS.dylib" || error 'Error 2x2 Unable to add BarryKN Hax to the USB.'
cp -rf "$PATCHES/InstallerHax/Hax3-BarryKN/HaxDoNotSealNoAPFSROMCheck.dylib" "$INSTALLER/InstallerHax/NoSealNoAPFS.dylib" || error 'Error 2x2 Unable to add BarryKN Hax to the USB.'
echo 'Added BarryKN Hax.'
echo
# MARK: Add Backup Scripts
#echo "PatchKexts.sh cannot be added yet."
# echo 'Adding Backup Scripts...'
echo 'Adding PatchSystem.sh...'
cp -f "$PATCHES/PatchSystem.sh" "$INSTALLER" || error 'Error 2x2 Unable to add PatchSystem.sh'
cp -a $PATCHES/Scripts "$INSTALLER/Scripts" || error 'Error 2x2 Unable to add extra commands.'
#echo 'Added extra commands...'
# echo 'Added Backup Scripts'
echo
# MARK: Setup Trampoline App
echo 'Setting up trampoline app...'
TEMPAPP="$INSTALLER/tmp.app"
mv -f "$APPPATH" "$TEMPAPP"
cp -r "$PATCHES/InstallerPatches/trampoline.app" "$APPPATH"
mv -f "$TEMPAPP" "$APPPATH/Contents/MacOS/InstallAssistant.app"
cp "$APPPATH/Contents/MacOS/InstallAssistant" "$APPPATH/Contents/MacOS/InstallAssistant_plain"
cp "$APPPATH/Contents/MacOS/InstallAssistant" "$APPPATH/Contents/MacOS/InstallAssistant_springboard"
pushd "$APPPATH/Contents" > /dev/null
for item in `cd MacOS/InstallAssistant.app/Contents;ls -1 | fgrep -v MacOS`
do
ln -s MacOS/InstallAssistant.app/Contents/$item .
done
popd > /dev/null
touch "$APPPATH"
echo 'Setup trampoline app.'
echo
# MARK: Confirm Permissions
echo 'Confirming script permissions...'
chmod -R u+x "$INSTALLER"/InstallerHax/*.dylib
echo 'Confirmed permissions...'
echo
# MARK: The Extra Things
echo 'Theming the installer icon...'
cp -rf $PATCHES/Images/InstallIcon.icns "$INSTALLER"/.VolumeIcon.icns
echo 'Themed (or at least tried to) the installer icon'
echo
# MARK: Sync and Finish
echo 'Finishing drive processes...'
sync
echo
echo 'Finished Patching USB!'
echo 'Now installing SetVars tool...'
# MARK: - Install SetVars
# This code is from the micropatcher.
if [[ ! "$1" == "--no-setvars" ]]; then
checkDirAccess() {
# List the two directories, but direct both stdout and stderr to
# /dev/null. We are only interested in the return code.
ls "$INSTALLER" . &> /dev/null
}
# Make sure there isn't already an "EFI" volume mounted.
if [ -d "/Volumes/EFI" ]
then
echo 'An "EFI" volume is already mounted. Please unmount it then try again.'
echo "If you don't know what this means, then restart your Mac and try again."
echo
error 'EFI Volume already mounted.'
fi
cd $PATCHES
# Check again in case we changed directory after the first check
if [ ! -d EFISetvars ]
then
error '"EFISetvars" folder was not founnd'
fi
# Check to make sure we can access both our own directory and the root
# directory of the USB stick.
if [ `uname -r | sed -e 's@\..*@@'` -ge 19 ]
then
echo 'Checking read access to necessary directories...'
if ! checkDirAccess
then
echo 'Access check failed.'
tccutil reset All com.apple.Terminal
echo 'Retrying access check...'
if ! checkDirAccess
then
echo
error 'Error 2x9 Terminal does not have the correct permissions, please give it Full Disk Access.'
else
echo 'Access check succeeded on second attempt.'
echo
fi
else
echo 'Access check succeeded.'
echo
fi
fi
diskutil mount ${DEVICE}s1
if [[ ! -d "/Volumes/EFI" ]]; then
echo "Partition 1 of the USB stick does not appear to be an EFI partition, or"
echo "mounting of the partition somehow failed."
error 'Error 2x2 Could not find (or mount?) the EFI partition of this device.'
fi
MACMODEL=`sysctl -n hw.model`
echo "Detected Mac model is:" $MACMODEL
case $MACMODEL in
iMac1[45],?|MacBookPro11,?|MacBookAir6,?|MacBook8,?)
echo "Mid 2013 or Later Mac detected, so enabling SIP/ARV."
SIPARV="YES"
;;
*)
echo "Early 2013 or Earily Mac detected, so disabling SIP/ARV."
SIPARV="NO"
;;
esac
# Now do the actual installation
echo "Installing setvars EFI utility."
rm -rf /Volumes/EFI/EFI
if [ "x$VERBOSEBOOT" = "xYES" ]
then
if [ "x$SIPARV" = "xYES" ]
then
echo 'Verbose boot enabled, SIP/ARV enabled'
# cp -r EFISetvars/EFI-enablesiparv-vb /Volumes/EFI/EFI
else
# echo 'Verbose boot enabled, SIP/ARV disabled'
cp -r EFISetvars/EFI-verboseboot /Volumes/EFI/EFI
fi
elif [ "x$SIPARV" = "xYES" ]
then
# echo 'Verbose boot disabled, SIP/ARV enabled'
cp -r EFISetvars/EFI-enablesiparv /Volumes/EFI/EFI
else
# echo 'Verbose boot disabled, SIP/ARV disabled'
cp -r EFISetvars/EFI /Volumes/EFI/EFI
fi
echo 'Adding icons...'
cp -rf $PATCHES/Images/EFIIcon.icns /Volumes/EFI/.VolumeIcon.icns
echo "Unmounting EFI volume if we can..."
umount /Volumes/EFI || diskutil unmount /Volumes/EFI
fi
echo
echo 'Mini Monterey PatchUSB.sh has finished. Refer to the README for instruction on how to continue.'
[[ ! "$SIPARV" == "YES" ]] || echo "Note: This USB should only be used on Mid 2013 and later Macs."