forked from YesThatAllen/sierra-vm-installer-fix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create Mavericks Installer.tool
314 lines (266 loc) · 8.47 KB
/
Create Mavericks Installer.tool
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/bash
#
# This executable converts a Mavericks .app (which allows to upgrade a machine
# from Mac OS 10.6.7+ to Mavericks) into a Mavericks .vmdk (which allows to
# install Mavericks from scratch in a virtual machine).
#
# It has been tested with the following Mac OS versions
# o 10.9 (starting with Developer Preview 4)
# o 10.10
# o 10.11
# o 10.12 (up to Public Beta 1)
#
# Note: "IA" below does not stand for Intel Architecture, it stands for Install
# Assistant.
#
# Uncomment the following line to get debug output.
#exec >/tmp/debug 2>&1
set -x
set -e
set -E
# The first argument is the path to the .app bundle (the input of the
# executable).
inputApp="$1"
inputAppB="`basename "$inputApp"`"
inputAppU="${inputAppB// /%20}"
# The second argument is the path to the .vmdk file (the output of the
# executable), which must end with ".vmdk".
outputVmdk="$2"
[ "${outputVmdk: -5}" = .vmdk ]
outputDmg="${outputVmdk:0:${#outputVmdk} - 5}".dmg
# createinstallmedia hardcodes the volume name. The installation succeeds
# regardless of the name, so let us just pick something sensible.
volName="`defaults read "$inputApp"/Contents/Info CFBundleDisplayName`"
tmpDir="`mktemp -d -t 'Create Mavericks Installer'`"
outputMnt="$tmpDir"/output
installMnt="$tmpDir"/install
baseMnt="$tmpDir"/base
cleanup() {
local status="$?"
if [ -d "$outputMnt" ]; then
hdiutil detach "$outputMnt"
fi
if [ -d "$baseMnt" ]; then
hdiutil detach "$baseMnt"
fi
if [ -d "$installMnt" ]; then
hdiutil detach "$installMnt"
fi
rm -rf -- "$tmpDir"
if [ "$status" -ne 0 ]; then
rm -f "$outputVmdk" "$outputDmg"
fi
}
# Cleanup on failure.
trap cleanup ERR
# Mount InstallESD.dmg so we can access BaseSystem.dmg inside.
# This fails if the image is already mounted somewhere else.
hdiutil \
attach "$inputApp"/Contents/SharedSupport/InstallESD.dmg \
-mountpoint "$installMnt" \
-nobrowse \
-noverify \
-readonly
# Mount BaseSystem.dmg so we can access files inside.
# This fails if the image is already mounted somewhere else.
if [ -f "$inputApp"/Contents/SharedSupport/BaseSystem.dmg ];
then
hdiutil \
attach "$inputApp"/Contents/SharedSupport/BaseSystem.dmg \
-mountpoint "$baseMnt" \
-nobrowse \
-noverify \
-readonly
else
hdiutil \
attach "$installMnt"/BaseSystem.dmg \
-mountpoint "$baseMnt" \
-nobrowse \
-noverify \
-readonly
fi
#
# Determine the size of the disk image.
#
# Between the initial boot and the first reboot, the Mavericks installer writes
# 16.2 MB to the volume, mostly to replace the
# .IABootFiles/boot.efi
# .IABootFiles/"$prelinkedKernelB"
# .IABootFiles/PlatformSupport.plist
# .IABootFiles/com.apple.Boot.plist
# hard links with actual copies...
#
# So account for that. To err on the side of caution, we further enlarge the
# disk image to keep 30 MB of free space on the volume at the first reboot.
#
addSize() {
# Use a temp file instead of a shell pipe, to detect when "du" fails.
BLOCKSIZE=512 du -s "$2" >"$tmpDir"/pipe
local size="`awk '{ print $1 }' "$tmpDir"/pipe`"
outputDmgSize=$((outputDmgSize + $1 * size))
}
#
# Determine the location of the prelinked kernel (a.k.a. kernelcache).
#
# There are two possible locations for the prelinked kernel. The first
# location is used by newer products. If not found there, fall back to the
# location used by Mac OS versions 10.9 and 10.10.
#
# Newer than Mac OS 10.10:
prelinkedKernel=System/Library/PrelinkedKernels/prelinkedkernel
if [ ! -r "$baseMnt"/"$prelinkedKernel" ]; then
# Mac OS 10.9 or 10.10:
prelinkedKernel=System/Library/Caches/com.apple.kext.caches/Startup/kernelcache
fi
prelinkedKernelB="`basename "$prelinkedKernel"`"
# A new booter System/Library/CoreServices/bootbase.efi was introduced in
# Mac OS 10.11 Public Beta 1. Apple recommends we use it going forward.
booter=System/Library/CoreServices/bootbase.efi
if [ ! -r "$baseMnt"/"$booter" ]; then
booter=System/Library/CoreServices/boot.efi
fi
outputDmgSize=119200
addSize 1 "$inputApp"
for i in \
"$prelinkedKernel" \
System/Library/CoreServices/PlatformSupport.plist \
"$booter" \
; do
addSize 2 "$baseMnt"/"$i"
done
# Create the disk image.
rm -f "$outputDmg"
# Layout: MBRSPUD produces a smaller disk image than SPUD or GPTSPUD.
hdiutil \
create "$outputDmg" \
-sectors "$outputDmgSize" \
-fs HFS+J \
-volname "$volName" \
-layout MBRSPUD
# Mount the disk image.
hdiutil \
attach "$outputDmg" \
-mountpoint "$outputMnt" \
-nobrowse \
-noverify
#
# Copy some files. The majority of the work (copying the installer .app bundle
# itself) takes place later.
#
copy() {
mkdir -p "`dirname "$2"`"
cp -a "$1" "$2"
}
copyRel() {
copy "$baseMnt"/"$1" "$outputMnt"/"$2"
}
copyRel "$prelinkedKernel" \
System/Library/Caches/com.apple.kext.caches/Startup/"$prelinkedKernelB"
copyRel System/Library/CoreServices/PlatformSupport.plist \
System/Library/CoreServices/PlatformSupport.plist
copyRel "$booter" \
System/Library/CoreServices/boot.efi
copyRel System/Library/CoreServices/SystemVersion.plist \
System/Library/CoreServices/SystemVersion.plist
#
# Generate some files.
#
f="$outputMnt"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist
mkdir -p "`dirname "$f"`"
cat <<EOF >"$f"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Kernel Cache</key>
<string>/.IABootFiles/$prelinkedKernelB</string>
<key>Kernel Flags</key>
<string>container-dmg=file:///$inputAppU/Contents/SharedSupport/InstallESD.dmg root-dmg=file:///BaseSystem.dmg</string>
</dict>
</plist>
EOF
f="$outputMnt"/.IAPhysicalMedia
mkdir -p "`dirname "$f"`"
cat <<EOF >"$f"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AppName</key>
<string>$inputAppB</string>
</dict>
</plist>
EOF
#
# Hardlink some files.
#
hardlink() {
mkdir -p "`dirname "$outputMnt"/"$2"`"
# "ln" fails with "Operation not permitted" (even for the super user) if the
# source's uchg (user immutable) flag is set.
local flags=`ls -lO@ "$outputMnt"/"$1" | awk '{ print $5 }'`
if echo "$flags" | grep -q uchg; then
# The uchg flag is set. Temporarily clear it to allow "ln" to succeed.
chflags nouchg "$outputMnt"/"$1"
fi
ln "$outputMnt"/"$1" "$outputMnt"/"$2"
if echo "$flags" | grep -q uchg; then
# The uchg flag was set. Restore it.
chflags uchg "$outputMnt"/"$1"
fi
}
hardlink System/Library/CoreServices/boot.efi \
usr/standalone/i386/boot.efi
hardlink System/Library/CoreServices/boot.efi \
.IABootFiles/boot.efi
hardlink System/Library/Caches/com.apple.kext.caches/Startup/"$prelinkedKernelB" \
.IABootFiles/"$prelinkedKernelB"
hardlink System/Library/CoreServices/PlatformSupport.plist \
.IABootFiles/PlatformSupport.plist
hardlink Library/Preferences/SystemConfiguration/com.apple.Boot.plist \
.IABootFiles/com.apple.Boot.plist
# The target path should probably be .IABootFiles/SystemVersion.plist, but let
# us be bug-compatible with Apple :)
hardlink System/Library/CoreServices/SystemVersion.plist \
.IABootFilesSystemVersion.plist
#
# Copy the bulky installer .app bundle.
# The copy must preserve symbolic links (see bug 1677798).
#
cp -a "$inputApp" "$outputMnt"
# Bless the volume.
/usr/sbin/bless \
-folder "$outputMnt"/.IABootFiles \
-bootefi "$outputMnt"/.IABootFiles/boot.efi \
-options 'config="\.IABootFiles\com.apple.Boot"' \
-label "$volName"
# Delete unnecessary stuff that might have been created by Finder.
if [[ -e "$outputMnt"/.Trashes ]]; then
chmod u+r "$outputMnt"/.Trashes
fi
rm -rf "$outputMnt"/.{DS_Store,Spotlight-V100,Trashes,fseventsd}
# Synchronize "$outputDmg".
hdiutil detach "$outputMnt"
# Create the virtual disk descriptor.
cat <<EOF >"$outputVmdk"
# Disk DescriptorFile
version=1
encoding="UTF-8"
CID=fffffffe
parentCID=ffffffff
isNativeSnapshot="no"
createType="monolithicFlat"
# Extent description
RW $outputDmgSize FLAT "`basename "$outputDmg"`" 0
# The Disk Data Base
#DDB
ddb.adapterType = "lsilogic"
#ddb.geometry.cylinders is not used by Mac OS.
#ddb.geometry.heads is not used by Mac OS.
#ddb.geometry.sectors is not used by Mac OS.
#ddb.longContentID will be generated on the first write to the file.
#ddb.uuid is not used by Mac OS.
ddb.virtualHWVersion = "6"
EOF
# Cleanup on success.
trap ERR; cleanup