简介
最近有 ipa 包的重签需求,在此记录一下
shell 脚本
#重签路径
sign_path=$1
#需要重签的 ipa 路径
ipa=$2
cd $sign_path
#替换 pp 文件名
provisioningProfile='xxxxx.mobileprovision'
#替换 team id
distributionCertificate='iPhone Distribution: XXXXX'
#替换 bundleid
bundleIdentifier="com.xxxx.xxxx"
echo "解压缩 ipa ********** "
unzip -q "$ipa"
cd Payload
declare -a appsInPayload=()
appsInPayload=$(find . -name '*app' | sed 's|^\./||')
cd ..
if [[ ${#appsInPayload[*]} -gt 1 ]]; then
echo "Payload 中不止包含 1 个.app 文件 **********/ (${appsInPayload[*]})"
echo -e "重签失败 **********"
exit 1
fi
app=$appsInPayload
echo -e"删除原有的 _CodeSignature**********"
rm -r -f Payload/"$app"/_CodeSignature
echo -e"解密 pp 文件**********"
security cms -D -i "$provisioningProfile" > ProvisioningProfile.plist 2>&1
/usr/libexec/PlistBuddy -x -c 'Print Entitlements' ProvisioningProfile.plist > Entitlements.plist 2>&1
echo -e"将新的 pp 文件拷贝到 app 中 ********** "
cp "$provisioningProfile" Payload/"$app"/embedded.mobileprovision
if [[ -n $bundleIdentifier ]]; then
/usr/libexec/PlistBuddy -x -c "Set :CFBundleIdentifier $bundleIdentifier" Payload/"$app"/Info.plist
else
echo ""
fi
echo -e"重签所有的动态库 **********"
if [[ -e Payload/$app/Frameworks ]]; then
cd Payload/"$app"/Frameworks
swiftLibraries=$(find . -name '*dylib')
SDK_PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/"
for dylib in $swiftLibraries; do
codesign -f -s "$distributionCertificate" "$dylib"
done
frameworks=$(find . -name '*framework')
for framework in $frameworks; do
codesign -f -s "$distributionCertificate" "$framework"
done
cd ../../..
fi
codesign -f -s "$distributionCertificate" --entitlements Entitlements.plist Payload/"$app"
echo "重新生成 ipa 文件 **********"
zip -q -r resigh.ipa Payload SwiftSupport Symbols
echo -e "重签完成 **********"