-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathHelperTool_CodeSign_RunScript.py
87 lines (65 loc) · 2.35 KB
/
HelperTool_CodeSign_RunScript.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
#!/usr/bin/python
import os
import subprocess
import plistlib
##### begin editing
app_id = "com.app-name.blerg"
helper_id ="com.app-name.blerg.helper"
helper_info = 'helper/helper-Info.plist'
helper_launchd = 'helper/helper-Launchd.plist'
##### end editing
def getCodeSignIdentity():
build_dir = os.getenv('BUILT_PRODUCTS_DIR')
identity = os.getenv('CODE_SIGN_IDENTITY')
dummy_file = 'csdummypath'
file = os.path.join(build_dir,dummy_file)
open(file, 'w').close()
result_check = subprocess.check_output(['codesign','--force','--sign',identity,file])
result = subprocess.check_output(['codesign','-d','-r', '-',file])
cid = result.split(dummy_file)[1]
checkVar(cid)
return cid
def editAppInfoPlist(cert_id):
app_info_plist = os.getenv('PRODUCT_SETTINGS_PATH')
checkVar(app_info_plist)
csstring = "identifier \"%s\"%s" % (helper_id, cert_id)
try:
p = plistlib.readPlist(app_info_plist)
p['SMPrivilegedExecutables'] = {helper_id:csstring}
except:
p = {'SMPrivilegedExecutables':{helper_id:csstring}}
plistlib.writePlist(p,app_info_plist)
def editHelperInfoPlist(cert_id,project_path):
helper_info_plist = os.path.join(project_path,helper_info)
checkVar(helper_info_plist)
csstring = "identifier \"%s\"%s" % (app_id, cert_id)
try:
p = plistlib.readPlist(helper_info_plist)
p['SMAuthorizedClients'] = {app_id:csstring}
except:
p = {'SMAuthorizedClients':{app_id:csstring}}
plistlib.writePlist(p,helper_info_plist)
def editHelperLaunchD(project_path):
helper_launchd_plist = os.path.join(project_path,helper_launchd)
checkVar(helper_launchd_plist)
try:
p = plistlib.readPlist(helper_launchd_plist)
p['Label'] = helper_id
p['MachServices'] = {helper_id:True}
except:
p = {'Label':helper_id,
'MachServices':{helper_id:True}}
plistlib.writePlist(p,helper_launchd_plist)
def checkVar(var):
if var == "" or var == None:
exit(1)
def main():
### Configure info from environment
project_path = os.getenv('PROJECT_DIR')
cert_id = getCodeSignIdentity()
### write out to the helper tool
editAppInfoPlist(cert_id)
editHelperInfoPlist(cert_id,project_path)
editHelperLaunchD(project_path)
if __name__ == "__main__":
main()