Last active
May 23, 2022 20:53
-
-
Save teriiehina/9c9c40fd8766c3f32150 to your computer and use it in GitHub Desktop.
Re-sign an IPA given a .mobileprovision and a signing identity
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
#!/usr/bin/env bash | |
if [ "$#" -ne 3 ]; then | |
echo "Usage: $0 ipa_path provisioning_profile_path signing_identity" >&2 | |
exit 1 | |
fi | |
set -e # make the script exit when a command fails. | |
set -u # exit when the script tries to use undeclared variables. | |
IPA_PATH="$1" | |
PROFILE_PATH="$2" | |
SIGNING_IDENTITY="$3" | |
CURRENT_DIR="$(pwd)" | |
IPA_NAME="$(basename -s .ipa ${IPA_PATH})" | |
RESIGNED_IPA_PATH="${CURRENT_DIR}/${IPA_NAME}-resigned.ipa" | |
TMP_DIR="$(date +%s | md5 | base64 | head -c 16)" | |
TMP_PATH="/tmp/resign-ipa-${TMP_DIR}" | |
TMP_PAYLOAD_PATH="${TMP_PATH}/Payload" | |
unzip -q "${IPA_PATH}" -d "${TMP_PATH}/" | |
PLIST_PATH="$(find ${TMP_PAYLOAD_PATH} -name Info.plist)" | |
APP_NAME=$(/usr/libexec/PlistBuddy -c "Print :CFBundleName" ${PLIST_PATH}) | |
rm -rf "${TMP_PAYLOAD_PATH}/${APP_NAME}.app/_CodeSignature" | |
cp "${PROFILE_PATH}" "${TMP_PAYLOAD_PATH}/${APP_NAME}.app/embedded.mobileprovision" | |
codesign --verbose=0 -f -s "${SIGNING_IDENTITY}" "${TMP_PAYLOAD_PATH}/${APP_NAME}.app" | |
cd "${TMP_PATH}" | |
zip -qr "${RESIGNED_IPA_PATH}" "Payload/" | |
cd "${CURRENT_DIR}" | |
rm -Rf "${TMP_PATH}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment