-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHelperTool_CodeSign_RunScript.py
More file actions
executable file
·122 lines (85 loc) · 3.41 KB
/
HelperTool_CodeSign_RunScript.py
File metadata and controls
executable file
·122 lines (85 loc) · 3.41 KB
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
#!/usr/bin/python
""" Place this script at the root of the project directory
and enter this for a Run Script during build phase
${PROJECT_DIR}"/HelperTool_CodeSign_RunScript.py"
put the runscript right after Target Dependencies
"""
import os
import subprocess
import plistlib
helper_info = 'printer-installer-helper/helper-Info.plist'
helper_launchd = 'printer-installer-helper/helper-Launchd.plist'
"""
the name for the helper tool will be default to this format com.your.app.helper
which is the main apps bundleID with a .helper extension.
if the executable you're insatlling is something other than that specify it here
"""
helper_name_override = '';
tmp_filename = 'code_sign_tmp_file'
def getCodeSignIdent(build_dir):
identity = os.getenv('CODE_SIGN_IDENTITY')
checkVar(identity)
file = os.path.join(build_dir,tmp_filename)
open(file, 'w').close()
result = subprocess.check_output(['codesign','--force','--sign',identity,file])
result = subprocess.check_output(['codesign','-d','-r', '-',file])
cid = result.split("=> ")[1]
cid = cid.rstrip(os.linesep)
os.remove(file)
return cid
def editAppInfoPlist(cert_id,app_name):
app_info_plist = os.getenv('PRODUCT_SETTINGS_PATH')
checkVar(app_info_plist)
try:
p = plistlib.readPlist(app_info_plist)
bundle_id = p['CFBundleIdentifier'].split("$")[0]
if not helper_name_override:
helper_id = ''.join([bundle_id, app_name,'.helper'])
else:
helper_id = helper_name_override
csstring = cert_id.replace(tmp_filename,helper_id)
p['SMPrivilegedExecutables'] = {helper_id:csstring}
except:
print "There is No Info.plist for them main app, somethings really wrong"
exit(1)
plistlib.writePlist(p,app_info_plist)
return bundle_id, helper_id
def editHelperInfoPlist(cert_id,project_path,bundle_id,app_name):
helper_info_plist = os.path.join(project_path,helper_info)
checkVar(helper_info_plist)
app_id = ''.join([bundle_id,app_name])
csstring = cert_id.replace(tmp_filename,app_id)
try:
p = plistlib.readPlist(helper_info_plist)
p['SMAuthorizedClients'] = [csstring]
except:
print "There is No Info.plist for helper tool, somethings really wrong"
exit(1)
plistlib.writePlist(p,helper_info_plist)
def editHelperLaunchD(project_path,helper_id):
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
build_dir = os.getenv('BUILT_PRODUCTS_DIR')
project_path = os.getenv('PROJECT_DIR')
app_name = os.getenv('PRODUCT_NAME')
# Get the existing cert values
cs_ident = getCodeSignIdent(build_dir)
# write out to the helper tool
bundle_id,helper_id = editAppInfoPlist(cs_ident,app_name)
editHelperInfoPlist(cs_ident,project_path,bundle_id,app_name)
editHelperLaunchD(project_path,helper_id)
if __name__ == "__main__":
main()