Created
April 9, 2012 22:08
-
-
Save madoke/2346915 to your computer and use it in GitHub Desktop.
Bash script to replace CodeSignature on an Ad-Hoc / Apple IPA 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 | |
EXPECTED_ARGS=3 | |
E_BADARGS=-1 | |
CERTIFICATE_NAME="iPhone Distribution: MY_CERTIFICATE_NAME" | |
#verify correct usage | |
if [ $# -ne $EXPECTED_ARGS ] | |
then | |
echo "Usage: `basename $0` file_to_resign provisioning_profile package_name" | |
exit $E_BADARGS | |
fi | |
FILENAME=$(basename $1) | |
PROVISIONING_PROFILE=$(basename $2) | |
APPNAME=$(basename "$3") | |
echo "Resigning $FILENAME with $PROVISIONING_PROFILE provisioning profile..." | |
#clear temporary dir if exists | |
rm -rf Payload; | |
#make temporary dir | |
mkdir $TEMPDIR; | |
echo "-> Extracting ipa to $TEMPDIR" | |
unzip $FILENAME > /dev/null | |
echo "-> Removing the old CodeSignature in Payload/$APPNAME/_CodeSignature and Payload/$APPNAME/CodeResources" | |
rm -r "Payload/$APPNAME/_CodeSignature" "Payload/$APPNAME/CodeResources" 2> /dev/null | true | |
echo "-> Replacing the provisioning profile in Payload/$APPNAME/embedded.mobileprovision with $PROVISIONING_PROFILE" | |
cp $PROVISIONING_PROFILE "Payload/$APPNAME/embedded.mobileprovision" | |
echo "-> Re-Signing application" | |
/usr/bin/codesign -f -s "$CERTIFICATE_NAME" --resource-rules "Payload/$APPNAME/ResourceRules.plist" --entitlements "Payload/$APPNAME/Entitlements.plist" "Payload/$APPNAME" | |
echo "-> Packaging the new application" | |
zip -qr "$APPNAME".resigned.ipa "Payload" | |
#lear temporary dir | |
#rm -rf $TEMPDIR; | |
echo "Created $APPNAME.resigned.ipa" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment