使用shell判断描述文件mobileprovision属于de
2019-09-22 本文已影响0人
独孤流
Shell系列上一篇:使用Shell判断钥匙串里是否包含mobileprovision里的Identity
参考:
前言
在iOS开发中,
账号分别为:
企业账号(in-house),个人开发者、公司开发者三种类型,
对应的打包证书有:
1、开发证书(三种开发账号都可以)、
2、ad-hoc证书(三种开发账号都可以)、
3、企业证书(只有企业账号可以)、
4、AppStore证书(只要个人账号和公司账号可以)几类不同的证书有不同的描述文件,通过描述文件里的
ProvisionedDevices
(debug、adhoc独有),
Entitlements.get-task-allow
(ad-hoc为false),
ProvisionsAllDevices
(企业证书独有)
这些字段判断出描述文件的类型,完整demo如下:
method: -- enterprise ad-hoc appstore develepment
# !/bin/bash
function findtype()
{
#接收参数,也就是xxx.mobileprovision的路径
profile_path=$1
#临时将xxx.mobileprovision转换成plist文件路径
temp_plist_path="./temp_profile.plist"
#删除之前存在的plist文件
rm -rf $temp_plist_path
#将xxx.mobileprovision转换成xxx.plist
security cms -D -i "$profile_path" > $temp_plist_path
#ad-hoc、debug独有
ProvisionedDevices=$(/usr/libexec/PlistBuddy -c "print ProvisionedDevices" $temp_plist_path)
ProvisionedDevices_txt_len=${#ProvisionedDevices}
if [ $ProvisionedDevices_txt_len -gt 0 ]; then
# echo "debug --- adhoc"
get_task_allow=$(/usr/libexec/PlistBuddy -c "print Entitlements:get-task-allow" $temp_plist_path)
if [ $get_task_allow == "false" ]; then
echo "ad-hoc"
return 1
else
echo "develepment"
return 2
fi
else
#enterprise 独有
ProvisionsAllDevices=$(/usr/libexec/PlistBuddy -c "print ProvisionsAllDevices" $temp_plist_path)
ProvisionsAllDevices_txt_len=${#ProvisionsAllDevices}
# echo "enterprise --appstore"
#true=4 false=5
if [ $ProvisionsAllDevices_txt_len -gt 0 -a $ProvisionsAllDevices_txt_len == 4 ]; then
echo "enterprise"
return 3
else
echo "appstore"
return 4
fi
fi
}
type_txt=`findtype "/xxx/xxx.mobileprovision"`
echo $type_txt
type_txt2=`findtype "/xxxx/xxx/xx.mobileprovision"`
echo $type_txt2
type_txt3=`findtype "/xxx/xxx.mobileprovision"`
echo $type_txt3
type_txt4=`findtype "/xxxx/xxx.mobileprovision"`
echo $type_txt4
分别用四种描述文件打印结果如下:
$ sh test.sh
ad-hoc
Print: Entry, "ProvisionedDevices", Does Not Exist
enterprise
debug
Print: Entry, "ProvisionedDevices", Does Not Exist
Print: Entry, "ProvisionsAllDevices", Does Not Exist
appstore
二、通过描述文件生成导出的ExportOption.plist文件
# !/bin/bash
function read_info_mobileprovision()
{
#接收参数,也就是xxx.mobileprovision的路径
profile_path=$1
#临时将xxx.mobileprovision转换成plist文件路径
temp_plist_path="./temp_profile.plist"
#删除之前存在的plist文件
rm -rf $temp_plist_path
#将xxx.mobileprovision转换成xxx.plist
security cms -D -i "$profile_path" > $temp_plist_path
inter_temp_varFile=$2
rm -rf $inter_temp_varFile
#2.3 读取信息
#证书持有者机构
config_TeamName=$(/usr/libexec/PlistBuddy -c "print TeamName" $temp_plist_path)
echo "config_TeamName='${config_TeamName}'" >> $inter_temp_varFile
#证书持有者组Id
config_teamId=$(/usr/libexec/PlistBuddy -c "print :Entitlements:com.apple.developer.team-identifier" $temp_plist_path)
echo "config_teamId='${config_teamId}'" >> $inter_temp_varFile
#bundleId
config_identifier=$(/usr/libexec/PlistBuddy -c "print :Entitlements:application-identifier" $temp_plist_path)
config_identifier_cut="${config_teamId}."
config_identifier=${config_identifier#*$config_identifier_cut}
echo "config_identifier='${config_identifier}'" >> $inter_temp_varFile
#发布证书名称
config_disName=$(/usr/libexec/PlistBuddy -c "print Name" $temp_plist_path)
echo "config_disName='${config_disName}'" >> $inter_temp_varFile
#描述文件UUID
config_uuid=$(/usr/libexec/PlistBuddy -c "print UUID" $temp_plist_path)
echo "config_uuid='${config_uuid}'" >> $inter_temp_varFile
#过期时间
config_expirationDate=$(/usr/libexec/PlistBuddy -c "print ExpirationDate" $temp_plist_path)
echo "config_expirationDate='${config_expirationDate}'" >> $inter_temp_varFile
#method: -- enterprise ad-hoc appstore develepment
#ad-hoc、debug独有
ProvisionedDevices=$(/usr/libexec/PlistBuddy -c "print ProvisionedDevices" $temp_plist_path)
ProvisionedDevices_txt_len=${#ProvisionedDevices}
if [ $ProvisionedDevices_txt_len -gt 0 ]; then
# echo "debug --- adhoc"
get_task_allow=$(/usr/libexec/PlistBuddy -c "print Entitlements:get-task-allow" $temp_plist_path)
if [ $get_task_allow == "false" ]; then
echo "ad-hoc"
echo "config_method='ad-hoc'" >> $inter_temp_varFile
else
echo "debug"
echo "config_method='develepment'" >> $inter_temp_varFile
fi
else
#enterprise 独有
ProvisionsAllDevices=$(/usr/libexec/PlistBuddy -c "print ProvisionsAllDevices" $temp_plist_path)
ProvisionsAllDevices_txt_len=${#ProvisionsAllDevices}
# echo "enterprise --appstore"
#true=4 false=5
if [ $ProvisionsAllDevices_txt_len -gt 0 -a $ProvisionsAllDevices_txt_len == 4 ]; then
echo "enterprise"
echo "config_method='enterprise'" >> $inter_temp_varFile
else
echo "appstore"
echo "config_method='appstore'" >> $inter_temp_varFile
fi
fi
}
#证书类型
tempVarFile="./temp_var.txt"
#测试adhoc
# mobile_provision_path="/xx/xxxx/xxx.mobileprovision"
#测试dubug
# mobile_provision_path="/xx/xxxx/xxx.mobileprovision"
#测试enterprise
# mobile_provision_path="/xx/xxxx/xxx.mobileprovision"
#测试appstore
mobile_provision_path="/xx/xxxx/xxx.mobileprovision"
read_info_mobileprovision $mobile_provision_path $tempVarFile
cat $tempVarFile
source $tempVarFile
#method: -- enterprise ad-hoc appstore develepment
#2.6、生成plist
cat > "./ExportOptions.plist" << END_TEXT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>compileBitcode</key>
<true/>
<key>destination</key>
<string>export</string>
<key>method</key>
<string>${config_method}</string>
<key>provisioningProfiles</key>
<dict>
<key>${config_identifier}</key>
<string>${config_disName}</string>
</dict>
<key>signingCertificate</key>
<string>iPhone Distribution</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>${config_teamId}</string>
<key>thinning</key>
<string><none></string>
</dict>
</plist>
END_TEXT