用命令行安装mobileprovision和p12证书

作者: shaneZhang 分类: ios技术 发布时间: 2018-12-26 20:35

我这边使用python来编写的,基本达到了最大化程度的解耦,其他人或者其他地方都可以直接使用。先创建installMobileProfile.py

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import commands
import os

paramsCount = len(sys.argv)
if (paramsCount != 5):
    print "本文件只支持以下的四个参数同时配置,缺一不可"
    print "第一个参数:描述文件的路径"
    print "第二个参数:p12文件的路径"
    print "第三个参数:操作系统用户的密码"
    print "第四个参数:p12文件的密码"
    exit()

mobileProfilePath=sys.argv[1]
p12filePath = sys.argv[2]
password = sys.argv[3]
cert_Pass = sys.argv[4]
print 'params is:' + mobileProfilePath + ' p12:' + p12filePath + ' pass:' + password + ' cert_Pass:' + cert_Pass

shellCommod = "grep UUID -A1 -a " + mobileProfilePath + "| grep -io '[-A-F0-9]\{36\}'"
UUID = commands.getoutput(str(shellCommod))
print "uuid is:" + UUID
homePath = commands.getoutput("echo ~")
output=str(homePath+"/Library/MobileDevice/Provisioning Profiles/"+UUID+".mobileprovision")
output1=str(homePath+"/Library/MobileDevice/Provisioning\ Profiles/"+UUID+".mobileprovision")
print output
if os.path.isfile(output):
    print "file is founded"
    print "install finished"
else:
    print "file not found"
    cp_commod = str("cp " + mobileProfilePath + " " + output1)
    print cp_commod
    print "copying file from "+mobileProfilePath+" to "+output1
    os.system(cp_commod)
    print "install finished"
    os.system("ls ~/Library/MobileDevice/Provisioning\ Profiles/")


#install p12 file
keychain_Path = str(homePath+"/Library/Keychains/login.keychain")
sh1 = str("security default-keychain -s " + keychain_Path)
print "shell1 is:" + sh1
os.system(sh1)
sh2 = str("security unlock-keychain -p " + password + ' ' + keychain_Path)
print "shell2 is:" + sh2
os.system(sh2)
sh3 = str("security import " + p12filePath + " -k " + keychain_Path + ' -P ' + cert_Pass)
print "shell3 is:" + sh3
result = commands.getoutput(sh3)
print result

本页面支持繁体中文友好显示:用命令行安装mobileprovision和p12证书

如果觉得我的文章对您有用,请随意打赏。如果有其他问题请联系博主QQ(909491009)或者下方留言!

发表回复