-
Notifications
You must be signed in to change notification settings - Fork 81
/
check-10.11-elcapitan-compatibility.py
executable file
·308 lines (272 loc) · 9.51 KB
/
check-10.11-elcapitan-compatibility.py
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
#!/usr/bin/env python
# encoding: utf-8
# ================================================================================
# check-elcapitan-compatibility.py
#
# This script checks if the current system is compatible with OS X 10.11 El Capitan.
# These checks are based on the installCheckScript and volCheckScript in
# /Applications/Install OS X El Capitan.app/Contents/SharedSupport/OSInstall.mpkg/Distribution
#
# The checks used in this script are:
# - Machine has a specific supported board-id or is a virtual machine
# - 64 bit capable CPU
# - At least 2 GB of memory
# - Current system version is less than 10.11
# - Current system version is at least 10.6.8 or newer
#
# Exit codes:
# 0 = El Capitan is supported
# 1 = El Capitan is not supported
#
#
# Hannes Juutilainen <[email protected]>
# https://github.com/hjuutilainen/adminscripts
#
# ================================================================================
import sys
import subprocess
import os
import re
import plistlib
from distutils.version import StrictVersion
from Foundation import CFPreferencesCopyAppValue
# ================================================================================
# Start configuration
# ================================================================================
# Set this to False if you don't want any output, just the exit codes
verbose = True
# Set this to True if you want to add "elcapitan_supported" custom conditional to
# /Library/Managed Installs/ConditionalItems.plist
update_munki_conditional_items = False
# ================================================================================
# End configuration
# ================================================================================
def logger(message, status, info):
if verbose:
print "%14s: %-40s [%s]" % (message, status, info)
pass
def conditional_items_path():
# <http://code.google.com/p/munki/wiki/ConditionalItems>
# Read the location of the ManagedInstallDir from ManagedInstall.plist
bundle_id = 'ManagedInstalls'
pref_name = 'ManagedInstallDir'
managed_installs_dir = CFPreferencesCopyAppValue(pref_name, bundle_id)
# Make sure we're outputting our information to "ConditionalItems.plist"
if managed_installs_dir:
return os.path.join(managed_installs_dir, 'ConditionalItems.plist')
else:
# Munki default
return "/Library/Managed Installs/ConditionalItems.plist"
def munki_installed():
cmd = ["pkgutil", "--pkg-info", "com.googlecode.munki.core"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = p.communicate()[0]
if p.returncode == 0:
return True
else:
return False
def is_system_version_supported():
system_version_plist = plistlib.readPlist("/System/Library/CoreServices/SystemVersion.plist")
product_name = system_version_plist['ProductName']
product_version = system_version_plist['ProductVersion']
if StrictVersion(product_version) >= StrictVersion('10.11'):
logger("System",
"%s %s" % (product_name, product_version),
"Failed")
return False
elif StrictVersion(product_version) >= StrictVersion('10.6.8'):
logger("System",
"%s %s" % (product_name, product_version),
"OK")
return True
else:
logger("System",
"%s %s" % (product_name, product_version),
"Failed")
return False
def get_board_id():
cmd = ["/usr/sbin/ioreg",
"-p", "IODeviceTree",
"-r",
"-n", "/",
"-d", "1"]
p1 = subprocess.Popen(cmd, bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p2 = subprocess.Popen(["/usr/bin/grep", "board-id"], stdin=p1.stdout, stdout=subprocess.PIPE)
(results, err) = p2.communicate()
board_id = re.sub(r"^\s*\"board-id\" = <\"(.*)\">$", r"\1", results)
board_id = board_id.strip()
if board_id.startswith('Mac'):
return board_id
else:
return None
def is_64bit_capable():
cmd = ["/usr/sbin/sysctl", "-n", "hw.cpu64bit_capable"]
p = subprocess.Popen(cmd, bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(results, err) = p.communicate()
if bool(results):
logger("CPU",
"64 bit capable",
"OK")
return True
else:
logger("CPU",
"not 64 bit capable",
"Failed")
return False
def has_required_amount_of_memory():
minimum_memory = int(2048 * 1024 * 1024)
cmd = ["/usr/sbin/sysctl", "-n", "hw.memsize"]
p = subprocess.Popen(cmd, bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(results, err) = p.communicate()
actual_memory = int(results)
actual_memory_gigabytes = actual_memory / 1024 / 1024 / 1024
if actual_memory >= minimum_memory:
logger("Memory",
"%i GB physical memory installed" % actual_memory_gigabytes,
"OK")
return True
else:
logger("Memory",
"%i GB installed, 2 GB required" % actual_memory_gigabytes,
"Failed")
return False
def is_virtual_machine():
cmd = ["/usr/sbin/sysctl", "-n", "machdep.cpu.features"]
p = subprocess.Popen(cmd, bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(results, err) = p.communicate()
for feature in results.split():
if feature == "VMM":
logger("Board ID",
"Virtual machine",
"OK")
return True
return False
def is_supported_board_id():
if is_virtual_machine():
return True
platform_support_values = [
"Mac-00BE6ED71E35EB86",
"Mac-031AEE4D24BFF0B1",
"Mac-031B6874CF7F642A",
"Mac-06F11F11946D27C5",
"Mac-06F11FD93F0323C5",
"Mac-189A3D4F975D5FFC",
"Mac-27ADBB7B4CEE8E61",
"Mac-2BD1B31983FE1663",
"Mac-2E6FAB96566FE58C",
"Mac-35C1E88140C3E6CF",
"Mac-35C5E08120C7EEAF",
"Mac-3CBD00234E554E41",
"Mac-42FD25EABCABB274",
"Mac-4B7AC7E43945597E",
"Mac-4BC72D62AD45599E",
"Mac-50619A408DB004DA",
"Mac-66F35F19FE2A0D05",
"Mac-6F01561E16C75D06",
"Mac-742912EFDBEE19B3",
"Mac-77EB7D7DAF985301",
"Mac-7BA5B2794B2CDB12",
"Mac-7DF21CB3ED6977E5",
"Mac-7DF2A3B5E5D671ED",
"Mac-81E3E92DD6088272",
"Mac-8ED6AF5B48C039E1",
"Mac-937CB26E2E02BB01",
"Mac-942452F5819B1C1B",
"Mac-942459F5819B171B",
"Mac-94245A3940C91C80",
"Mac-94245B3640C91C81",
"Mac-942B59F58194171B",
"Mac-942B5BF58194151B",
"Mac-942C5DF58193131B",
"Mac-9F18E312C5C2BF0B",
"Mac-AFD8A9D944EA4843",
"Mac-BE0E8AC46FE800CC",
"Mac-C08A6BB70A942AC2",
"Mac-C3EC7CD22292981F",
"Mac-E43C1C25D4880AD6",
"Mac-F2208EC8",
"Mac-F2218EA9",
"Mac-F2218EC8",
"Mac-F2218FA9",
"Mac-F2218FC8",
"Mac-F221BEC8",
"Mac-F221DCC8",
"Mac-F222BEC8",
"Mac-F2238AC8",
"Mac-F2238BAE",
"Mac-F223BEC8",
"Mac-F22586C8",
"Mac-F22587A1",
"Mac-F22587C8",
"Mac-F22589C8",
"Mac-F2268AC8",
"Mac-F2268CC8",
"Mac-F2268DAE",
"Mac-F2268DC8",
"Mac-F2268EC8",
"Mac-F226BEC8",
"Mac-F22788AA",
"Mac-F227BEC8",
"Mac-F22C86C8",
"Mac-F22C89C8",
"Mac-F22C8AC8",
"Mac-F305150B0C7DEEEF",
"Mac-F42386C8",
"Mac-F42388C8",
"Mac-F4238BC8",
"Mac-F4238CC8",
"Mac-F42C86C8",
"Mac-F42C88C8",
"Mac-F42C89C8",
"Mac-F42D86A9",
"Mac-F42D86C8",
"Mac-F42D88C8",
"Mac-F42D89A9",
"Mac-F42D89C8",
"Mac-F60DEB81FF30ACF6",
"Mac-F65AE981FFA204ED",
"Mac-FA842E06C61E91C5",
"Mac-FC02E91DDD3FA6A4"]
board_id = get_board_id()
if board_id in platform_support_values:
logger("Board ID",
board_id,
"OK")
return True
else:
logger("Board ID",
"\"%s\" is not supported" % board_id,
"Failed")
return False
def append_conditional_items(dictionary):
current_conditional_items_path = conditional_items_path()
if os.path.exists(current_conditional_items_path):
existing_dict = plistlib.readPlist(current_conditional_items_path)
output_dict = dict(existing_dict.items() + dictionary.items())
else:
output_dict = dictionary
plistlib.writePlist(output_dict, current_conditional_items_path)
pass
def main(argv=None):
elcapitan_supported_dict = {}
elcapitan_needs_fw_update_dict = {}
# Run the checks
board_id_passed = is_supported_board_id()
memory_passed = has_required_amount_of_memory()
cpu_passed = is_64bit_capable()
system_version_passed = is_system_version_supported()
if board_id_passed and memory_passed and cpu_passed and system_version_passed:
elcapitan_supported = 0
elcapitan_supported_dict = {'elcapitan_supported': True}
else:
elcapitan_supported = 1
elcapitan_supported_dict = {'elcapitan_supported': False}
# Update "ConditionalItems.plist" if munki is installed
if munki_installed() and update_munki_conditional_items:
append_conditional_items(elcapitan_supported_dict)
# Exit codes:
# 0 = El Capitan is supported
# 1 = El Capitan is not supported
return elcapitan_supported
if __name__ == '__main__':
sys.exit(main())