简体   繁体   English

可以从命令行“安装”Xcode .mobileprovision 文件吗?

[英]Can an Xcode .mobileprovision file be 'installed' from the command line?

I'm trying to automate the process of building apps for our clients using bash scripts running on a Mac Mini Server (OSX 10.7).我正在尝试使用在 Mac Mini Server (OSX 10.7) 上运行的 bash 脚本为我们的客户自动化构建应用程序的过程。

My script is based on the spectacularly useful script from github originally posted at https://gist.github.com/949831我的脚本基于 github 上非常有用的脚本,最初发布在https://gist.github.com/949831

I'm building the app using xcodebuild, and then signing and embedding the mobileprovision file using xcrun.我正在使用 xcodebuild 构建应用程序,然后使用 xcrun 签署和嵌入 mobileprovision 文件。

When I do all this with a mobileprovision file I manually installed into Xcode using the GUI (eg double-clicking) it works fine.当我使用 mobileprovision 文件执行所有这些操作时,我使用 GUI(例如双击)手动安装到 Xcode 中,它工作正常。 If I simply try to use a mobileprovision file copied onto the server with SCP it fails (Code Sign error: Provisioning profile '123abc123' can't be found.)如果我只是尝试使用复制到带有 SCP 的服务器上的 mobileprovision 文件,它会失败(代码签名错误:无法找到配置文件“123abc123”。)

Presumably this is because the file isn't 'installed'.大概这是因为该文件未“安装”。

Is there any way to install the mobileprovision file from the terminal?有没有办法从终端安装mobileprovision文件? I'm using SSH so using things such as the 'open' command won't work.我正在使用 SSH,所以使用诸如“打开”命令之类的东西是行不通的。

Thanks!谢谢!

If you don't want to download external dependencies (like Ben did), the following should work in most cases:如果您不想下载外部依赖项(如 Ben 所做的),以下在大多数情况下应该可以工作:

uuid=`grep UUID -A1 -a adhoc.mobileprovision | grep -io "[-A-F0-9]\{36\}"`
cp adhoc.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/$uuid.mobileprovision

Note that a UUID is composed of hexadecimal digits so the correct range is [-A-F0-9] and not [-A-Z0-9] .请注意, UUID 由十六进制数字组成,因此正确的范围是[-A-F0-9]而不是[-A-Z0-9]

Bonus: Download and install profiles奖励:下载并安装配置文件

Using the cupertino tool , the following snippet downloads all your distribution profiles from the Developer Portal and installs them.使用cupertino 工具,以下代码段从Developer Portal 下载您的所有分发配置文件并安装它们。

ios profiles:download:all --type distribution

for file in *.*provision*; do
    uuid=`grep UUID -A1 -a "$file" | grep -io "[-A-F0-9]\{36\}"`
    extension="${file##*.}"
    echo "$file -> $uuid"
    mv -f "$file" ~/Library/MobileDevice/Provisioning\ Profiles/"$uuid.$extension"
done

cupertino (the ios command) can be installed with sudo gem install cupertino . cupertino( ios命令)可以使用sudo gem install cupertino

Since asking this question, I've built a solution myself.自从提出这个问题以来,我自己建立了一个解决方案。 The secret is to simply copy the file to the ~/Library/MobileDevice/Provisioning Profiles/ folder, but (here's the tricky bit) renamed to [The UUID].mobileprovision.秘诀是简单地将文件复制到 ~/Library/MobileDevice/Provisioning Profiles/ 文件夹,但(这里是棘手的部分)重命名为 [UUID].mobileprovision。

The UUID is held inside a text part of the file itself (in a plist). UUID 保存在文件本身的文本部分(在 plist 中)。 Unfortunately, the file also includes binary so 'defaults read' cannot read it.不幸的是,该文件还包含二进制文件,因此“默认读取”无法读取它。 Luckily this guy has built a small command line utility to get the UUID (and some other things out again).幸运的是, 这个家伙已经构建了一个小的命令行实用程序来获取 UUID(以及其他一些东西)。

Here's my full working script:这是我的完整工作脚本:

https://gist.github.com/2568707 https://gist.github.com/2568707

A compendium of all other answers update_provisioning_profile.sh :所有其他答案的概要update_provisioning_profile.sh

