-
Notifications
You must be signed in to change notification settings - Fork 36
/
CodeSignUpdate.sh
executable file
·138 lines (112 loc) · 4.1 KB
/
CodeSignUpdate.sh
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
#!/bin/bash
# CodeSignUpdate.sh
# SwiftPrivilegedHelperApplication
#
# Created by Erik Berglund.
# Copyright © 2018 Erik Berglund. All rights reserved.
set -e
###
### CUSTOM VARIABLES
###
bundleIdentifierApplication="com.github.erikberglund.SwiftPrivilegedHelperApplication"
bundleIdentifierHelper="com.github.erikberglund.SwiftPrivilegedHelper"
###
### STATIC VARIABLES
###
infoPlist="${INFOPLIST_FILE}"
if [[ $( /usr/libexec/PlistBuddy -c "Print NSPrincipalClass" "${infoPlist}" 2>/dev/null ) == "NSApplication" ]]; then
target="application"
else
target="helper"
fi
oidAppleDeveloperIDCA="1.2.840.113635.100.6.2.6"
oidAppleDeveloperIDApplication="1.2.840.113635.100.6.1.13"
oidAppleMacAppStoreApplication="1.2.840.113635.100.6.1.9"
oidAppleWWDRIntermediate="1.2.840.113635.100.6.2.1"
###
### FUNCTIONS
###
function appleGeneric {
printf "%s" "anchor apple generic"
}
function appleDeveloperID {
printf "%s" "certificate leaf[field.${oidAppleMacAppStoreApplication}] /* exists */ or certificate 1[field.${oidAppleDeveloperIDCA}] /* exists */ and certificate leaf[field.${oidAppleDeveloperIDApplication}] /* exists */"
}
function appleMacDeveloper {
printf "%s" "certificate 1[field.${oidAppleWWDRIntermediate}]"
}
function identifierApplication {
printf "%s" "identifier \"${bundleIdentifierApplication}\""
}
function identifierHelper {
printf "%s" "identifier \"${bundleIdentifierHelper}\""
}
function developerID {
developmentTeamIdentifier="${DEVELOPMENT_TEAM}"
if ! [[ ${developmentTeamIdentifier} =~ ^[A-Z0-9]{10}$ ]]; then
printf "%s\n" "Invalid Development Team Identifier: ${developmentTeamIdentifier}"
exit 1
fi
printf "%s" "certificate leaf[subject.OU] = ${developmentTeamIdentifier}"
}
function macDeveloper {
macDeveloperCN="${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
if ! [[ ${macDeveloperCN} =~ ^Mac\ Developer:\ .*\ \([A-Z0-9]{10}\)$ ]]; then
printf "%s\n" "Invalid Mac Developer CN: ${macDeveloperCN}"
exit 1
fi
printf "%s" "certificate leaf[subject.CN] = \"${macDeveloperCN}\""
}
function updateSMPrivilegedExecutables {
/usr/libexec/PlistBuddy -c 'Delete SMPrivilegedExecutables' "${infoPlist}"
/usr/libexec/PlistBuddy -c 'Add SMPrivilegedExecutables dict' "${infoPlist}"
/usr/libexec/PlistBuddy -c 'Add SMPrivilegedExecutables:'"${bundleIdentifierHelper}"' string '"$( sed -E 's/\"/\\\"/g' <<< ${1})"'' "${infoPlist}"
}
function updateSMAuthorizedClients {
/usr/libexec/PlistBuddy -c 'Delete SMAuthorizedClients' "${infoPlist}"
/usr/libexec/PlistBuddy -c 'Add SMAuthorizedClients array' "${infoPlist}"
/usr/libexec/PlistBuddy -c 'Add SMAuthorizedClients: string '"$( sed -E 's/\"/\\\"/g' <<< ${1})"'' "${infoPlist}"
}
###
### MAIN SCRIPT
###
case "${ACTION}" in
"build")
appString=$( identifierApplication )
appString="${appString} and $( appleGeneric )"
appString="${appString} and $( macDeveloper )"
appString="${appString} and $( appleMacDeveloper )"
appString="${appString} /* exists */"
helperString=$( identifierHelper )
helperString="${helperString} and $( appleGeneric )"
helperString="${helperString} and $( macDeveloper )"
helperString="${helperString} and $( appleMacDeveloper )"
helperString="${helperString} /* exists */"
;;
"install")
appString=$( appleGeneric )
appString="${appString} and $( identifierApplication )"
appString="${appString} and ($( appleDeveloperID )"
appString="${appString} and $( developerID ))"
helperString=$( appleGeneric )
helperString="${helperString} and $( identifierHelper )"
helperString="${helperString} and ($( appleDeveloperID )"
helperString="${helperString} and $( developerID ))"
;;
*)
printf "%s\n" "Unknown Xcode Action: ${ACTION}"
exit 1
;;
esac
case "${target}" in
"helper")
updateSMAuthorizedClients "${appString}"
;;
"application")
updateSMPrivilegedExecutables "${helperString}"
;;
*)
printf "%s\n" "Unknown Target: ${target}"
exit 1
;;
esac