分享一个自己写的重签名脚本
使用方法./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
fi
fi
#获取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
fi
fi
#当前路径
current_path=`pwd`
#工作路径
work_path=${current_path}/work
log_pth=${work_path}/null
#如果原工作路径存在 删除
if [ -e $work_path ]
then
echo "删除工作路径"
rm -rf $work_path
fi
#创建工作路径
echo "新创建工作路径"
mkdir $work_path
#解压ipa文件
echo "解压ipa文件"
unzip -o $ipa_path -d $work_path > $log_pth
#获取apppath
app_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_path
security cms -D -i ${mb_path} >> $entitlementsfull_plist_path
#生成entitlements.plist
cat $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}
#获取teamname
team_name=`/usr/libexec/PlistBuddy -c "print TeamName" ${entitlementsfull_plist_path}`
#获取bundleid
full_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.重签frammework
echo "重签framework"
framework_path=${app_path}/Frameworks
#判断有没有这个文件夹
if [ -e $framework_path ]
then
for f in ${framework_path}/*
do
codesign -fs "${team_name}" $f
done
fi
#4.重签app
echo "重签app"
#移除_CodeSignature
# rm -rf ${app_path}/_CodeSignature
codesign -fs "${team_name}" --no-strict --entitlements ${entitlements_plist_path} ${app_path}
echo "重签完成"
#5.生成ipa
echo "生成ipa中请稍等"
export_path=${work_path}/new.ipa
#压缩文件必须进入到work目录下
cd $work_path
zip -ry $export_path Payload > $log_pth
#返回原工作路径
cd $current_path
rm -rf $log_pth
rm -rf ${entitlements_plist_path}
rm -rf ${entitlementsfull_plist_path}
rm -rf ${work_path}/Payload
echo "完成"
open $work_path