Created
November 29, 2023 22:58
-
-
Save JanisErdmanis/618ee27c5af01c1de9ae8bdc10e66677 to your computer and use it in GitHub Desktop.
Bundling script for AppBundler produced app bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
info() { | |
local GREEN="\033[0;32m" | |
local NO_COLOR="\033[0m" # No color (reset to default) | |
echo -e "${GREEN}INFO: $*${NO_COLOR}" | |
} | |
APPDIR="$1" | |
if [ -z "$2" ]; then | |
DMG="$(basename ${APPDIR%.*}).dmg" | |
else | |
DMG="$2" | |
fi | |
LAUNCHER=$(/usr/libexec/PlistBuddy -c "Print CFBundleExecutable" $APPDIR/Contents/Info.plist) | |
APP_NAME=$(/usr/libexec/PlistBuddy -c "Print CFBundleDisplayName" $APPDIR/Contents/Info.plist) | |
ARCH=$(file $APPDIR/Contents/Libraries/julia/bin/julia | grep -o 'x86_64\|arm64' | uniq) | |
info "Precompiling" | |
# Waiting for julia 1.11 with cache relocatability fix | |
# $APPDIR/Contents/MacOS/precompile | |
# Installation of apps is allways in /Applications folder thus it can be compiled from there | |
cleanup() { | |
[ -d "/Applications/$APP_NAME.app" ] && mv "/Applications/$APP_NAME.app" "$APPDIR" | |
} | |
trap cleanup EXIT | |
mv "$APPDIR" "/Applications/$APP_NAME.app" | |
"/Applications/$APP_NAME.app/Contents/MacOS/precompile" | |
cleanup | |
info "Forming launcher" | |
[ ! -f "$APPDIR/Contents/MacOS/main" ] && mv "$APPDIR/Contents/MacOS/$LAUNCHER" "$APPDIR/Contents/MacOS/main" | |
gcc -arch $ARCH -o "$APPDIR/Contents/MacOS/$LAUNCHER" "$APPDIR/Contents/Resources/launcher.c" | |
info "Codesigning" | |
codesign --force --sign "JanisErdmanis" "$APPDIR/Contents/Libraries/julia/bin/julia" | |
codesign --force --sign "JanisErdmanis" "$APPDIR/Contents/Libraries/julia/libexec/julia/lld" | |
codesign --force --sign "JanisErdmanis" "$APPDIR/Contents/Libraries/julia/libexec/julia/dsymutil" | |
codesign --entitlements "$APPDIR/Contents/Resources/Entitlements.plist" --force --sign "JanisErdmanis" --deep "$APPDIR" | |
info "Bundling app into dmg" | |
TMPAPP="$TMPDIR/$APP_NAME.app" | |
cleanup() { | |
[ -d "$TMPAPP" ] && mv "$TMPAPP" "$APPDIR" | |
} | |
mv "$APPDIR" "$TMPAPP" | |
dmgbuild -s "$TMPAPP/Contents/Resources/dmg_settings.py" -D app="$TMPAPP" "$APP_NAME Installer" "$DMG" | |
cleanup | |
codesign --sign "JanisErdmanis" -v "$DMG" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment