-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreateAppOnPortal.rb
executable file
·105 lines (74 loc) · 3.31 KB
/
CreateAppOnPortal.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env ruby
$LOAD_PATH << '.'
require 'spaceship'
require 'openssl'
require 'fileutils'
require 'config'
def camel_case(str)
words = str.downcase.split
words.shift + words.map(&:capitalize).join
end
if ARGV[0].nil?
puts 'Please provide Application Name to create'
exit
end
if ARGV[1].nil?
puts 'Please provide bundle id prefix'
exit
end
appName = ARGV[0]
appNameJoined = ARGV[0].split(' ').join
app_id = ARGV[1] + '.' + camel_case(appName)
client = Spaceship.login(AppMakerConfig::DEV_USER, AppMakerConfig::DEV_PASSWORD)
puts "Logged in"
#Spaceship.select_team
client.team_id = 'P2WQ65BAA8'
#puts "Team Selected: #{client.team_information.name}"
#Spaceship.app.all.collect do |app|
# puts app
#end
FileUtils::mkdir_p appName
app = Spaceship.app.find(app_id)
if !app.nil?
puts 'Application already exists:'
puts app.app_id
puts app.name
puts app.bundle_id
devices = Spaceship::Device.all
devCerts = Spaceship.certificate.development.all
puts 'got devCerts'
profile = Spaceship.provisioning_profile.development.create!(bundle_id: app_id, certificate: devCerts, name: appName + ' Development')
File.write(appName + '/' + appName + ' Development.mobileprovision', profile.download)
puts "Development provisioning profile created: #{profile.name}"
exit
end
puts "Application '#{app_id}' not found. Will create one..."
app = Spaceship.app.create!(bundle_id: app_id, name: appName)
puts "App created: #{app.app_id}"
# Create a new certificate signing request
prod_csr, prod_pkey = Spaceship.certificate.create_certificate_signing_request
# Use the signing request to create a new push certificate
prodCert = Spaceship.certificate.production_push.create!(csr: prod_csr, bundle_id: app_id)
prod_pfx = OpenSSL::PKCS12.create('Abcd1234', app_id, prod_pkey, prodCert.download)
File.open(appName + '/' + appNameJoined + '_Production_Push.p12', 'w') {
|f| f.write(prod_pfx.to_der)
}
puts 'Production push certificate stored to ' + appNameJoined + '_Production_Push.p12'
# Create a new certificate signing request
dev_csr, dev_pkey = Spaceship.certificate.create_certificate_signing_request
# Use the signing request to create a new push certificate
devCert = Spaceship.certificate.development_push.create!(csr: dev_csr, bundle_id: app_id)
dev_pfx = OpenSSL::PKCS12.create('Abcd1234', app_id, dev_pkey, devCert.download)
File.open(appName + '/' + appNameJoined + '_Development_Push.p12', 'w') {
|f| f.write(dev_pfx.to_der)
}
puts 'Development push certificate stored to ' + appNameJoined + '_Development_Push.p12'
devCerts = Spaceship.certificate.development.all
profile = Spaceship.provisioning_profile.development.create!(bundle_id: app_id, certificate: devCerts, name: appName + ' Development')
File.write(appName + '/' + appName + ' Development.mobileprovision', profile.download)
puts "Development provisioning profile created: #{profile.name}; id: #{profile.uuid}"
prodCert = Spaceship.certificate.production.all.first
productionProfile = Spaceship.provisioning_profile.app_store.create!(bundle_id: app_id, certificate: prodCert, name: appName + ' Production')
File.write(appName + '/' + appName + ' Production.mobileprovision', productionProfile.download)
puts "Production provisioning profile created: #{productionProfile.name}; id: #{productionProfile.uuid}"
#/Users/pbeast/Library/MobileDevice/Provisioning\ Profiles