分享一個(gè)自己寫(xiě)的重簽名腳本
使用方法./resign.sh or ./resign.sh [ipa路徑] [mobileprovision證書(shū)路徑]
若無(wú)權(quán)限 先執(zhí)行chmod+x resign.sh
demo:
#bin/bash
# exit
#判斷是否是正確的ipa文件
isRightIPAFile(){
ipa_file_name=$1
if [ ! -z $ipa_file_name ]
then
#多加了x,是為了防止字符串為空時(shí)報(bào)錯(cuò)
if [ ${ipa_file_name##*.}x == "ipa"x ]
then
return 1
fi
fi
return 0
}
#ipa文件路徑
ipa_path=$1
#mobileprovision路徑
mb_path=$2
#判斷是否有輸入ipa參數(shù)
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 "請(qǐng)選擇需要重簽的ipa文件"
echo `ls | grep ".ipa"`
read ipa_path
isRightIPAFile $ipa_path
done
fi
else
echo "請(qǐng)輸入ipa文件路徑"
read ipa_path
fi
fi
#獲取mb文件 (簡(jiǎn)化過(guò)程)
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 "請(qǐng)輸入mobileprovision文件路徑"
read mb_path
fi
fi
#當(dāng)前路徑
current_path=`pwd`
#工作路徑
work_path=${current_path}/work
log_pth=${work_path}/null
#如果原工作路徑存在 刪除
if [ -e $work_path ]
then
echo "刪除工作路徑"
rm -rf $work_path
fi
#創(chuàng)建工作路徑
echo "新創(chuàng)建工作路徑"
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")
#準(zhǔn)備材料 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
#判斷有沒(méi)有這個(gè)文件夾
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中請(qǐng)稍等"
export_path=${work_path}/new.ipa
#壓縮文件必須進(jìn)入到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