在 bash 中解析 mobileprovision 文件?

Posted

技术标签:

【中文标题】在 bash 中解析 mobileprovision 文件?【英文标题】:Parsing mobileprovision files in bash? 【发布时间】:2011-06-18 19:24:54 【问题描述】:

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

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

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

谢谢

【问题讨论】:

提出问题通常有助于获得答案。你想要什么? 我读过比这更糟糕的问题。我认为@egray 是在询问如何“读取项目的mobileprovision 文件中的应用程序标识符键并将其更改为info.plist 文件”。诚挚的! 【参考方案1】:

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

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

【讨论】:

哦!感谢security cms -D -i path_to_mobileprovision 的提示!我之前收到了很多 Unexpected character 0 at line 1 错误【参考方案2】:

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

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

在您的情况下,一个完整的例子可能是:

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

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

【讨论】:

【参考方案3】:

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

将其保存到您的 .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)

【讨论】:

完美运行。谢谢! 对于那些不知道如何在.bash_profiletouch ~/.bash_profile; open ~/.bash_profile 上插入的人,复制并粘贴提供的源,保存,重新启动终端窗口,他们只需使用list_xcode_provisioning_profiles 就像建议。 默认shell改为zsh,所以添加到~/.zshrc【参考方案4】:

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

将 egrep 与 -a 选项一起使用,它将二进制文件视为文本文件和“-A 2”,它将在您要匹配的字符串之后显示两行:ApplicationIdentifierPrefix。

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

使用一系列管道:

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

【讨论】:

【参考方案5】:

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

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

【讨论】:

【参考方案6】:

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

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

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

【讨论】:

以上是关于在 bash 中解析 mobileprovision 文件?的主要内容,如果未能解决你的问题,请参考以下文章

在 Bash 中解析命令行参数的最佳方法是啥?

在 bash 中解析 CSV 并分配变量

如何在 Bash 脚本中解析 CSV?

在 bash 中解析 YAML 文件中的嵌套变量

在 bash 中使用命令行工具解析变体数组

Linux/bash 解析文本输出,选择字段,仅忽略一个字段中的空值