You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
5.1 KiB

1 month ago
# !/bin/bash
set -e
A1_Cert[0]='2C74981D1576F9502198F77282E4A7ECBD8A81A0 "iPhone Developer: Created via API (JDPXHYVWYZ)"'
A1_Cert_Name[0]="iPhone Developer: Created via API (JDPXHYVWYZ)"
A1_Provision[0]=com.tencent.baiye_Development_SignProvision.mobileprovision
A1_Cert_Alias[0]="baiye"
echo "\033[30m _____检查证书开始_____ \033[0m"
for((i=0;i<${#A1_Cert[@]};i++))
do
echo ${A1_Cert[i]}
security find-identity -v -p codesigning | grep "${A1_Cert[i]}"
if [ $? -eq 0 ];then
echo "\033[36m ${A1_Cert[i]} alreay installed...\033[0m"
else
echo "\033[35m ${A1_Cert[i]} not installed,please install it...\033[0m"
return -1
fi
done
echo "\033[32m打包所需证书都已经正确安装\033[0m"
echo "\033[30m _____检查证书结束_____ \033[0m"
echo "\033[30m _____签名开始_____ \033[0m"
#需要重签名的ipa,jenkins打包请为此赋值
SOURCE_IPA=srpg.ipa
#工作文件夹,需要放置证书文件和ipa文件
CURRENT_PATH=$(cd `dirname $0`;pwd)
#需要替换的文件夹,用来替换到ipa包中的文件
IOS_PATH="${CURRENT_PATH}/IOSFiles"
#临时文件夹,用来存储中间文件
TEMP_PATH="${CURRENT_PATH}/Temp"
#递归进行替换的函数,进行递归查找,然后替换IOS_PATH中的文件
repalce_lua_file(){
for file in $1/*@$2
do
if [ -e $file ]
then
echo "$IOS_PATH/$2" "$file"
cp "$IOS_PATH/$2" "$file"
fi
done
for file in `ls $1`
do
if [ -d $1"/"$file ]
then
repalce_lua_file $1"/"$file $2
fi
done
}
repalce_file(){
for file in $1/$2
do
if [ -e $file ]
then
echo "$IOS_PATH/$2" "$file"
cp "$IOS_PATH/$2" "$file"
fi
done
for file in `ls $1`
do
if [ -d $1"/"$file ]
then
repalce_file $1"/"$file $2
fi
done
}
# 用证书数组进行重签,可进行多证书签名
#----------------------------------------
for((i=0;i<${#A1_Cert[@]};i++))
do
#报告是哪一个证书正在重签名
echo "${A1_Cert_Alias[i]}在重签名${SOURCE_IPA}"
#----------------------------------------
# 1. 解压IPA到Temp下
#清空Temp文件夹再重新创建Temp文件夹
rm -rf "${TEMP_PATH}"
mkdir -p "${TEMP_PATH}"
echo "解压中,请稍等……"
unzip -oq "${CURRENT_PATH}/$SOURCE_IPA" -d "$TEMP_PATH"
echo "解压完成"
# 拿到解压的临时的APP的路径
TEMP_APP_PATH=$(set -- "$TEMP_PATH/Payload/"*.app;echo "$1")
#----------------------------------------
# 2. 删除extension和WatchAPP.个人证书没法签名Extention,删除原有的证书文件
rm -rf "$TEMP_APP_PATH/PlugIns"
rm -rf "$TEMP_APP_PATH/Watch"
rm -rf "$TEMP_APP_PATH/_CodeSignature"
# 3.拷贝新的mobileprovision文件进来
rm -rf "$TEMP_APP_PATH/embedded.mobileprovision"
cp "${CURRENT_PATH}/${A1_Provision[i]}" "$TEMP_APP_PATH/embedded.mobileprovision"
# 4. 替换app中的文件
for file in `ls $IOS_PATH/*.luac`
do
repalce_lua_file $TEMP_APP_PATH $(basename ${file})
done
for file in `ls $IOS_PATH/*.*`
do
repalce_file $TEMP_APP_PATH $(basename ${file})
done
#----------------------------------------
# todo:5.更新文件
#. 更新info.plist文件 CFBundleIdentifier
# 设置:"Set : KEY Value" "目标文件路径"
#PRODUCT_BUNDLE_IDENTIFIER=matchsrpg
#/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $PRODUCT_BUNDLE_IDENTIFIER" "$TEMP_APP_PATH/Info.plist"
# 给MachO文件上执行权限
# 拿到MachO文件的路径
#APP_BINARY=`plutil -convert xml1 -o - $TEMP_APP_PATH/Info.plist|grep -A1 Exec|tail -n1|cut -f2 -d\>|cut -f1 -d\<`
#上可执行权限
#chmod +x "$TEMP_APP_PATH/$APP_BINARY"
#----------------------------------------
# 6. 重签名,包括重签名第三方文件
find -d $TEMP_APP_PATH \( -name "*.app" -o -name "*.appex" -o -name "*.framework" -o -name "*.dylib" \) > "${CURRENT_PATH}/directories.txt"
security cms -D -i "$TEMP_APP_PATH/embedded.mobileprovision" > "${CURRENT_PATH}/t_entitlements_full.plist"
/usr/libexec/PlistBuddy -x -c 'Print:Entitlements' "${CURRENT_PATH}/t_entitlements_full.plist" > "${CURRENT_PATH}/t_entitlements.plist"
while IFS='' read -r line || [[ -n "$line" ]]; do
/usr/bin/codesign --continue --deep -f -s "${A1_Cert_Name[i]}" --entitlements "${CURRENT_PATH}/t_entitlements.plist" "$line"
done < "${CURRENT_PATH}/directories.txt"
#--------------------------------------
# 7.重新压缩成ipa文件,生成到当前文件夹CURRENT_PATH下
echo "生成ipa中,请稍等……"
cd $TEMP_PATH
zip -qr "${CURRENT_PATH}/${A1_Cert_Alias[i]}_${SOURCE_IPA}" *
#将上传脚本放在此处,ipa路径为"${CURRENT_PATH}/${A1_Cert_Alias[i]}_${SOURCE_IPA}"
cd ${CURRENT_PATH}
echo "\033[5;32m${A1_Cert_Alias[i]}重签名完成....\033[0m\n"
rm -rf "${TEMP_PATH}"
rm -rf "${CURRENT_PATH}/t_entitlements_full.plist"
rm -rf "${CURRENT_PATH}/t_entitlements.plist"
rm -rf "${CURRENT_PATH}/directories.txt"
done