Created
August 31, 2009 13:31
-
-
Save masuidrive/178459 to your computer and use it in GitHub Desktop.
Automatic to build iPhone app package for AdHoc distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# build AdHoc package | |
# | |
# Install: | |
# sudo gem install mechanize | |
# | |
# Usage: | |
# ruby build-adhoc.rb adhoc.yaml | |
# | |
# adhoc.yaml is below | |
=begin | |
provisioning: "AdHoc" # set http://developer.apple.com/iphone/manage/provisioningprofiles/index.action Provisioning Profile | |
target: "FooApp" | |
configuration: "AdHoc" | |
sdk: "iphoneos3.0" | |
code_sign_identity: "iPhone Distribution: Example Inc" | |
apple_id: "[email protected]" | |
apple_password: "apple" | |
package_name: "package" | |
=end | |
require 'rubygems' | |
require 'mechanize' | |
require 'yaml' | |
require 'fileutils' | |
CONFIG = YAML.load(File.read(ARGV[0])) | |
TMP_DIR = File.join(`pwd`.chomp, "tmp") | |
TMP_PACKAGE_DIR = File.join(TMP_DIR, "package") | |
def install_provisioning_file(path) | |
`open #{path}` | |
end | |
def main | |
a = WWW::Mechanize.new { |agent| | |
agent.follow_meta_refresh = true | |
} | |
a.get('http://developer.apple.com/iphone/login.action') do |signin_page| | |
# login | |
my_page = signin_page.form_with(:name => 'appleConnectForm') do |form| | |
form.theAccountName = CONFIG['apple_id'] | |
form.theAccountPW = CONFIG['apple_password'] | |
end.submit | |
# access to provisioning | |
provisioning_href = nil | |
a.get('/ios/manage/provisioningprofiles/viewDistributionProfiles.action') do |page| | |
page.search('.nt_multi tr').each do |line| | |
name = line.search(".profile span").text | |
if CONFIG['provisioning']==name | |
line.search(".action a").each do |link| | |
if %r|/ios/manage/provisioningprofiles/download.action|.match(link['href']) | |
provisioning_href = link['href'] | |
end | |
end | |
end | |
end # page.search('.nt_multi tr') | |
end | |
provisioning_uuid = provisioning_file = nil | |
a.get(provisioning_href) do |page| | |
filename = /filename=(\S*)/.match(page.response['content-disposition']).to_a[1] | |
provisioning_file = File.join(TMP_DIR, filename) | |
open(provisioning_file, 'w') do |f| | |
f.write page.body | |
end | |
install_provisioning_file provisioning_file | |
provisioning_uuid = %r|<key>UUID</key>\s*<string>(.*?)</string>|.match(page.body).to_a.last | |
end | |
build provisioning_uuid | |
make_package "#{CONFIG['package_name']}-#{Time.now.strftime '%Y%m%d-%H%M'}.zip", Dir.glob('build/*/*.app').last, provisioning_file | |
end | |
end | |
def build(provisioning_uuid) | |
FileUtils.rm_r 'build' if File.directory?('build') | |
puts build_command = %(xcodebuild -target "#{CONFIG['target']}" \ | |
-configuration "#{CONFIG['configration']}" -sdk "#{CONFIG['sdk']}" \ | |
CODE_SIGN_IDENTITY="#{CONFIG['code_sign_identity']}" \ | |
PROVISIONING_PROFILE="#{provisioning_uuid}" \ | |
clean build) | |
result = system(build_command) | |
end | |
def make_package(zipfile, app_dir, provisioning_file) | |
FileUtils.rm_r TMP_PACKAGE_DIR if File.directory?(TMP_PACKAGE_DIR) | |
FileUtils.mkdir TMP_PACKAGE_DIR | |
FileUtils.move app_dir, TMP_PACKAGE_DIR | |
FileUtils.move provisioning_file, TMP_PACKAGE_DIR | |
system(%!ditto -ck --sequesterRsrc --rsrc "#{TMP_PACKAGE_DIR}" "#{zipfile}"!) | |
puts "\n>>>>>>>\n#{zipfile}" | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment