Skip to content

Instantly share code, notes, and snippets.

@skjalgsm
Created February 26, 2020 09:40
Show Gist options
  • Save skjalgsm/5e9090abb4bb6ec140a910df9080061f to your computer and use it in GitHub Desktop.
Save skjalgsm/5e9090abb4bb6ec140a910df9080061f to your computer and use it in GitHub Desktop.
Easy sign script for mac apps
#!/bin/bash
path="$1"
if [ "$path" = "" ] ; then
path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
fi
echo $path
appfile=`find "$path" -name "*.app" -exec basename {} \;`
echo $appfile
appDir=`find "$path" -name "*.app" -print`
echo $appDir
appName="${appfile%.*}"
echo $appName
BUILD_FOR="$2"
echo "2: " + $BUILD_FOR
DEVNAME="$3"
echo "3: " + $DEVNAME
provProfile="$4"
echo "4: " + $provProfile
signature="3rd Party Mac Developer Application: $DEVNAME"
installerSignature="3rd Party Mac Developer Installer: $DEVNAME"
if [ "$BUILD_FOR" = "development" ] ; then
signature="Mac Developer: $DEVNAME"
fi
entitlementsPath="fastlane/entitlements-appstore.plist"
if [ "$BUILD_FOR" = "development" ] ; then
entitlementsPath="fastlane/entitlements-development.plist"
fi
echo "--------- Changing read permissions ---------"
chmod -R 777 "$appDir"
echo "--------- Deleting meta files ---------"
find "$appDir/Contents/Plugins" -name '*.meta' -print -delete
echo "--------- Embedding CloudKit ---------"
optool install -c load -p "/System/Library/Frameworks/CloudKit.framework/Versions/A/CloudKit" -t "$appDir/Contents/MacOS/$appName"
echo "--------- Embedding provisionprofile $provProfile ---------"
cp -R "$provProfile" "$appDir/Contents/embedded.provisionprofile"
##cd "../$path"
echo "--------- Codesigning plugins ---------"
#Sign all the .dylib libraries in <your game name>.app/Contents/Frameworks manually. Do not include entitlements in the signing command.
#Sign all the plugins in your game. Do not include entitlements in the signing command.
OIFS="$IFS"
IFS=$'\n'
for bundle in $(find "$appDir/Contents" -name "*.bundle") $(find "$appDir/Contents" -name "*.dylib");
do
codesign --force --verify --sign "$signature" --preserve-metadata=identifier,entitlements,flags "$bundle"
done
IFS="$OIFS"
echo "--------- Codesigning $appDir with entlitlements plist "$entitlementsPath" ---------"
#Sign all the plugins in your game. Do not include entitlements in the signing command.
#codesign --force --verify --sign "<your development signing id>" --entitlements "<path to your entitlements files>" "<your game name>.app"
codesign --force --verify --sign "$signature" --entitlements "$entitlementsPath" "$appDir"
#echo "Display entitlements of app"
#CRASHES IN FASTLANE: invalid byte sequence in UTF-8
#codesign --display --entitlements - "$1".app
echo "--------- Verify code sign of $appDir ---------"
codesign -v --verify "$appDir"
if [ "$BUILD_FOR" != "development" ]; then
echo "--------- Productbuild pkg and sign $appfile.pkg ---------"
productbuild --component "$appDir" /Applications --sign "$installerSignature" "$path/$appName.pkg"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment