#!/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" # 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" # Convert options to an array. This is necessary, because we set IFS below. declare -a 'APP_SIGN_OPTIONS=($APP_SIGN_OPTIONS)' # Partially based on http://stackoverflow.com/a/11284404 FRAMEWORK_DIR="${APP_BUNDLE_PATH}/${FRAMEWORKS_FOLDER_PATH}" echo "Identity:" echo "${APP_SIGN_IDENTITY}" echo "" ## Sign dependencies echo "== SIGNING COCOA BUNDLES & FRAMEWORKS ==" FRAMEWORKS=$(find "${FRAMEWORK_DIR}" -depth -type d -name "*.framework" -or -name "*.dylib" -or -name "*.bundle" | sed -e "s/\(.*framework\)/\1\/Versions\/A\//") RESULT=$? if [[ $RESULT != 0 ]] ; then exit 1 fi echo "Will sign:" echo "${FRAMEWORKS}" echo "" # Changing the Internal Field Separator (IFS) so that spaces in paths will not cause problems below. SAVED_IFS=$IFS IFS=$(echo -en "\n\b") for FRAMEWORK in $FRAMEWORKS; do echo "Signing '${FRAMEWORK}'" /usr/bin/codesign ${APP_SIGN_OPTIONS} --sign "${APP_SIGN_IDENTITY}" "${FRAMEWORK}" RESULT=$? if [[ $RESULT != 0 ]] ; then IFS=$SAVED_IFS exit 1 fi done # restore $IFS IFS=$SAVED_IFS # Sign app bundle itself echo "" echo "== SIGNING $APP_BUNDLE_PATH ==" /usr/bin/codesign $APP_SIGN_OPTIONS --sign "$APP_SIGN_IDENTITY" "$APP_BUNDLE_PATH" RESULT=$? if [[ $RESULT != 0 ]] ; then exit 1 fi # Packaging echo "" if [ "${INSTALLER_SIGN_IDENTITY}" = "" ] ; then echo "No INSTALLER_SIGN_IDENTITY. Packaging was skipped." exit 0 fi echo "== PACKAGING ==" rm "$PKG_PATH" productbuild --component "$APP_BUNDLE_PATH" "/Applications" "$PKG_PATH" --sign "$INSTALLER_SIGN_IDENTITY" RESULT=$? if [[ $RESULT != 0 ]] ; then exit 1 fi echo "" echo "== THAT'S ALL FOLKS! ==" # Done