分享一个自己写的重签名脚本
使用方法./resign.sh or ./resign.sh [ipa路径] [mobileprovision证书路径]
若无权限 先执行chmod+x resign.sh
demo:
#bin/bash# exit#判断能否是正确的ipa文件isRightIPAFile(){ ipa_file_name=$1 if [ ! -z $ipa_file_name ] then #多加了x,是为了防止字符串为空时报错 if [ ${ipa_file_name##*.}x == "ipa"x ] then return 1 fi fi return 0}#ipa文件路径ipa_path=$1#mobileprovision路径mb_path=$2#判断能否有输入ipa参数 if [ -z $ipa_path ] #不存在then #获取ipa文件路径 ipa_count=`ls | grep ".ipa"|wc -l` if [ $ipa_count != 0 ] then if [ $ipa_count == 1 ] then ipa_path=*.ipa else echo 111 isRightIPAFile $ipa_path while [ $? == 0 ] do echo "请选择需要重签的ipa文件" echo `ls | grep ".ipa"` read ipa_path isRightIPAFile $ipa_path done fi else echo "请输入ipa文件路径" read ipa_path fifi#获取mb文件 (简化过程)if [ -z $mb_path ]then mb_count=`ls | grep ".mobileprovision"|wc -l` echo $mb_count if [ $mb_count != 0 ] then mb_path=*.mobileprovision else echo "请输入mobileprovision文件路径" read mb_path fifi#当前路径current_path=`pwd`#工作路径work_path=${current_path}/worklog_pth=${work_path}/null#假如原工作路径存在 删除if [ -e $work_path ]then echo "删除工作路径" rm -rf $work_pathfi#创立工作路径echo "新创立工作路径"mkdir $work_path#解压ipa文件echo "解压ipa文件"unzip -o $ipa_path -d $work_path > $log_pth#获取apppathapp_path=$(set -- "$work_path/Payload/"*.app;echo "$1")#准备材料 entitlements.plist bundleid teamname#entitlements.plist 路径entitlements_plist_path=${work_path}/"entitlements.plist"#entitlementfull.plist 路径entitlementsfull_plist_path=${work_path}/"entitlements_full.plist"#生成entitlementsfull_plist_pathsecurity cms -D -i ${mb_path} >> $entitlementsfull_plist_path#生成entitlements.plistcat $entitlementsfull_plist_path | sed -n '1,3p' > ${entitlements_plist_path}cat $entitlementsfull_plist_path | sed -n '/<key>Entitlements<\/key>/,/<\/dict>/p' | sed '1d' >> ${entitlements_plist_path}cat $entitlementsfull_plist_path | sed -n '$p' >> ${entitlements_plist_path}#获取teamnameteam_name=`/usr/libexec/PlistBuddy -c "print TeamName" ${entitlementsfull_plist_path}`#获取bundleidfull_bundle_id=`/usr/libexec/PlistBuddy -c "print Entitlements:application-identifier" ${entitlementsfull_plist_path}`bundle_id=${full_bundle_id#*.}#1.替换mb文件cp $mb_path ${app_path}/embedded.mobileprovision#2.替换bundle_id/usr/libexec/PlistBuddy -c "set CFBundleIdentifier ${bundle_id}" ${app_path}/Info.plist#3.重签frammeworkecho "重签framework"framework_path=${app_path}/Frameworks#判断有没有这个文件夹if [ -e $framework_path ]then for f in ${framework_path}/* do codesign -fs "${team_name}" $f donefi#4.重签appecho "重签app"#移除_CodeSignature# rm -rf ${app_path}/_CodeSignaturecodesign -fs "${team_name}" --no-strict --entitlements ${entitlements_plist_path} ${app_path}echo "重签完成"#5.生成ipaecho "生成ipa中请稍等"export_path=${work_path}/new.ipa#压缩文件必需进入到work目录下cd $work_pathzip -ry $export_path Payload > $log_pth#返回原工作路径cd $current_pathrm -rf $log_pthrm -rf ${entitlements_plist_path}rm -rf ${entitlementsfull_plist_path}rm -rf ${work_path}/Payloadecho "完成"open $work_path