Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing mobileprovision files in bash?

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.

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

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

Thanks

like image 468
egiray Avatar asked Jun 18 '11 19:06

egiray


4 Answers

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

/usr/libexec/PlistBuddy -c 'Print :Entitlements:application-identifier' /dev/stdin <<< $(security cms -D -i path_to_mobileprovision)
like image 130
jlawrie Avatar answered Nov 03 '22 08:11

jlawrie


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:

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.

like image 41
olivierypg Avatar answered Nov 03 '22 09:11

olivierypg


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

Save this into your .bash_profile and just call it with list_xcode_provisioning_profiles from a terminal.

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)
}
like image 14
hyperknot Avatar answered Nov 03 '22 08:11

hyperknot


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.

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

Using a series of pipes:

egrep -a -A 2 ApplicationIdentifierPrefix file.mobileprovision | grep string | sed -e 's/<string>//' -e 's/<\/string>//' -e 's/ //'
like image 6
dneff Avatar answered Nov 03 '22 07:11

dneff