Skip to content

Instantly share code, notes, and snippets.

@mluton
Forked from idy/re-sign-ipa.sh
Last active April 19, 2016 17:24
Show Gist options
  • Save mluton/527de3f78bfa223334e7 to your computer and use it in GitHub Desktop.
Save mluton/527de3f78bfa223334e7 to your computer and use it in GitHub Desktop.
Use codesign re-sign swift app
#!/bin/sh
# Usage: ./sign.sh INPUT.ipa OUTPUT PROVISION.mobileprovision IDENTITY_NAME ENTITLEMENTS BUNDLEID
# Reading parameters
INPUT=$1
OUTPUT=$2.ipa
MOBILE_PROVISTION=$3
CER_NAME=$4
ENTITLEMENTS=$5
BUNDLEID=$6
# Cleaning working env
rm -r Payload SwiftSupport
# Unpackaging app
unzip -q $INPUT
APP=`ls Payload | tail -1`
rm -rf Payload/$APP/_CodeSignature Payload/$APP/CodeResources
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $BUNDLEID" ./Payload/$APP/Info.plist
# Replacing mobile provision
echo "Deleting original embedded.mobileprovision"
rm "Payload/$APP/embedded.mobileprovision"
echo "Copying embedded.mobileprovision"
cp "$MOBILE_PROVISTION" "Payload/$APP/embedded.mobileprovision"
# Resigning ipa
echo "Re-sign by $CER_NAME"
# Resigning dylibs
if [ -e Payload/$APP/Frameworks ]
then
for dylib in "Payload/$APP/Frameworks/*"
do
codesign -f -s "$CER_NAME" $dylib
done
fi
# Resigning app
codesign -f -s "$CER_NAME" --entitlements $ENTITLEMENTS "Payload/$APP"
# Cleaning output env
rm -r "$OUTPUT"
# Packaging ipa
echo "Packaging ipa"
zip -qr "$OUTPUT" Payload
echo "Re-signed ipa $OUTPUT"
@mluton
Copy link
Author

mluton commented Nov 12, 2015

  • Added the --entitlements option to the codesign step.
  • Added a step to remove _CodeSignature and CodeResources.
  • Added step to set new bundle ID.

This worked for me to resign an .ipa with my own credentials (and bundle ID) including embedded Swift libraries which each need to signed individually.

@ernishant11
Copy link

Hi mluton can you help me? I am not able to use this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment