-
Notifications
You must be signed in to change notification settings - Fork 191
/
build_nudge.zsh
executable file
·322 lines (288 loc) · 13.1 KB
/
build_nudge.zsh
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/bin/zsh
#
# Build script for Nudge
check_exit_code() {
if [ "$1" != "0" ]; then
echo "$2: $1" 1>&2
exit 1
fi
}
# Variables
XCODE_PATH="/Applications/Xcode_15.4.app"
APP_SIGNING_IDENTITY="Developer ID Application: Mac Admins Open Source (T4SK8ZXCXG)"
INSTALLER_SIGNING_IDENTITY="Developer ID Installer: Mac Admins Open Source (T4SK8ZXCXG)"
MP_SHA="71c57fcfdf43692adcd41fa7305be08f66bae3e5"
MP_BINDIR="/tmp/munki-pkg"
CONSOLEUSER=$(/usr/bin/stat -f "%Su" /dev/console)
TOOLSDIR=$(dirname $0)
BUILDSDIR="$TOOLSDIR/build"
OUTPUTSDIR="$TOOLSDIR/outputs"
MP_ZIP="/tmp/munki-pkg.zip"
XCODE_BUILD_PATH="$XCODE_PATH/Contents/Developer/usr/bin/xcodebuild"
XCODE_NOTARY_PATH="$XCODE_PATH/Contents/Developer/usr/bin/notarytool"
XCODE_STAPLER_PATH="$XCODE_PATH/Contents/Developer/usr/bin/stapler"
CURRENT_NUDGE_MAIN_BUILD_VERSION=$(/usr/libexec/PlistBuddy -c Print:CFBundleVersion $TOOLSDIR/Nudge/Info.plist)
NEWSUBBUILD=$((80620 + $(git rev-parse HEAD~0 | xargs -I{} git rev-list --count {})))
# automate the build version bump
AUTOMATED_NUDGE_BUILD="$CURRENT_NUDGE_MAIN_BUILD_VERSION.$NEWSUBBUILD"
/usr/bin/xcrun agvtool new-version -all $AUTOMATED_NUDGE_BUILD
/usr/bin/xcrun agvtool new-marketing-version $AUTOMATED_NUDGE_BUILD
# Create files to use for build process info
echo "$AUTOMATED_NUDGE_BUILD" > $TOOLSDIR/build_info.txt
echo "$CURRENT_NUDGE_MAIN_BUILD_VERSION" > $TOOLSDIR/build_info_main.txt
# Ensure Xcode is set to run-time
sudo xcode-select -s "$XCODE_PATH"
if [ -e $XCODE_BUILD_PATH ]; then
XCODE_BUILD="$XCODE_BUILD_PATH"
else
ls -la /Applications
echo "Could not find required Xcode build. Exiting..."
exit 1
fi
# Perform unit tests
echo "Running Nudge unit tests"
$XCODE_BUILD test -project "$TOOLSDIR/Nudge.xcodeproj" -scheme "Nudge - Debug" -destination 'platform=macos'
check_exit_code "$?" "Error running xcodebuild unit tests"
# build nudge
echo "Building Nudge"
$XCODE_BUILD -project "$TOOLSDIR/Nudge.xcodeproj" CODE_SIGN_IDENTITY=$APP_SIGNING_IDENTITY OTHER_CODE_SIGN_FLAGS="--timestamp"
check_exit_code "$?" "Error running xcodebuild"
# Create outputs folder
if [ -e $OUTPUTSDIR ]; then
/bin/rm -rf $OUTPUTSDIR
fi
/bin/mkdir -p "$OUTPUTSDIR"
if ! [ -n "$1" ]; then
echo "Did not pass option to create package"
# Move notarized zip to outputs folder
/usr/bin/ditto -c -k --keepParent "${BUILDSDIR}/Release/Nudge.app" "${BUILDSDIR}/Release/Nudge.zip"
/bin/mv "${BUILDSDIR}/Release/Nudge.zip" "$OUTPUTSDIR"
exit 0
fi
# move the app to the payload folder
echo "Moving Nudge.app to payload folder"
NUDGE_PKG_PATH="$TOOLSDIR/NudgePkg"
if [ -e $NUDGE_PKG_PATH ]; then
/bin/rm -rf $NUDGE_PKG_PATH
fi
/bin/mkdir -p "$NUDGE_PKG_PATH/payload"
/bin/mkdir -p "$NUDGE_PKG_PATH/scripts"
/usr/bin/sudo /usr/sbin/chown -R ${CONSOLEUSER}:wheel "$NUDGE_PKG_PATH"
/bin/cp -R "${BUILDSDIR}/Release/Nudge.app" "$NUDGE_PKG_PATH/payload/Nudge.app"
echo "Moving postinstall to scripts folder"
/bin/cp "${TOOLSDIR}/build_assets/postinstall-nudge" "$NUDGE_PKG_PATH/scripts/postinstall"
# Download specific version of munki-pkg
echo "Downloading munki-pkg tool from github..."
if [ -f "${MP_ZIP}" ]; then
/usr/bin/sudo /bin/rm -rf ${MP_ZIP}
fi
/usr/bin/curl https://github.com/munki/munki-pkg/archive/${MP_SHA}.zip -L -o ${MP_ZIP}
if [ -d ${MP_BINDIR} ]; then
/usr/bin/sudo /bin/rm -rf ${MP_BINDIR}
fi
/usr/bin/unzip ${MP_ZIP} -d ${MP_BINDIR}
check_exit_code "$?" "Error downloading munki-pkg tool"
# Create the json file for signed munkipkg Nudge pkg
/bin/cat << SIGNED_JSONFILE > "$NUDGE_PKG_PATH/build-info.json"
{
"ownership": "recommended",
"suppress_bundle_relocation": true,
"identifier": "com.github.macadmins.Nudge",
"postinstall_action": "none",
"distribution_style": true,
"version": "$AUTOMATED_NUDGE_BUILD",
"name": "Nudge-$AUTOMATED_NUDGE_BUILD.pkg",
"install_location": "/Applications/Utilities",
"signing_info": {
"identity": "$INSTALLER_SIGNING_IDENTITY",
"timestamp": true
}
}
SIGNED_JSONFILE
# Create the signed pkg
python3 "${MP_BINDIR}/munki-pkg-${MP_SHA}/munkipkg" "$NUDGE_PKG_PATH"
PKG_RESULT="$?"
check_exit_code "$?" "Could not sign package: Nudge-$AUTOMATED_NUDGE_BUILD.pkg"
# move the LaunchAgent to the payload folder
echo "Moving LaunchAgent to payload folder"
NUDGE_LA_PKG_PATH="$TOOLSDIR/NudgePkgLA"
if [ -e $NUDGE_LA_PKG_PATH ]; then
/bin/rm -rf $NUDGE_LA_PKG_PATH
fi
/bin/mkdir -p "$NUDGE_LA_PKG_PATH/payload"
/bin/mkdir -p "$NUDGE_LA_PKG_PATH/scripts"
/usr/bin/sudo /usr/sbin/chown -R ${CONSOLEUSER}:wheel "$NUDGE_LA_PKG_PATH"
echo "Moving LaunchAgent to payload folder"
/bin/cp "${TOOLSDIR}/build_assets/com.github.macadmins.Nudge.plist" "$NUDGE_LA_PKG_PATH/payload"
echo "Moving postinstall to scripts folder"
/bin/cp "${TOOLSDIR}/build_assets/postinstall-launchagent" "$NUDGE_LA_PKG_PATH/scripts/postinstall"
# Create the json file for the signed munkipkg LaunchAgent pkg
/bin/cat << SIGNED_JSONFILE > "$NUDGE_LA_PKG_PATH/build-info.json"
{
"distribution_style": true,
"identifier": "com.github.macadmins.Nudge.LaunchAgent",
"install_location": "/Library/LaunchAgents",
"name": "Nudge_LaunchAgent-1.0.1.pkg",
"ownership": "recommended",
"postinstall_action": "none",
"suppress_bundle_relocation": true,
"version": "1.0.1",
"signing_info": {
"identity": "$INSTALLER_SIGNING_IDENTITY",
"timestamp": true
}
}
SIGNED_JSONFILE
# Create the LaunchAgent signed pkg
python3 "${MP_BINDIR}/munki-pkg-${MP_SHA}/munkipkg" "$NUDGE_LA_PKG_PATH"
check_exit_code "$?" "Could not sign package: Nudge_LaunchAgent-1.0.1.pkg"
# move the Logger to the payload folder
echo "Moving LaunchDaemon to logging payload folder"
NUDGE_LD_PKG_PATH="$TOOLSDIR/NudgePkgLogger"
if [ -e $NUDGE_LD_PKG_PATH ]; then
/bin/rm -rf $NUDGE_LD_PKG_PATH
fi
/bin/mkdir -p "$NUDGE_LD_PKG_PATH/payload"
/bin/mkdir -p "$NUDGE_LD_PKG_PATH/scripts"
/usr/bin/sudo /usr/sbin/chown -R ${CONSOLEUSER}:wheel "$NUDGE_LD_PKG_PATH"
echo "Moving LaunchDaemon to logging payload folder"
/bin/cp "${TOOLSDIR}/build_assets/com.github.macadmins.Nudge.logger.plist" "$NUDGE_LD_PKG_PATH/payload"
echo "Moving postinstall to scripts folder"
/bin/cp "${TOOLSDIR}/build_assets/postinstall-logger" "$NUDGE_LD_PKG_PATH/scripts/postinstall"
# Create the json file for the signed munkipkg Logger pkg
/bin/cat << SIGNED_JSONFILE > "$NUDGE_LD_PKG_PATH/build-info.json"
{
"distribution_style": true,
"identifier": "com.github.macadmins.Nudge.Logger",
"install_location": "/Library/LaunchDaemons",
"name": "Nudge_Logger-1.0.1.pkg",
"ownership": "recommended",
"postinstall_action": "none",
"suppress_bundle_relocation": true,
"version": "1.0.1",
"signing_info": {
"identity": "$INSTALLER_SIGNING_IDENTITY",
"timestamp": true
}
}
SIGNED_JSONFILE
# Create the signed pkg
python3 "${MP_BINDIR}/munki-pkg-${MP_SHA}/munkipkg" "$NUDGE_LD_PKG_PATH"
check_exit_code "$?" "Could not sign package: Nudge_Logger-1.0.1.pkg"
# Create the Essentials package
echo "Moving Nudge.app to payload folder"
ESSENTIALS_PKG_PATH="$TOOLSDIR/NudgePkgEssentials"
if [ -e $ESSENTIALS_PKG_PATH ]; then
/bin/rm -rf $ESSENTIALS_PKG_PATH
fi
/bin/mkdir -p "$ESSENTIALS_PKG_PATH/payload/Applications/Utilities"
/bin/mkdir -p "$ESSENTIALS_PKG_PATH/payload/Library/LaunchAgents"
/bin/mkdir -p "$ESSENTIALS_PKG_PATH/scripts"
/usr/bin/sudo /usr/sbin/chown -R ${CONSOLEUSER}:wheel "$ESSENTIALS_PKG_PATH"
/bin/cp -R "${BUILDSDIR}/Release/Nudge.app" "$ESSENTIALS_PKG_PATH/payload/Applications/Utilities/Nudge.app"
echo "Moving LaunchAgent to payload folder"
/bin/cp "${TOOLSDIR}/build_assets/com.github.macadmins.Nudge.plist" "$ESSENTIALS_PKG_PATH/payload/Library/LaunchAgents"
echo "Moving postinstall to scripts folder"
/bin/cp "${TOOLSDIR}/build_assets/postinstall-essentials" "$ESSENTIALS_PKG_PATH/scripts/postinstall"
# Create the json file for signed munkipkg Nudge Essentials pkg
/bin/cat << SIGNED_JSONFILE > "$ESSENTIALS_PKG_PATH/build-info.json"
{
"ownership": "recommended",
"suppress_bundle_relocation": true,
"identifier": "com.github.macadmins.Nudge.Essentials",
"postinstall_action": "none",
"distribution_style": true,
"version": "$AUTOMATED_NUDGE_BUILD",
"name": "Nudge_Essentials-$AUTOMATED_NUDGE_BUILD.pkg",
"install_location": "/",
"signing_info": {
"identity": "$INSTALLER_SIGNING_IDENTITY",
"timestamp": true
}
}
SIGNED_JSONFILE
# Create the signed Nudge Essentials pkg
python3 "${MP_BINDIR}/munki-pkg-${MP_SHA}/munkipkg" "$ESSENTIALS_PKG_PATH"
check_exit_code "$?" "Could not sign package: Nudge_Essentials-$AUTOMATED_NUDGE_BUILD.pkg"
# Create the Suite package
echo "Moving Nudge.app to payload folder"
SUITE_PKG_PATH="$TOOLSDIR/NudgePkgSuite"
if [ -e $SUITE_PKG_PATH ]; then
/bin/rm -rf $SUITE_PKG_PATH
fi
/bin/mkdir -p "$SUITE_PKG_PATH/payload/Applications/Utilities"
/bin/mkdir -p "$SUITE_PKG_PATH/payload/Library/LaunchAgents"
/bin/mkdir -p "$SUITE_PKG_PATH/payload/Library/LaunchDaemons"
/bin/mkdir -p "$SUITE_PKG_PATH/scripts"
/usr/bin/sudo /usr/sbin/chown -R ${CONSOLEUSER}:wheel "$SUITE_PKG_PATH"
/bin/cp -R "${BUILDSDIR}/Release/Nudge.app" "$SUITE_PKG_PATH/payload/Applications/Utilities/Nudge.app"
echo "Moving LaunchAgent to payload folder"
/bin/cp "${TOOLSDIR}/build_assets/com.github.macadmins.Nudge.plist" "$SUITE_PKG_PATH/payload/Library/LaunchAgents"
echo "Moving LaunchDaemon to logging payload folder"
/bin/cp "${TOOLSDIR}/build_assets/com.github.macadmins.Nudge.logger.plist" "$SUITE_PKG_PATH/payload/Library/LaunchDaemons"
echo "Moving postinstall to scripts folder"
/bin/cp "${TOOLSDIR}/build_assets/postinstall-suite" "$SUITE_PKG_PATH/scripts/postinstall"
# Create the json file for signed munkipkg Nudge Suite pkg
/bin/cat << SIGNED_JSONFILE > "$SUITE_PKG_PATH/build-info.json"
{
"ownership": "recommended",
"suppress_bundle_relocation": true,
"identifier": "com.github.macadmins.Nudge.Suite",
"postinstall_action": "none",
"distribution_style": true,
"version": "$AUTOMATED_NUDGE_BUILD",
"name": "Nudge_Suite-$AUTOMATED_NUDGE_BUILD.pkg",
"install_location": "/",
"signing_info": {
"identity": "$INSTALLER_SIGNING_IDENTITY",
"timestamp": true
}
}
SIGNED_JSONFILE
# Create the signed Nudge Suite pkg
python3 "${MP_BINDIR}/munki-pkg-${MP_SHA}/munkipkg" "$SUITE_PKG_PATH"
check_exit_code "$?" "Could not sign package: Nudge_Suite-$AUTOMATED_NUDGE_BUILD.pkg"
# Notarize packages
if ! [ -n "$2" ]; then
echo "Did not pass option to notarize packages"
# Move notarized zip to outputs folder
/bin/mv "${BUILDSDIR}/Release/Nudge.zip" "$OUTPUTSDIR"
exit 0
fi
# Setup notary item
$XCODE_NOTARY_PATH store-credentials --apple-id "[email protected]" --team-id "T4SK8ZXCXG" --password "$2" nudge
# Notarize Nudge package
$XCODE_NOTARY_PATH submit "$NUDGE_PKG_PATH/build/Nudge-$AUTOMATED_NUDGE_BUILD.pkg" --keychain-profile "nudge" --wait
check_exit_code "$?" "Could not notarize package: Nudge-$AUTOMATED_NUDGE_BUILD.pkg"
$XCODE_STAPLER_PATH staple "$NUDGE_PKG_PATH/build/Nudge-$AUTOMATED_NUDGE_BUILD.pkg"
check_exit_code "$?" "Could not staple package: Nudge-$AUTOMATED_NUDGE_BUILD.pkg"
# Move the Nudge signed/notarized pkg
/bin/mv "$NUDGE_PKG_PATH/build/Nudge-$AUTOMATED_NUDGE_BUILD.pkg" "$OUTPUTSDIR"
# Notarize Nudge LaunchAgent package
$XCODE_NOTARY_PATH submit "$NUDGE_LA_PKG_PATH/build/Nudge_LaunchAgent-1.0.1.pkg" --keychain-profile "nudge" --wait
check_exit_code "$?" "Could not notarize package: Nudge_LaunchAgent-1.0.1.pkg"
$XCODE_STAPLER_PATH staple "$NUDGE_LA_PKG_PATH/build/Nudge_LaunchAgent-1.0.1.pkg"
check_exit_code "$?" "Could not staple package: Nudge_LaunchAgent-1.0.1.pkg"
# Move the Nudge LaunchAgent signed/notarized pkg
/bin/mv "$NUDGE_LA_PKG_PATH/build/Nudge_LaunchAgent-1.0.1.pkg" "$OUTPUTSDIR"
# Notarize Nudge Logger package
$XCODE_NOTARY_PATH submit "$NUDGE_LD_PKG_PATH/build/Nudge_Logger-1.0.1.pkg" --keychain-profile "nudge" --wait
check_exit_code "$?" "Could not notarize package: Nudge_Logger-1.0.1.pkg"
$XCODE_STAPLER_PATH staple "$NUDGE_LD_PKG_PATH/build/Nudge_Logger-1.0.1.pkg"
check_exit_code "$?" "Could not staple package: Nudge_Logger-1.0.1.pkg"
# Move the Nudge Logger signed/notarized pkg
/bin/mv "$NUDGE_LD_PKG_PATH/build/Nudge_Logger-1.0.1.pkg" "$OUTPUTSDIR"
# Notarize Nudge Essentials package
$XCODE_NOTARY_PATH submit "$ESSENTIALS_PKG_PATH/build/Nudge_Essentials-$AUTOMATED_NUDGE_BUILD.pkg" --keychain-profile "nudge" --wait
check_exit_code "$?" "Could not notarize package: Nudge_Essentials-$AUTOMATED_NUDGE_BUILD.pkg"
$XCODE_STAPLER_PATH staple "$ESSENTIALS_PKG_PATH/build/Nudge_Essentials-$AUTOMATED_NUDGE_BUILD.pkg"
check_exit_code "$?" "Could not staple package: Nudge_Essentials-$AUTOMATED_NUDGE_BUILD.pkg"
# Move the Nudge Essentials signed/notarized pkg
/bin/mv "$ESSENTIALS_PKG_PATH/build/Nudge_Essentials-$AUTOMATED_NUDGE_BUILD.pkg" "$OUTPUTSDIR"
# Notarize Nudge Suite package
$XCODE_NOTARY_PATH submit "$SUITE_PKG_PATH/build/Nudge_Suite-$AUTOMATED_NUDGE_BUILD.pkg" --keychain-profile "nudge" --wait
check_exit_code "$?" "Could not notarize package: Nudge_Suite-$AUTOMATED_NUDGE_BUILD.pkg"
$XCODE_STAPLER_PATH staple "$SUITE_PKG_PATH/build/Nudge_Suite-$AUTOMATED_NUDGE_BUILD.pkg"
check_exit_code "$?" "Could not staple package: Nudge_Suite-$AUTOMATED_NUDGE_BUILD.pkg"
# Move the Nudge Suite signed/notarized pkg
/bin/mv "$SUITE_PKG_PATH/build/Nudge_Suite-$AUTOMATED_NUDGE_BUILD.pkg" "$OUTPUTSDIR"