#!/usr/bin/env ruby require 'rubygems' require 'commander/import' require 'omudid' require 'terminal-table' require 'term/ansicolor' require 'cupertino_compatibility' require 'shellwords' program :name, 'OneMoreUDID' program :version, "1.0.7" program :description, '''Uses the developer portal to add one device to a provisioning profile, then downloads and installs the new profile. Also uploads provisioning profiles to TestFlight.''' HighLine.track_eof = false # Fix for built-in Ruby default_command :help command :'list-teams' do |c| c.syntax = 'omudid list-teams [username] [password]' c.summary = 'Lists teams on the iOS developer portal' c.description = '' c.action do |args, options| agent = OneMoreUDID::PortalAgent.new username, password = (args[0] rescue nil), (args[1] rescue nil) username, password = agent.login(username, password) if !args[1] puts say_warning 'Note: you can automate this process by running:' say_warning ' omudid list-teams ' + Shellwords.escape(username) + ' [password]' puts end teams = agent.get_teams() table = Terminal::Table.new do |t| t << ['Team ID', 'Team Name'] t << :separator teams.each do |id, name| t << [id, name] end end puts table end end command :'list-profiles' do |c| c.syntax = 'omudid list-profiles [username] [password] ([team ID])' c.summary = 'Lists provisioning profiles on the iOS developer portal' c.description = '' c.action do |args, options| agent = OneMoreUDID::PortalAgent.new username, password = (args[0] rescue nil), (args[1] rescue nil) username, password = agent.login(username, password) team_name = args[2] rescue '' if !args[1] puts end agent.setup_cupertino(team_name) profiles = agent.list_profiles() if !args[1] puts say_warning 'Note: you can automate this process by running:' if agent.agent.instance_variable_get('@team') say_warning ' omudid list-profiles ' + Shellwords.escape(username) + ' [password] ' + agent.agent.instance_variable_get('@team') else say_warning ' omudid list-profiles ' + Shellwords.escape(username) + ' [password]' end puts end table = Terminal::Table.new do |t| t << ['Name', 'Type', 'App ID', 'Status'] t << :separator profiles.each do |profile| t << [profile.name, profile.type, profile.app_id, profile.status] end end puts table end end command :add do |c| c.syntax = 'omudid add [username] [password] [profile name] [device name] [UDID] ([team ID])' c.summary = 'Adds a device to the provisioning portal, then downloads and installs the new profile' c.description = '' c.action do |args, options| agent = OneMoreUDID::PortalAgent.new username, password = (args[0] rescue nil), (args[1] rescue nil) username, password = agent.login(username, password) profile_name = (args[2] or (puts; ask 'Profile name (leave blank to select from available profiles):')) device_name = (args[3] or ask 'Device name:') udid = (args[4] or ask 'UDID:') team_name = args[5] rescue '' if udid.match(/^[A-f0-9]{40}$/).nil? say_error 'Invalid UDID entered, won\'t be inserted.' end show_hint = false if !args[4] show_hint = true puts end agent.setup_cupertino(team_name) agent.add_device(device_name, udid) if profile_name == '' puts profile_name = choose "\nSelect a profile:", *agent.list_profiles().collect { |profile| profile.name } puts end if show_hint say_warning 'Note: you can automate this process by running:' if agent.agent.instance_variable_get('@team') say_warning ' omudid add ' + Shellwords.escape(username) + ' [password] ' + Shellwords.escape(profile_name) + ' ' + Shellwords.escape(device_name) + ' ' + Shellwords.escape(udid) + ' ' + agent.agent.instance_variable_get('@team') else say_warning ' omudid add ' + Shellwords.escape(username) + ' [password] ' + Shellwords.escape(profile_name) + ' ' + Shellwords.escape(device_name) + ' ' + Shellwords.escape(udid) end puts end agent.update_profile(profile_name) filename = agent.download_new_profile(profile_name) local_agent = OneMoreUDID::LocalAgent.new local_agent.install_profile(profile_name, filename) end end command :'testflight list-apps' do |c| c.syntax = 'omudid testflight list-apps [username] [password]' c.summary = 'Lists apps on TestFlight' c.description = '' c.action do |args, options| agent = OneMoreUDID::TestFlightAgent.new username, password = (args[0] rescue nil), (args[1] rescue nil) username, password = agent.login(username, password) if !args[1] say_warning 'Note: you can automate this process by running:' say_warning ' omudid testflight list-apps ' + Shellwords.escape(username) + ' [password]' puts end apps = agent.get_apps() table = Terminal::Table.new do |t| t << ['App ID', 'App Name'] t << :separator apps.each do |id, name| t << [id, name] end end puts table end end command :'testflight list-builds' do |c| c.syntax = 'omudid testflight list-builds [username] [password] [app ID]' c.summary = 'Lists builds of an app on TestFlight' c.description = '' c.action do |args, options| agent = OneMoreUDID::TestFlightAgent.new username, password = (args[0] rescue nil), (args[1] rescue nil) username, password = agent.login(username, password) app_id = (args[2] or ask 'App ID (leave blank to select from available IDs):') show_hint = false if !args[2] show_hint = true end if app_id == '' apps = agent.get_apps().collect{ |id, name| id + ' ('+name+')' } puts choice = choose 'Select an app ID:', *apps puts regex = /^[^ ]*/ app_id = (choice.match regex)[0] end say_warning 'Note: you can automate this process by running:' say_warning ' omudid testflight list-builds ' + Shellwords.escape(username) + ' [password] ' + Shellwords.escape(app_id) puts builds = agent.get_builds(app_id) table = Terminal::Table.new do |t| t << ['Build ID', 'Build Name'] t << :separator builds.each do |id, name| t << [id, name] end end puts table end end command :'testflight upload' do |c| c.syntax = 'omudid testflight upload [username] [password] [build ID] [profile name]' c.summary = 'Uploads a provisioning profile to TestFlight' c.description = '' c.action do |args, options| agent = OneMoreUDID::TestFlightAgent.new username, password = (args[0] rescue nil), (args[1] rescue nil) username, password = agent.login(username, password) build_id = (args[2] or ask 'Build ID (leave blank to select from available IDs):') profile_name = (args[3] or ask 'Profile name (leave blank to select from available local profiles):') show_hint = false if !args[3] show_hint = true end if build_id == '' app_id = ask 'Enter an App ID to list builds (or leave blank to list App IDs):' if app_id == '' apps = agent.get_apps().collect{ |id, name| id + ' ('+name+')' } puts choice = choose 'Select an app ID:', *apps puts regex = /^[^ ]*/ app_id = (choice.match regex)[0] end builds = agent.get_builds(app_id).collect{ |id, name| id + ' ('+name+')' } puts choice = choose 'Select a build ID:', *builds puts regex = /^[^ ]*/ build_id = (choice.match regex)[0] show_hint = true end if profile_name == '' local_agent = OneMoreUDID::LocalAgent.new profile_name = choose 'Select a profile:', *local_agent.get_profiles() puts show_hint = true end if show_hint say_warning 'Note: you can automate this process by running:' say_warning ' omudid testflight list-builds ' + Shellwords.escape(username) + ' [password] ' + Shellwords.escape(build_id) + ' ' + Shellwords.escape(profile_name) puts end agent.upload(build_id, profile_name) end end