Skip to content

Instantly share code, notes, and snippets.

@hjeffrey
Created July 20, 2015 14:11
Show Gist options
  • Save hjeffrey/b87d0059338f77ab05ff to your computer and use it in GitHub Desktop.
Save hjeffrey/b87d0059338f77ab05ff to your computer and use it in GitHub Desktop.
Resign ipa.
#!/bin/sh
#
# resign.sh
#
# Created by Jia Yuhui on 08/07/2015.
# Copyright 2015 Jia Yuhui. All rights reserved.
currentPath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CERTIFICATE="iPhone Developer: xxx (xxxxxxxx)" # must be in keychain
cd $currentPath
PROVISIONS=$(find $currentPath -name '*.mobileprovision' -maxdepth 1)
if [ -z "$PROVISIONS" ]; then
echo "不存在 .mobileprovision 文件"
exit 0
fi
echo "开始重新签名 ipa 文件"
for file in $PROVISIONS; do
if [ -f "$file" ]; then
PROVISION=$file
else
echo '!!错误: ${file} 不存在'
fi
done
ipaFiles=$(find $currentPath -name '*.ipa' -maxdepth 1)
if [ -z "$ipaFiles" ]; then
echo "不存在 ipa 文件"
exit 0
fi
for item in $ipaFiles; do
echo $item
if [ -f "$item" ]; then
# unzip the ipa
unzip -q "$item"
# remove the signature
rm -rf Payload/*.app/_CodeSignature Payload/*.app/CodeResources
# replace the provision
cp "$PROVISION" Payload/*.app/embedded.mobileprovisio
cp "ResourceRules.plist" Payload/*.app/ResourceRules.plist
# sign with the new certificate (--resource-rules has been deprecated OS X Yosemite (10.10), it can safely be removed)
#/usr/bin/codesign -f -s "$CERTIFICATE" --resource-rules Payload/*.app/ResourceRules.plist Payload/*.app
/usr/bin/codesign -f -s "$CERTIFICATE" Payload/*.app/ResourceRules.plist Payload/*.app
if [[ $? != 0 ]]; then
echo '!!签名错误'
exit 1
fi
# zip it back up
zip -qr ${item}_resigned.ipa Payload
rm -rf Payload
else
echo "!!错误: "$item"不存在"
fi #if [ -f "$item" ]; then
done #for item in $ipaFiles; do
echo '完成重新签名'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment