-
Notifications
You must be signed in to change notification settings - Fork 21
/
coreapp-chrome-enable-autoupdate.py
162 lines (134 loc) · 5.29 KB
/
coreapp-chrome-enable-autoupdate.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
#!/usr/bin/env python
# encoding: utf-8
"""
-This script configures Google's own 'keystone' update mechanism
-to keep Chrome up to date without a requirement for user interaction.
-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, hjuutilainen@mac.com
-Date: @@DATE
-Version: @@VERSION
-Origin: @@ORIGIN
Released by JSS User: @@USER
"""
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')
if not os.path.exists(installScript):
installScript = os.path.join(keystoneRegistrationFrameworkPath(), 'Resources/install.py')
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())