在 bash 中解析 mobileprovision 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6398364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:12:20  来源:igfitidea点击:

Parsing mobileprovision files in bash?

iphonebashshellplistadhoc

提问by egiray

I am tying building a php/bash/mysql system for automating adhoc distribution for iPhone apps. But I want to read the application-identifier key in mobileprovision file of projects and change it info.plist file according to that.

我正在构建一个 php/bash/mysql 系统,用于自动为 iPhone 应用程序进行临时分发。但是我想读取项目的 mobileprovision 文件中的 application-identifier 键并根据它更改 info.plist 文件。

I can currently build ipa files from php IF the cfbundleidentifer key is same as its provision file.

如果 cfbundleidentifer 密钥与其配置文件相同,我目前可以从 php 构建 ipa 文件。

I found a code like this https://gist.github.com/711794but I want bash script to integrate it to my system.

我找到了这样的代码https://gist.github.com/711794但我希望 bash 脚本将它集成到我的系统中。

Thanks

谢谢

回答by jlawrie

If your running this on a machine with mac os x, you can use the following:

如果您在装有 mac os x 的机器上运行它,您可以使用以下命令:

/usr/libexec/PlistBuddy -c 'Print :Entitlements:application-identifier' /dev/stdin <<< $(security cms -D -i path_to_mobileprovision)

回答by olivierypg

If you want to extract the plist from the mobileprovision in a proper way and not rely on grepping/sedding/etc., you can use OpenSSL as follow:

如果您想以适当的方式从 mobileprovision 中提取 plist 并且不依赖于 grepping/sedding/等,您可以使用 OpenSSL,如下所示:

openssl smime -inform der -verify -noverify -in file.mobileprovision

A complete example in your case could be:

您的情况的完整示例可能是:

openssl smime -inform der -verify -noverify -in file.mobileprovision > tmp.plist
/usr/libexec/PlistBuddy -c 'Print :Entitlements:application-identifier' tmp.plist

The OpenSSL part should work on any platform, although I've only done that on a Mac so far. PlistBuddy is only on Mac, but other utilities can be found to read/write property list files.

OpenSSL 部分应该适用于任何平台,尽管到目前为止我只在 Mac 上做过。PlistBuddy 仅在 Mac 上可用,但可以找到其他实用程序来读/写属性列表文件。

回答by hyperknot

I created a bash function based on jlawrie's answer to list all .mobileprovision's bundle IDs from the ~/Library/MobileDevice/Provisioning Profilesfolder.

我根据 jlawrie 的回答创建了一个 bash 函数,以列出~/Library/MobileDevice/Provisioning Profiles文件夹中所有 .mobileprovision 的捆绑 ID 。

Save this into your .bash_profileand just call it with list_xcode_provisioning_profilesfrom a terminal.

将其保存到您的文件中.bash_profile,然后list_xcode_provisioning_profiles从终端调用它。

list_xcode_provisioning_profiles() {
    while IFS= read -rd '' f; do
        2> /dev/null /usr/libexec/PlistBuddy -c 'Print :Entitlements:application-identifier' /dev/stdin \
            <<< $(security cms -D -i "$f")

    done < <(find "$HOME/Library/MobileDevice/Provisioning Profiles" -name '*.mobileprovision' -print0)
}

回答by dneff

One solution among many...

众多解决方案中的一种...

Use egrep with the -a option, which treats binary files like text files and '-A 2' which will display the two lines after the string you want to match: ApplicationIdentifierPrefix.

使用带有 -a 选项的 egrep,它将二进制文件视为文本文件,'-A 2' 将显示您要匹配的字符串后的两行:ApplicationIdentifierPrefix。

After that, trim the line of brackets and whitespace using sed.

之后,使用 sed 修剪括号行和空格。

Using a series of pipes:

使用一系列管道:

egrep -a -A 2 ApplicationIdentifierPrefix file.mobileprovision | grep string | sed -e 's/<string>//' -e 's/<\/string>//' -e 's/ //'

回答by tc.

It is mildly tedious, since a .mobileprovision is "PKCS #7 signed data" or so.

这有点乏味,因为 .mobileprovision 是“PKCS #7 签名数据”左右。

Fortunately, you can probably get away with using grep :)

幸运的是,您可能可以使用 grep 逃脱:)

回答by chrish

I used the code from mobileprovision-readrepository to be able to pull information from the mobileprovision file. This uses macOS APIs to read the file.

我使用了mobileprovision-read存储库中的代码,以便能够从 mobileprovision 文件中提取信息。这使用 macOS API 来读取文件。

Here is the usage from running the generated program:

这是运行生成的程序的用法:

mobileprovision-read -- mobileprovision files querying tool.

USAGE
mobileprovision-read -f fileName [-o option]

OPTIONS
    type – prints mobileprovision profile type (debug, ad-hoc, enterprise, appstore)
    appid – prints application identifier
Will print raw provision's plist if option is not specified.
You can also use key path as an option.

EXAMPLES
mobileprovision-read -f test.mobileprovision -o type
    Prints profile type

mobileprovision-read -f test.mobileprovision -o UUID
    Prints profile UUID

mobileprovision-read -f test.mobileprovision -o ProvisionedDevices
    Prints provisioned devices UDIDs

mobileprovision-read -f test.mobileprovision -o Entitlements.get-task-allow
    Prints 0 if profile doesn't allow debugging 1 otherwise