-
Notifications
You must be signed in to change notification settings - Fork 9
/
generate_apple_dev_center_config.rb
executable file
·67 lines (56 loc) · 1.74 KB
/
generate_apple_dev_center_config.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
#!/usr/bin/ruby
require 'optparse'
require 'ostruct'
require 'rubygems'
require 'encrypted_strings'
require 'yaml'
# Set default options.
opts = OpenStruct.new
opts.login = ""
opts.password = ""
opts.secret_key = ""
opts.teamid = ""
opts.teamname = ""
# Specify options.
options = OptionParser.new do |options|
options.banner = "Usage: #{File.basename($0)} [options]\nGenerates a YAML config file for apple_dev_center.rb"
options.separator "Mandatory options:"
options.on("-l", "--login LOGIN", "Login e-mail address") {|l| opts.login = l}
options.on("-p", "--password PASS", "Login password") {|p| opts.password = p}
options.separator "Optional options:"
options.on("-t", "--team-id TID", "Team ID - The team ID from the Multiple Developer Programs") {|t| opts.teamid = t}
options.on("-T", "--team-name TEAMNAME", "Team name - The team name from the Multiple Developer Programs") {|n| opts.teamname = n}
options.on("-s", "--secret-key SECRET-KEY", "Secret key") {|s| opts.secret_key = s}
options.separator "General options:"
options.on_tail("-h", "--help", "Show this message") do
puts options
exit
end
end
# Show usage if no arguments are given.
if (ARGV.empty?)
puts options
exit
end
# Parse options.
begin
options.parse!
rescue
puts options
exit 1
end
crypted_password = opts.password.encrypt(:symmetric, :password => opts.secret_key).to_s
data={}
data['default'] = opts.login
# Force to string
encrypted = '' + crypted_password
# Remove trailing carriage return characters (\n, \r, and \r\n)
encrypted = encrypted.chomp()
account = {}
account['login'] = opts.login
account['password'] = encrypted
account['teamid'] = opts.teamid
account['teamname'] = opts.teamname
data['accounts'] = [account]
s = YAML::dump(data)
puts s