-
Notifications
You must be signed in to change notification settings - Fork 20
/
pack_app3.sh
executable file
·440 lines (380 loc) · 13.5 KB
/
pack_app3.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/bin/bash
# creates a package for macOS
# create an appbundle structure
# package as dmg (diskimage)
#./pack_app3.sh Lernfabrik futurefactory.pvr /Users/victorhafner/Projects/lernfabrik
appName=$1
appProject=$2
appFolder=$3
deployName="$appName"
deployExeName="$appName"
pckFolder="packages/$deployExeName.app"
pckPVRFolder="$pckFolder/Contents/Resources" # copy directly in Resources because of CEF.. (relative path to helpers!)
bin="$pckFolder/Contents/MacOS/"
res="$pckFolder/Contents/Resources/"
libs="$pckFolder/Contents/Frameworks"
function createPListFile() {
if [[ ! -f entitlements.plist ]]; then
cat <<EOT >> entitlements.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
</dict>
</plist>
EOT
fi
}
function signFile {
# Warning, using --options runtime makes apple apply strikt security rules, this may make the app not to start at all
codesign --force --options runtime --entitlements "entitlements.plist" --sign "Developer ID Application: Victor Haefner" --deep "$1"
#codesign --force --sign - --deep "$1" # for testing
}
function signBundle {
echo "sign whole bundle, $pckFolder"
codesign --force --options runtime --entitlements "entitlements.plist" --sign "Developer ID Application: Victor Haefner" --deep "$pckFolder"
#codesign --force --sign - --deep "$pckFolder" # for testing, see above
}
strip_absolute_paths() {
local executable=$1
#local libs=$(otool -L "$executable" | grep -oE '/[^ ]+\.dylib' | sort -u)
local libs=$(otool -L "$executable" | grep -oE '[^ ]+\.dylib' | sort -u)
# Loop through each library and strip the absolute path
for lib in $libs; do
# TODO: check if boost or [email protected] in path and if present prepend to lib_name!
local lib_name=$(basename "$lib")
if [[ "$lib" == *"libSystem"* ]]; then
continue
fi
if [[ "$lib" == *"libobjc"* ]]; then
continue
fi
if [[ "$lib" == *"libc++"* ]]; then
continue
fi
#if [[ "$lib" == *"libgfortran"* ]]; then
# continue
#fi
if [[ ! -f $2/$lib_name ]]; then
echo "strip $executable, ignore lib $lib, $lib_name is not in folder $2!"
continue # ignore libs not in folder
fi
if [[ "$lib" == *"[email protected]"* ]]; then
lib_name="[email protected]/$lib_name"
#continue
elif [[ "$lib" == *"boost"* ]]; then
lib_name="boost/$lib_name"
#continue
fi
rPath="@executable_path/../Frameworks"
install_name_tool -change "$lib" "$rPath/$lib_name" "$executable" 2>/dev/null
done
}
function check_libs_paths {
echo "check_libs_paths"
for file in $1/*.dylib; do
if [[ -f $file ]]; then
#echo "Processing file: $file"
strip_absolute_paths "$file" "$1"
signFile $file
fi
done
for file in $1/boost176/*.dylib; do
if [[ -f $file ]]; then
#echo "Processing file: $file"
#strip_absolute_paths "$file" "$1"
signFile $file
fi
done
}
function addDir {
if [ ! -e $1 ]; then
mkdir -p $1
fi
}
function checkAppFolder {
echo "check for $appFolder/$appProject"
if [ ! -d "$appFolder" ]; then
echo "Error: app folder not found, $appFolder"
exit 1
fi
if [ ! -e "$appFolder/$appProject" ]; then
echo "Error: project file not found, $appFolder/$appProject"
exit 1
fi
}
function getDeployConfig {
echo "get deploy config"
if [ -e "$appFolder/deploy/config" ]; then
while IFS=: read -r key value; do
echo $key $value
eval "${key}='${value}'"
done < "$appFolder/deploy/config"
fi
echo "$deployName" "$deployExeName"
if [ -e "packages/$deployExeName.dmg" ]; then
rm "packages/$deployExeName.dmg"
fi
if [ -e "packages/${deployExeName}_ro.dmg" ]; then
rm "packages/${deployExeName}_ro.dmg"
fi
}
function setupFolders {
addDir $pckFolder
rm -rf $pckFolder/*
addDir $pckFolder/Contents
addDir $pckFolder/Contents/MacOS
addDir $pckFolder/Contents/Resources
addDir $pckFolder/Contents/Frameworks
}
function copyAppData {
echo " copy app data"
cp -r $appFolder/* $pckPVRFolder/
}
function copyPolyVR {
echo " copy polyvr"
cp -r build/polyvr $bin/
cp -r ressources $res/
cp -r setup $res/
cp -r shader $res/
#cp -r examples $res/
mkdir -p "$libs/polyvr Helper.app/Contents/MacOS"
mkdir -p "$libs/polyvr Helper (GPU).app/Contents/MacOS"
mkdir -p "$libs/polyvr Helper (Renderer).app/Contents/MacOS"
mkdir -p "$libs/polyvr Helper (Plugin).app/Contents/MacOS"
mkdir -p "$libs/polyvr Helper (Alerts).app/Contents/MacOS"
cp "ressources/cefMac/helper/CefSubProcessMac" "$libs/polyvr Helper.app/Contents/MacOS/polyvr Helper"
cp "ressources/cefMac/helper/CefSubProcessMac (Alerts)" "$libs/polyvr Helper (Alerts).app/Contents/MacOS/polyvr Helper (Alerts)"
cp "ressources/cefMac/helper/CefSubProcessMac (GPU)" "$libs/polyvr Helper (GPU).app/Contents/MacOS/polyvr Helper (GPU)"
cp "ressources/cefMac/helper/CefSubProcessMac (Plugin)" "$libs/polyvr Helper (Plugin).app/Contents/MacOS/polyvr Helper (Plugin)"
cp "ressources/cefMac/helper/CefSubProcessMac (Renderer)" "$libs/polyvr Helper (Renderer).app/Contents/MacOS/polyvr Helper (Renderer)"
}
function signPolyVR {
signFile $bin/polyvr
signFile "$res/ressources/cefMac/helper/CefSubProcessMac"
signFile "$res/ressources/cefMac/helper/CefSubProcessMac (Alerts)"
signFile "$res/ressources/cefMac/helper/CefSubProcessMac (GPU)"
signFile "$res/ressources/cefMac/helper/CefSubProcessMac (Plugin)"
signFile "$res/ressources/cefMac/helper/CefSubProcessMac (Renderer)"
signFile "$libs/polyvr Helper.app/Contents/MacOS/polyvr Helper"
signFile "$libs/polyvr Helper (Alerts).app/Contents/MacOS/polyvr Helper (Alerts)"
signFile "$libs/polyvr Helper (GPU).app/Contents/MacOS/polyvr Helper (GPU)"
signFile "$libs/polyvr Helper (Plugin).app/Contents/MacOS/polyvr Helper (Plugin)"
signFile "$libs/polyvr Helper (Renderer).app/Contents/MacOS/polyvr Helper (Renderer)"
signFile "$libs/Chromium Embedded Framework.framework/Libraries/libEGL.dylib"
signFile "$libs/Chromium Embedded Framework.framework/Libraries/libvk_swiftshader.dylib"
signFile "$libs/Chromium Embedded Framework.framework/Libraries/libGLESv2.dylib"
}
function copyDependencies {
echo " copy libs"
#cp -r $pyPath $pckFolder/engine/pyLibs
cp -r /usr/local/lib64/* $libs/
rm $libs/libOSGWindowGLUT*
cp -r /usr/local/lib/cef/* $libs/
cp -r /usr/local/lib/libcollada* $libs/
cp -r /opt/homebrew/opt/freetype/lib/* $libs
cp -r $HOME/.pyenv/versions/2.7.18/lib/* $libs/
cp -r /opt/homebrew/opt/bullet/lib/* $libs/
cp -r /opt/homebrew/opt/icu4c/lib/* $libs/
cp -r /opt/homebrew/opt/lapack/lib/* $libs/
cp -r /opt/homebrew/opt/openal-soft/lib/* $libs/
cp -r /opt/homebrew/opt/ffmpeg/lib/* $libs/
cp -r /opt/homebrew/opt/fftw/lib/* $libs/
cp -r /opt/homebrew/opt/jsoncpp/lib/* $libs/
cp -r /opt/homebrew/opt/libssh/lib/* $libs/
cp -r /opt/homebrew/opt/libpng/lib/* $libs/
cp -r /opt/homebrew/opt/jpeg-turbo/lib/* $libs/
cp -r /opt/homebrew/opt/krb5/lib/* $libs/
# TODO: those should be present on mac by default, but maybe the version might not fit someday?
#cp /usr/lib/libcurl.4.dylib $libs/
#cp /usr/lib/libz.1.dylib $libs/
#cp /usr/lib/libbz2.1.0.dylib $libs/
#cp /usr/lib/libiconv.2.dylib $libs/
while IFS= read -r line; do
cp -r "$line" $libs/
done < "macLibs.txt"
rm -f $libs/*.a
mkdir $libs/lib
mv $libs/python2.7 $libs/lib/python27
ln -s python27 python2.7 ; mv ./python2.7 $libs/lib/python2.7
mv $libs/python3.11 $libs/python311
mv $libs/bullet/single/python3.11 $libs/bullet/single/python311
ln -s python311 python3.11 ; mv ./python3.11 $libs/python3.11
ln -s python311 python3.11 ; mv ./python3.11 $libs/bullet/single/python3.11
mkdir -p "$libs/boost"
mkdir -p "$libs/[email protected]"
cp -r /opt/homebrew/opt/boost/lib/* $libs/boost/
cp -r /opt/homebrew/opt/[email protected]/lib/* $libs/[email protected]/
cp $libs/boost/libboost_system.dylib $libs/
cp $libs/boost/libboost_serialization.dylib $libs/
cp $libs/boost/libboost_filesystem.dylib $libs/
cp $libs/boost/libboost_program_options.dylib $libs/
mv $libs/[email protected] $libs/boost176
echo " cleanup"
rm -rf $res/ressources/cef
rm -rf $res/ressources/cef18
rm -rf $res/ressources/cefWin
rm -rf $libs/pkgconfig
rm -rf $libs/cmake
rm -f $libs/boost/*.a
rm -rf $libs/boost/cmake
rm -rf $libs/bullet/single/pkgconfig
rm -rf $libs/bullet/single/cmake
rm -f $libs/bullet/single/*.a
rm -rf $libs/bullet/double/pkgconfig
rm -rf $libs/bullet/double/cmake
rm -f $libs/bullet/double/*.a
rm -rf $libs/lib/python27/site-packages/*.dist-info
rm -f $libs/lib/python27/config/libpython2.7.a
rm -f $libs/boost176/*.a
rm -rf $libs/boost176/cmake
rm -rf $libs/icu
if [ -e $pckPVRFolder/deploy/cleanup.sh ]; then
/bin/bash $pckPVRFolder/deploy/cleanup.sh
fi
}
function stripPaths {
check_libs_paths $libs
strip_absolute_paths $bin/polyvr "$libs"
}
function setupAppRessources {
echo "create icon"
icon="ressources/gui/logo_icon.png"
if [ -e "$pckPVRFolder/deploy/icon.png" ]; then
icon="$pckPVRFolder/deploy/icon.png"
fi
addDir $res/$deployExeName.iconset
cp $icon $res/$deployExeName.iconset/icon_16x16.png
cp $icon $res/$deployExeName.iconset/[email protected]
cp $icon $res/$deployExeName.iconset/icon_32x32.png
cp $icon $res/$deployExeName.iconset/[email protected]
cp $icon $res/$deployExeName.iconset/icon_128x128.png
cp $icon $res/$deployExeName.iconset/[email protected]
cp $icon $res/$deployExeName.iconset/icon_256x256.png
cp $icon $res/$deployExeName.iconset/[email protected]
cp $icon $res/$deployExeName.iconset/icon_512x512.png
cp $icon $res/$deployExeName.iconset/[email protected]
iconutil -c icns -o $res/$deployExeName.icns $res/$deployExeName.iconset
echo "write Info.plist file"
# check plist file with
# plutil -lint Lernfabrik.app/Contents/Info.plist
cat <<EOT >> $pckFolder/Contents/Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleGetInfoString</key>
<string>$deployExeName</string>
<key>CFBundleExecutable</key>
<string>startApp.sh</string>
<key>CFBundleIdentifier</key>
<string>com.ees.www</string>
<key>CFBundleName</key>
<string>$deployName</string>
<key>CFBundleIconFile</key>
<string>$deployExeName</string>
<key>CFBundleShortVersionString</key>
<string>0.01</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>IFMajorVersion</key>
<integer>0</integer>
<key>IFMinorVersion</key>
<integer>1</integer>
<key>LSMinimumSystemVersion</key>
<string>10.12</string>
</dict>
</plist>
EOT
echo "write startApp.sh file"
if [ -n "$appProject" ]; then # check is appProject given
cat <<EOT >> $bin/startApp.sh
#!/bin/zsh
DIR="\$(cd "\$(dirname "\$0")" && pwd)"
osascript <<EOF
tell application "Terminal"
do script "cd \${DIR} && ./startApp2.sh"
end tell
EOF
#cd \${DIR} && ./startApp2.sh
EOT
fi
echo "write startApp2.sh file"
if [ -n "$appProject" ]; then # check is appProject given
cat <<EOT >> $bin/startApp2.sh
#!/bin/zsh
#xclock
DIR="\$(cd "\$(dirname "\$0")" && pwd)"
LIBS="\${DIR}/../Frameworks"
libs="\$LIBS:\$LIBS/Chromium Embedded Framework.framework/Libraries"
export DYLD_LIBRARY_PATH="\$libs"
export DYLD_FRAMEWORK_PATH="\$libs"
export PYTHONHOME="\$LIBS"
cd \$DIR/../Resources
../MacOS/polyvr --setup="macOS" --application $appProject
EOT
fi
chmod +x $bin/startApp.sh
chmod +x $bin/startApp2.sh
}
function verifyApp {
echo "zip app"
/usr/bin/ditto -c -k --keepParent "packages/$deployExeName.app" "packages/$deployExeName.zip"
echo "submit packages/$deployExeName.zip for verification"
xcrun notarytool submit "packages/$deployExeName.zip" --keychain-profile "notarizeLernfabrik" --wait
xcrun stapler staple "packages/$deployExeName.app"
xcrun notarytool history --keychain-profile "notarizeLernfabrik"
}
function createDiskImage {
echo "create disk image"
hdiutil create -volname $deployExeName -srcfolder $pckFolder -ov -format UDRW "packages/$deployExeName.dmg"
echo "configure dmg"
MOUNT_POINT=/Volumes/$deployExeName
hdiutil detach $MOUNT_POINT
hdiutil attach "packages/$deployExeName.dmg"
ln -s /Applications $MOUNT_POINT/Applications
osascript <<EOF
tell application "Finder"
tell disk "$deployExeName"
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set the bounds of container window to {100, 100, 600, 400}
set viewOptions to the icon view options of container window
set arrangement of viewOptions to not arranged
set icon size of viewOptions to 72
set position of item "$deployExeName" of container window to {100, 100}
set position of item "Applications" of container window to {400, 100}
update without registering applications
delay 5
end tell
end tell
EOF
hdiutil detach $MOUNT_POINT
echo "create read only disk image"
hdiutil convert "packages/$deployExeName.dmg" -format UDZO -o "packages/${deployExeName}_ro.dmg"
}
checkAppFolder
getDeployConfig
setupFolders
setupAppRessources
copyAppData
copyPolyVR
copyDependencies
#exit 0
stripPaths
signPolyVR
signBundle
verifyApp
createDiskImage
echo " done"