Instantly share code, notes, and snippets.

Embed
What would you like to do?
Codesign an app bundle and build a signed package ready for submission to the Mac App Store
#!/bin/bash
#
# SignAndPackageForMAS.sh v1.0.1
#
# Codesign an app bundle and build a signed package ready for submission to the
# Mac App Store
#
# Copyright (c) 2014 Felix Schwarz (@felix_schwarz), IOSPIRIT GmbH (@iospirit)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
## Configuration
# The name of the identity to use for signing the app and its contents
# (use Keychain Access.app to get the name of yours)
APP_SIGN_IDENTITY="3rd Party Mac Developer Application: IOSPIRIT GmbH (UH96K9N25C)"
# Options passed to codesign. If the app bundle (and its binaries) that you
# provide has already been signed and contains metadata (such as entitlements
# and requirements) that you want to re-use, be sure to add "--preserve-metadata".
# For more info on codesign options, please consult the man page for codesign.
# (thanks @danielpunkass for pointing out this omission)
APP_SIGN_OPTIONS="--force --sign"
# The name of the identity to use for signing the app and its contents
# (use Keychain Access.app to get the name of yours)
INSTALLER_SIGN_IDENTITY="3rd Party Mac Developer Installer: IOSPIRIT GmbH (UH96K9N25C)"
# Path to the app bundle to sign and build a MAS package from
APP_BUNDLE_PATH="../distribution/Remote Buddy Express.app"
# Path to store the completed package at (any pre-existing file at this path will be deleted)
PKG_PATH="../distribution/RemoteBuddyExpress.pkg"
## Sign
echo "== SIGNING COCOA BUNDLES =="
find "$APP_BUNDLE_PATH" -name "*.bundle" -exec echo "Will sign" {} \;
find "$APP_BUNDLE_PATH" -name "*.bundle" -exec /usr/bin/codesign $APP_SIGN_OPTIONS "$APP_SIGN_IDENTITY" {} \;
echo ""
echo "== SIGNING FRAMEWORKS =="
find "$APP_BUNDLE_PATH" -name "*.framework" -exec echo "Will sign" {}/Versions/A \;
find "$APP_BUNDLE_PATH" -name "*.framework" -exec /usr/bin/codesign $APP_SIGN_OPTIONS "$APP_SIGN_IDENTITY" {}/Versions/A \;
echo ""
echo "== SIGNING $APP_BUNDLE_PATH =="
/usr/bin/codesign $APP_SIGN_OPTIONS "$APP_SIGN_IDENTITY" "$APP_BUNDLE_PATH"
echo ""
echo "== PACKAGING =="
rm "$PKG_PATH"
productbuild --component "$APP_BUNDLE_PATH" "/Applications" "$PKG_PATH" --sign "$INSTALLER_SIGN_IDENTITY"
echo ""
echo "== THAT'S ALL FOLKS! =="
# Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment