provision.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #! /usr/bin/env python
  2. import shutil
  3. import os
  4. identity="iPhone Developer: David Rose"
  5. library='/Users/drose/Library'
  6. profile="31FDB595-E85E-41D8-BE12-7C67B777B6C3"
  7. appPrefix="VGEKRBUPUE"
  8. appId="com.ddrose.iphone.pview"
  9. entitlements="/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/Entitlements.plist"
  10. app="/tmp/iphone/pview.app"
  11. xcent="/tmp/file.xcent"
  12. sourceFilename = '%s/MobileDevice/Provisioning Profiles/%s.mobileprovision' % (library, profile)
  13. targetFilename = '%s/embedded.mobileprovision' % (app)
  14. shutil.copyfile(sourceFilename, targetFilename)
  15. origtext = open(entitlements, 'r').read()
  16. dict = origtext.find('<dict>')
  17. newtext = origtext[:dict + 6] + '\n<key>application-identifier</key>\n<string>%s.%s</string>' % (appPrefix, appId) + origtext[dict + 6:]
  18. # Some kind of crazy binary header on the xcent file. The second
  19. # group of four bytes is the file length.
  20. header = '\xfa\xde\x71\x71'
  21. length = len(header) + 4 + len(newtext)
  22. lengthstr = chr(length >> 24) + chr((length >> 16) & 0xff) + chr((length >> 8) & 0xff) + chr(length & 0xff)
  23. open(xcent, 'w').write(header + lengthstr + newtext)
  24. command = 'env CODESIGN_ALLOCATE="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate" PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /usr/bin/codesign -f -s "%(identity)s" --resource-rules="%(app)s/ResourceRules.plist" --entitlements "%(xcent)s" "%(app)s"' % {
  25. 'identity' : identity,
  26. 'app' : app,
  27. 'xcent' : xcent,
  28. }
  29. print command
  30. result = os.system(command)
  31. if result != 0:
  32. raise StandardError
  33. os.unlink(xcent)