Created
January 24, 2014 05:31
-
-
Save comuttun/8592479 to your computer and use it in GitHub Desktop.
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
MYDIR=$(cd $(dirname $0) && pwd) | |
IPA="$1" | |
PROVISION="$2" | |
CERTIFICATE="$3" | |
usage() { | |
echo "Usage: $0 <ipa file> <provision profile> <certificate name>" >&2 | |
exit 99 | |
} | |
if [ -z "$IPA" ]; then | |
usage | |
fi | |
if [ -z "$PROVISION" ]; then | |
usage | |
fi | |
if [ -z "$CERTIFICATE" ]; then | |
usage | |
fi | |
if [ ! -f "$IPA" ]; then | |
echo "ERROR: ipa file '$IPA' not found" >&2 | |
usage | |
fi | |
if [ ! -f "$PROVISION" ]; then | |
echo "ERROR: Provision file '$PROVISION' not found" >&2 | |
usage | |
fi | |
WORKDIR=$(mktemp -d /tmp/resign.XXXXXX) | |
if [ $? -ne 0 ] || [ ! -d "$WORKDIR" ]; then | |
echo "ERROR: Cannot create temporary directory" >&2 | |
exit 1 | |
fi | |
unzip -q "$IPA" -d $WORKDIR | |
if [ $? -ne 0 ]; then | |
echo "ERROR: Cannot unzip ipa to directory" >&2 | |
exit 1 | |
fi | |
# remove the signature | |
rm -rf $WORKDIR/Payload/*.app/_CodeSignature $WORKDIR/Payload/*.app/CodeResources | |
# replace the provision | |
cp -p "$PROVISION" $WORKDIR/Payload/*.app/embedded.mobileprovision | |
if [ $? -ne 0 ]; then | |
echo "ERROR: Cannot replace provision file" >&2 | |
exit 1 | |
fi | |
# sign with the new certificate | |
/usr/bin/codesign -f -s "$CERTIFICATE" --resource-rules $WORKDIR/Payload/*.app/ResourceRules.plist $WORKDIR/Payload/*.app | |
if [ $? -ne 0 ]; then | |
echo "ERROR: Cannot resign with certificate '$CERTIFICATE'" >&2 | |
exit 1 | |
fi | |
# zip it back up | |
resigned_ipa="$MYDIR"/${IPA%.ipa}-resigned.ipa | |
(cd $WORKDIR && zip -qr $resigned_ipa Payload) | |
if [ $? -ne 0 ]; then | |
echo "ERROR: Cannot create resigned ipa" >&2 | |
exit 1 | |
fi | |
rm -rf $WORKDIR | |
echo "SUCCESS: Resigned ipa is successfully out to $resigned_ipa" >&2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment