-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·297 lines (232 loc) · 7.87 KB
/
build.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
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
#!/bin/sh
VERSION="0.1.0"
VERSION=$(echo $VERSION | tr '.' '_')
PLUGIN_DIR="$HOME/Desktop/test"
PLUGIN_DIR="/Library/Audio/Plug-Ins"
SUPPORT_DIR="/Library/Application Support/sound_ctl"
PLUGIN_SUPPORT_DIR="$SUPPORT_DIR/rtstft_ctl"
PLUGIN_PRESETS_DIR="$PLUGIN_SUPPORT_DIR/presets"
OUTPUT_DIR='..'
SIGNING_CERT="Developer ID Application: Jackson Kaplan (792TGC726K)"
INSTALLER_CERT="Developer ID Installer: Jackson Kaplan (792TGC726K)"
INSTALLER_NAME_FINAL="OSX_rtstft_ctl_"$VERSION
bold=$(tput bold)
norm=$(tput sgr0)
function print_help() {
cat <<PRINT_HELP
${bold}NAME:${norm}
build.sh:
${bold}USAGE:${norm}
./build.sh [-p [DIR]] [-f]
${bold}OPTIONS:${norm}
-p [DIR] location of presets dir to copy into the repository before assembling the installation package
-f copy the default presets factory directory (${PLUGIN_PRESETS_DIR}/Factory) into the repository before packaging
-k keep the pkg_build dir to inspect for debugging purposes
-n build a dmg and notarize
-h display this dialog
PRINT_HELP
}
function error_out() {
print_help
exit 1
}
CLEANUP=TRUE
NOTARIZE=
while getopts 'p:fknh' OPT; do
case "$OPT" in
p)
PRESETS_FACTORY_DIR=$OPTARG
if [ -d "$OPTARG" ]; then
rm -rf ./Resources/Factory
cp -r "$OPTARG" ./Resources/Factory
chmod -R 777 ./Resources/Factory
else
error_out
fi
;;
f)
rm -rf ./Resources/Factory
cp -r "/Library/Application Support/sound_ctl/rtstft_ctl/presets/Factory" ./Resources/Factory
chmod -R 777 ./Resources/Factory
;;
k)
CLEANUP=
;;
n)
NOTARIZE=TRUE
git branch | fgrep '*' | fgrep main >/dev/null 2>&1
if [ "$?" -ne "0" ]; then
echo "ERROR: Don't try to notarize a non-main build!"
exit 1
fi
;;
h)
print_help
exit 0
;;
?)
error_out
;;
esac
done
echo $"======= RUNNING CMAKE BUILD =======\n"
cmake -Bbuild -G "Ninja Multi-Config"
cmake --build build --config Release --target rtstft_ctl_AU
cmake --build build --config Release --target rtstft_ctl_VST3
echo $"======= CREATING BUNDLE FILES =======\n"
mkdir pkg_build
cd pkg_build
mkdir resources
cat >resources/readme.txt <<README
Welcome to the rtstft_ctl installer! By default, this \
package will install both the AU and VST versions of rtstft_ctl, \
but feel free to customize the installation and exclude one of these \
in order to save some space on your machine.
README
cp ../LICENSE resources/license.txt
# https://github.com/kurasu/surge/blob/main/installer_mac/make_installer.sh
echo $"===== CREATING DISTRIBUTION XML =====\n"
BUILD_SRC="../build/rtstft_ctl_artefacts/Release"
AU_NAME="rtstft_ctl.component"
AU_SRC=$BUILD_SRC"/AU/"$AU_NAME
AU_DEST=$PLUGIN_DIR"/Components"
AU_ID="com.soundctl.rtstftctl.au"
VST3_NAME="rtstft_ctl.vst3"
VST3_SRC=$BUILD_SRC"/VST3/"$VST3_NAME
VST3_DEST=$PLUGIN_DIR"/VST3"
VST3_ID="com.soundctl.rtstftctl.vst3"
PRESETS_NAME="Presets"
PRESETS_ID="com.soundctl.rtstftctl.presets"
cat >distribution.xml <<XMLEND
<?xml version="1.0" encoding="UTF-8"?>
<installer-gui-script>
<options/>
<title>rtstft_ctl</title>
<background file="background" scaling="tofit" alignment="center"/>
<welcome file="readme.txt" mime-type="text/plain" />
<license file="license.txt" mime-type="text/plain" />
<choices-outline>
<line choice="${AU_NAME}"/>
<line choice="${VST3_NAME}"/>
<line choice="${PRESETS_NAME}"/>
</choices-outline>
<choice id="${AU_NAME}" title="Audio Unit" description="rtstft_ctl Audio Unit Installation">
<pkg-ref id="${AU_ID}"/>
</choice>
<choice id="${VST3_NAME}" title="VST3" description="rtstft_ctl VST3 Installation">
<pkg-ref id="${VST3_ID}"/>
</choice>
<choice id="${PRESETS_NAME}" title="Presets" description="Install factory preset library">
<pkg-ref id="${PRESETS_ID}"/>
</choice>
<pkg-ref id="${AU_ID}" version="0.1.0" auth="Root">${AU_NAME}.pkg</pkg-ref>
<pkg-ref id="${VST3_ID}" version="0.1.0" auth="Root">${VST3_NAME}.pkg</pkg-ref>
<pkg-ref id="${PRESETS_ID}" version="0.1.0" auth="Root">${PRESETS_NAME}.pkg</pkg-ref>
</installer-gui-script>
XMLEND
echo $"========= WRITING SCRIPTS ==========\n"
mkdir scripts
cat >scripts/postinstall <<CHECK_DIR_END
#!/bin/sh
echo "running postinstall..." > /tmp/rtstft_install.log
mkdir -p "/Library/Application Support/sound_ctl/rtstft_ctl/presets"
chmod -R 777 "/Library/Application Support/sound_ctl/rtstft_ctl/presets"
if [ "\$?" -ne '0' ]; then
echo FAILED TO CHMOD PRESET DIRECTORIES!!!
echo FAILED TO CHMOD PRESET DIRECTORIES!!!
echo FAILED TO CHMOD PRESET DIRECTORIES!!!
echo FAILED TO CHMOD PRESET DIRECTORIES!!!
echo FAILED TO CHMOD PRESET DIRECTORIES!!!
echo FAILED TO CHMOD PRESET DIRECTORIES!!! >> /tmp/rtstft_install.log
exit 5
fi
echo "check_directories done." >> /tmp/rtstft_install.log
exit 0
CHECK_DIR_END
chmod 755 scripts/postinstall
echo $"======= CREATING SUB-PACKAGES =======\n"
asssemble_pkg() {
SRC="$1"
DEST="$2"
NAME="$3"
ID="$4"
if [ -z $ID ]; then
echo $"Missing parameters in pkg assembly phase\n Check the build script."
exit 1
fi
cp -r $SRC $NAME
codesign -fs "$SIGNING_CERT" $NAME
pkgbuild \
--component "$NAME" \
--identifier "$ID" \
--version $VERSION \
--install-location "$DEST" \
--sign "$INSTALLER_CERT" \
--scripts scripts \
$NAME.pkg # > /dev/null 2>&1
echo $"\n"
}
asssemble_pkg $AU_SRC $AU_DEST $AU_NAME $AU_ID
asssemble_pkg $VST3_SRC $VST3_DEST $VST3_NAME $VST3_ID
pkgbuild \
--root ../Resources/Factory \
--version $VERSION \
--identifier "$PRESETS_ID" \
--install-location "$PLUGIN_PRESETS_DIR/Factory" \
--sign "$INSTALLER_CERT" \
--scripts scripts \
$PRESETS_NAME.pkg
echo $"\n======== FINAL PACKAGE BUILD ========\n"
PKG_NAME_FINAL="$INSTALLER_NAME_FINAL.pkg"
productbuild --sign "$INSTALLER_CERT" \
--distribution distribution.xml \
--package-path '.' \
--scripts scripts \
./"$PKG_NAME_FINAL" # > /dev/null 2>&1
function notarize() {
echo $"\n========= GENARATE MANUAL =========\n"
DOCS="../RTSTFT/docs"
PAPER="RTSTFT_CTL_WHITEPAPER.pdf"
make -C "$DOCS" >/dev/null
cp "$DOCS/paper.pdf" "./$PAPER"
make clean -C "$DOCS"
TMPDIR="./dmg-tmp"
mkdir -p "$TMPDIR"
mv "./$PAPER" "./$TMPDIR"
# https://github.com/surge-synthesizer/surge/blob/main/scripts/installer_mac/make_installer.sh
echo $"\n============ CREATE DMG ============\n"
DMG_NAME_FINAL="$INSTALLER_NAME_FINAL.dmg"
mv "./$PKG_NAME_FINAL" "$TMPDIR"
if [ -f "$OUTPUT_DIR/$DMG_NAME_FINAL" ]; then
rm "$OUTPUT_DIR/$DMG_NAME_FINAL"
fi
hdiutil create /tmp/tmp.dmg -ov -volname "$INSTALLER_NAME_FINAL" -fs HFS+ -srcfolder "$TMPDIR"
hdiutil convert /tmp/tmp.dmg -format UDZO -o "$OUTPUT_DIR/$DMG_NAME_FINAL"
echo $"\n============= NOTARIZE ==============\n"
if [ -n "$SIGNING_CERT" ]; then
codesign -fs "$SIGNING_CERT" --timestamp "$OUTPUT_DIR/$DMG_NAME_FINAL"
codesign -vvv "$OUTPUT_DIR/$DMG_NAME_FINAL"
if [ "$(xcodebuild -version | egrep -o '[0-9]+' | head -n 1)" -ge 13 ]; then
xcrun notarytool submit "$OUTPUT_DIR/$DMG_NAME_FINAL" --keychain-profile AC_PASSWORD --wait
else
echo "Just use XCode 13 god damnit"
exit 5
fi
if [ "$?" -ne '0' ]; then
echo "Notarization failed."
exit 17
fi
xcrun stapler staple "$OUTPUT_DIR/$INSTALLER_NAME_FINAL.dmg"
fi
rm -rf "$TMPDIR"
}
if [ -n "$NOTARIZE" ]; then
notarize
else
mv $PKG_NAME_FINAL ..
fi
cd ..
if [ -n "$CLEANUP" ]; then
echo $"\n============== CLEANUP ==============\n"
rm -rf pkg_build
fi