-
Notifications
You must be signed in to change notification settings - Fork 3
/
GoogleChrome.munki.recipe
211 lines (176 loc) · 6.45 KB
/
GoogleChrome.munki.recipe
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
<?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>Identifier</key>
<string>com.grahamgilbert.munki.GoogleChrome</string>
<key>Input</key>
<dict>
<key>DOWNLOAD_URL</key>
<string>https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg</string>
<key>MUNKI_REPO_SUBDIR</key>
<string>apps/Google/GoogleChrome</string>
<key>NAME</key>
<string>GoogleChrome</string>
<key>pkginfo</key>
<dict>
<key>catalogs</key>
<array>
<string>testing</string>
</array>
<key>description</key>
<string>Chrome is a fast, simple, and secure web browser, built for the modern web.</string>
<key>display_name</key>
<string>Google Chrome</string>
<key>name</key>
<string>%NAME%</string>
<key>unattended_install</key>
<true/>
<key>postinstall_script</key>
<string>#!/usr/bin/env python
# encoding: utf-8
"""
chrome-enable-autoupdates.py
This script enables system wide automatic updates for Google Chrome.
It should work for Chrome versions 18 and later. No configuration needed
as this is originally intended as a munki postinstall script.
Created by Hannes Juutilainen, [email protected]
History:
--------
2014-11-20, Hannes Juutilainen
- Modifications for Chrome 39
2012-08-31, Hannes Juutilainen
- Added --force flag to keystoneInstall as suggested by Riley Shott
2012-05-29, Hannes Juutilainen
- Added more error checking
2012-05-25, Hannes Juutilainen
- Added some error checking in main
2012-05-24, Hannes Juutilainen
- First version
"""
import sys
import os
import getopt
import subprocess
import plistlib
chromePath = "/Applications/Google Chrome.app"
infoPlistPath = os.path.realpath(os.path.join(chromePath, 'Contents/Info.plist'))
brandPath = "/Library/Google/Google Chrome Brand.plist"
brandKey = "KSBrandID"
tagPath = infoPlistPath
tagKey = "KSChannelID"
versionPath = infoPlistPath
versionKey = "KSVersion"
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def chromeIsInstalled():
"""Check if Chrome is installed"""
if os.path.exists(chromePath):
return True
else:
return False
def chromeVersion():
"""Returns Chrome version"""
infoPlist = plistlib.readPlist(infoPlistPath)
bundleShortVersion = infoPlist["CFBundleShortVersionString"]
return bundleShortVersion
def chromeKSUpdateURL():
"""Returns KSUpdateURL from Chrome Info.plist"""
infoPlist = plistlib.readPlist(infoPlistPath)
KSUpdateURL = infoPlist["KSUpdateURL"]
return KSUpdateURL
def chromeKSProductID():
"""Returns KSProductID from Chrome Info.plist"""
infoPlist = plistlib.readPlist(infoPlistPath)
KSProductID = infoPlist["KSProductID"]
return KSProductID
def keystoneRegistrationFrameworkPath():
"""Returns KeystoneRegistration.framework path"""
keystoneRegistration = os.path.join(chromePath, 'Contents/Versions')
keystoneRegistration = os.path.join(keystoneRegistration, chromeVersion())
keystoneRegistration = os.path.join(keystoneRegistration, 'Google Chrome Framework.framework')
keystoneRegistration = os.path.join(keystoneRegistration, 'Frameworks/KeystoneRegistration.framework')
return keystoneRegistration
def keystoneInstall():
"""Install the current Keystone"""
installScript = os.path.join(keystoneRegistrationFrameworkPath(), 'Resources/ksinstall')
keystonePayload = os.path.join(keystoneRegistrationFrameworkPath(), 'Resources/Keystone.tbz')
if os.path.exists(installScript) and os.path.exists(keystonePayload):
retcode = subprocess.call([installScript, '--install', keystonePayload, '--force'])
if retcode == 0:
return True
else:
return False
else:
print >> sys.stderr, "Error: KeystoneRegistration.framework not found"
return False
def removeChromeFromKeystone():
"""Removes Chrome from Keystone"""
ksadmin = "/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/MacOS/ksadmin"
ksadminProcess = [ ksadmin, '--delete', '--productid', chromeKSProductID()]
retcode = subprocess.call(ksadminProcess)
if retcode == 0:
return True
else:
return False
def registerChromeWithKeystone():
"""Registers Chrome with Keystone"""
ksadmin = "/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/MacOS/ksadmin"
if os.path.exists(ksadmin):
ksadminProcess = [ksadmin,
'--register',
'--preserve-tttoken',
'--productid', chromeKSProductID(),
'--version', chromeVersion(),
'--xcpath', chromePath,
'--url', chromeKSUpdateURL(),
'--tag-path', tagPath,
'--tag-key', tagKey,
'--brand-path', brandPath,
'--brand-key', brandKey,
'--version-path', versionPath,
'--version-key', versionKey]
retcode = subprocess.call(ksadminProcess)
if retcode == 0:
return True
else:
return False
else:
print >> sys.stderr, "Error: %s doesn't exist" % ksadmin
return False
def main(argv=None):
if argv is None:
argv = sys.argv
try:
# Check for root
if os.geteuid() != 0:
print >> sys.stderr, "This script must be run as root"
return 1
if not chromeIsInstalled():
print >> sys.stderr, "Error: Chrome is not installed on this computer"
return 1
if keystoneInstall():
print "Keystone installed"
else:
print >> sys.stderr, "Error: Keystone install failed"
return 1
if registerChromeWithKeystone():
print "Registered Chrome with Keystone"
return 0
else:
print >> sys.stderr, "Error: Failed to register Chrome with Keystone"
return 1
except Usage, err:
print >>sys.stderr, err.msg
print >>sys.stderr, "for help use --help"
return 2
if __name__ == "__main__":
sys.exit(main())
</string>
</dict>
</dict>
<key>ParentRecipe</key>
<string>com.github.autopkg.munki.google-chrome</string>
</dict>
</plist>