#!/bin/sh
#
# Download and install a single iOS provisioning profile
# Requires https://github.com/nomad/cupertino
#
# Usage
# - Login to your account once:
# ios login
# - Configure TEAM and PROFILE (instructions below)
# - Run update_provisioning_profile.sh at anytime, usually after adding/removing devices to the profile

# Configure the team identifier
# Copy it from developer portal or just use cupertino to get it:
# ios devices
# Copy the string in parens and set it as TEAM
TEAM="team id"

# Configure the profile name you want to manage
# Copy it from developer portal or use cupertino to get a list (ignoring Xcode managed profiles):
# ios profiles --team ${TEAM} | grep -v 'iOS Team Provisioning Profile'
# Copy the name as-is and set as PROFILE
PROFILE="profile name"

# Fetch the profile using `cupertino` tool
# you need to run `ios login` once to setup the account
ios profiles:download "${PROFILE}" --team ${TEAM}
PROFILE_FILE=`echo $PROFILE | tr ' ' '_'` # `cupertino` tool will replace spaces with _
UUID=`/usr/libexec/PlistBuddy -c 'Print :UUID' /dev/stdin <<< $(security cms -D -i ${PROFILE_FILE}.mobileprovision)`

# copy where Xcode can find it
cp ${PROFILE_FILE}.mobileprovision "$HOME/Library/MobileDevice/Provisioning Profiles/${UUID}.mobileprovision"

# clean
rm ${PROFILE_FILE}.mobileprovision

Easy to adapt to your provisioning needs.易于适应您的配置需求。

We run our builds in Jenkins and had a similar problem.我们在 Jenkins 中运行我们的构建并遇到了类似的问题。 Our Ad Hoc provisioning profile changes quite often and we don't want to run around to each of our build slaves installing them in xcode every time they change, so here's what I got to work:我们的 Ad Hoc 配置文件经常更改,我们不想在每次更改时都跑到我们的每个构建从属程序中将它们安装在 xcode 中,所以这就是我要做的工作:

/usr/bin/xcrun -sdk iphoneos PackageApplication -v <path to yourapp.app> -o <path to your .ipa file> --sign "<Name of signing identity>" --embed <path to .mobileprovision file>

The "" is what you see under "Code Signing" section in the Build Settings of your target. "" 是您在目标的构建设置中的“代码签名”部分下看到的内容。

Looks like Apple added empty line in the .mobileprovision provisioning profile file below each key-value pair and the grep option doesn't not work anymore.看起来 Apple 在每个键值对下方的 .mobileprovision 配置文件中添加了空行,并且 grep 选项不再起作用。

Here's how to retrieve it with PlistBuddy and security using a python script以下是如何使用 PlistBuddy 和安全性使用 python 脚本检索它

command = "/usr/libexec/PlistBuddy -c 'Print :UUID' /dev/stdin <<< $(security cms -D -i abc.mobileprovision)"
uuid = os.popen(command).readline().rstrip('\n')

Use fastlane sigh to install a particular provisional file or you can create a new one.使用 fastlane sigh 安装特定的临时文件,或者您可以创建一个新文件。

fastlane sigh renew --adhoc -n "provisional-profile-name" --app_identifier "app-identifier" -u "user-name" --ignore_profiles_with_different_name

provisional-profile-name is just name of the profile, doesn't contain the .mobileprovision extension.临时配置文件名称只是配置文件的名称,不包含 .mobileprovision 扩展名。

To create a new adhoc profile with all the device UUIDs added,要使用添加的所有设备 UUID 创建新的临时配置文件,

fastlane sigh --adhoc --app_identifier "app-identifier" -u "username"

Fastfile,快速文件,

lane :build do

sigh(
adhoc: true,
app_identifier: "***APP_ID**",
provisioning_name: "**Profile_name**",
username: "Apple_ID",
force: true,
skip_certificate_verification: true,
)


gym(
#export_options: "exportPlist.plist",
scheme: "**scheme-name**",
export_method: "ad-hoc",
xcargs: "PROVISIONING_PROFILE=$SIGH_UUID",
)
end

It looks like there hasn't been any recent development on cupertino .看起来cupertino上最近没有任何进展。 Fastlane has a tool called sigh to manage provisioning profiles (create, download, renew, repair): https://github.com/fastlane/fastlane/tree/master/sigh#readme Fastlane有一个工具叫sigh来管理供应型材(创建,下载,更新,维修): https://github.com/fastlane/fastlane/tree/master/sigh#readme

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM