Created
May 7, 2013 17:47
-
-
Save charlesmchen/5534599 to your computer and use it in GitHub Desktop.
A fork of Richard Bronosky's simple tool for resigning an iOS app .ipa with a new certificate & provisioning profile.
This file contains hidden or 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
#!/usr/bin/env bash | |
# Derived from: https://gist.github.com/RichardBronosky/2878446 | |
realpath(){ | |
echo "$(cd "$(dirname "$1")"; echo -n "$(pwd)/$(basename "$1")")"; | |
} | |
IPA_SRC="$(realpath $1)" | |
PROVISIONING_PROFILE="$(realpath $2)" | |
CERTIFICATE_NAME="$3" | |
APP_NAME="$4" | |
IPA_DST="$(realpath $5)" | |
echo " - .ipa source file: $IPA_SRC" | |
echo " - Provisioning profile: $PROVISIONING_PROFILE" | |
echo " - Certificate name: $CERTIFICATE_NAME" | |
echo " - App name: $APP_NAME" | |
echo " - .ipa destination: file $IPA_DST" | |
USAGE="Usage: resign.sh src.ipa foo/bar.mobileprovision \"iPhone Distribution: Cert name\" AppName.app dst.ipa " | |
if [[ ! ( | |
-f "$IPA_SRC" | |
) ]]; | |
then | |
echo ".ipa source file cannot be found. $USAGE" | |
exit 1 | |
fi | |
if [[ ! ( | |
"${IPA_SRC##*.}" == "ipa" | |
) ]]; | |
then | |
echo ".ipa source file missing .ipa extension. $USAGE" | |
exit 1 | |
fi | |
if [[ ! ( | |
-f "$PROVISIONING_PROFILE" | |
) ]]; | |
then | |
echo "Provisioning profile cannot be found. $USAGE" | |
exit 1 | |
fi | |
if [[ ! ( | |
"${PROVISIONING_PROFILE##*.}" == "mobileprovision" | |
) ]]; | |
then | |
echo "Provisioning profile missing .mobileprovision extension. $USAGE" | |
exit 1 | |
fi | |
if [[ ! ( | |
-n "$CERTIFICATE_NAME" | |
) ]]; | |
then | |
echo "Certificate name missing. $USAGE" | |
exit 1 | |
fi | |
if [[ ! ( | |
-n "$APP_NAME" | |
) ]]; | |
then | |
echo "App name missing. $USAGE" | |
exit 1 | |
fi | |
if [[ ! ( | |
"${APP_NAME##*.}" == "app" | |
) ]]; | |
then | |
echo "App name missing .app extension. $USAGE" | |
exit 1 | |
fi | |
if [[ ! ( | |
-f "$IPA_DST" | |
) ]]; | |
then | |
echo ".ipa destination file cannot be found. $USAGE" | |
exit 1 | |
fi | |
if [[ ! ( | |
"${IPA_DST##*.}" == "ipa" | |
) ]]; | |
then | |
echo ".ipa destination file missing .ipa extension. $USAGE" | |
exit 1 | |
fi | |
## Exit on use of an uninitialized variable | |
set -o nounset | |
## Exit if any statement returns a non-true return value (non-zero) | |
set -o errexit | |
## Announce commands | |
#set -o xtrace | |
TMP="$(mktemp -d -t ./resign)" | |
CLEANUP_TEMP=0 # Do not remove this line or "set -o nounset" will error on checks below | |
#CLEANUP_TEMP=1 # Uncomment this line if you want this script to clean up after itself | |
cd "$TMP" | |
[[ $CLEANUP_TEMP -ne 1 ]] && echo "Using temp dir: $TMP" | |
unzip -q "$IPA_SRC" | |
echo App has AppID $(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' Payload/*.app/Info.plist) | |
security cms -D -i Payload/$APP_NAME/embedded.mobileprovision > mobileprovision.plist | |
echo "Trying to resign with '$(/usr/libexec/PlistBuddy -c "Print :Name" mobileprovision.plist)', which supports '$(/usr/libexec/PlistBuddy -c "Print :Entitlements:application-identifier" mobileprovision.plist)'" | |
rm -rf Payload/*.app/_CodeSignature Payload/*.app/CodeResources | |
cp "$PROVISIONING_PROFILE" Payload/*.app/embedded.mobileprovision | |
/usr/bin/codesign -f -s "$CERTIFICATE_NAME" --resource-rules Payload/*.app/ResourceRules.plist Payload/*.app | |
zip -qr "$IPA_DST" Payload | |
[[ $CLEANUP_TEMP -eq 1 ]] && rm -rf "$TMP" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment