Class: Sigh::Resign
- Inherits:
-
Object
- Object
- Sigh::Resign
- Defined in:
- lib/sigh/resign.rb
Overview
Resigns an existing ipa file
Class Method Summary collapse
Instance Method Summary collapse
- #ask_for_signing_identity ⇒ Object
- #find_entitlements ⇒ Object
- #find_ipa ⇒ Object
- #find_provisioning_profile ⇒ Object
- #find_resign_path ⇒ Object
- #find_signing_identity(signing_identity) ⇒ Object
- #get_inputs(options, args) ⇒ Object
-
#installed_identies ⇒ Object
Array of available signing identities.
- #print_available_identities ⇒ Object
- #resign(ipa, signing_identity, provisioning_profiles, entitlements, version, display_name) ⇒ Object
- #run(options, args) ⇒ Object
- #validate_ipa_file(ipa) ⇒ Object
- #validate_params(resign_path, ipa, provisioning_profiles) ⇒ Object
- #validate_provisioning_file(provisioning_profile) ⇒ Object
- #validate_resign_path(resign_path) ⇒ Object
Class Method Details
.resign(ipa, signing_identity, provisioning_profiles, entitlements, version, display_name) ⇒ Object
14 15 16 |
# File 'lib/sigh/resign.rb', line 14 def self.resign(ipa, signing_identity, provisioning_profiles, entitlements, version, display_name) self.new.resign(ipa, signing_identity, provisioning_profiles, entitlements, version, display_name) end |
Instance Method Details
#ask_for_signing_identity ⇒ Object
116 117 118 119 |
# File 'lib/sigh/resign.rb', line 116 def ask_for_signing_identity print_available_identities ask('Signing Identity: ') end |
#find_entitlements ⇒ Object
79 80 81 |
# File 'lib/sigh/resign.rb', line 79 def find_entitlements Dir[File.join(Dir.pwd, '*.entitlements')].sort { |a, b| File.mtime(a) <=> File.mtime(b) }.first end |
#find_ipa ⇒ Object
71 72 73 |
# File 'lib/sigh/resign.rb', line 71 def find_ipa Dir[File.join(Dir.pwd, '*.ipa')].sort { |a, b| File.mtime(a) <=> File.mtime(b) }.first end |
#find_provisioning_profile ⇒ Object
75 76 77 |
# File 'lib/sigh/resign.rb', line 75 def find_provisioning_profile Dir[File.join(Dir.pwd, '*.mobileprovision')].sort { |a, b| File.mtime(a) <=> File.mtime(b) }.first end |
#find_resign_path ⇒ Object
67 68 69 |
# File 'lib/sigh/resign.rb', line 67 def find_resign_path File.join(Helper.gem_path('sigh'), 'lib', 'assets', 'resign.sh') end |
#find_signing_identity(signing_identity) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/sigh/resign.rb', line 83 def find_signing_identity(signing_identity) until installed_identies.include?(signing_identity) UI.error "Couldn't find signing identity '#{signing_identity}'." signing_identity = ask_for_signing_identity end signing_identity end |
#get_inputs(options, args) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sigh/resign.rb', line 56 def get_inputs(, args) ipa = args.first || find_ipa || ask('Path to ipa file: ') signing_identity = .signing_identity || ask_for_signing_identity provisioning_profiles = .provisioning_profile || find_provisioning_profile || ask('Path to provisioning file: ') entitlements = .entitlements || find_entitlements version = .version_number || nil display_name = .display_name || nil return ipa, signing_identity, provisioning_profiles, entitlements, version, display_name end |
#installed_identies ⇒ Object
Array of available signing identities
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/sigh/resign.rb', line 122 def installed_identies available = `security find-identity -v -p codesigning` ids = [] available.split("\n").each do |current| begin (ids << current.match(/.*\"(.*)\"/)[1]) rescue nil end # the last line does not match end ids end |
#print_available_identities ⇒ Object
112 113 114 |
# File 'lib/sigh/resign.rb', line 112 def print_available_identities UI. "Available identities: \n\t#{installed_identies.join("\n\t")}\n" end |
#resign(ipa, signing_identity, provisioning_profiles, entitlements, version, display_name) ⇒ Object
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 |
# File 'lib/sigh/resign.rb', line 18 def resign(ipa, signing_identity, provisioning_profiles, entitlements, version, display_name) resign_path = find_resign_path signing_identity = find_signing_identity(signing_identity) unless provisioning_profiles.kind_of?(Enumerable) provisioning_profiles = [provisioning_profiles] end # validate that we have valid values for all these params, we don't need to check signing_identity because `find_signing_identity` will only ever return a valid value validate_params(resign_path, ipa, provisioning_profiles) entitlements = "-e #{entitlements}" if entitlements = provisioning_profiles.map { |fst, snd| "-p #{[fst, snd].compact.map(&:shellescape).join('=')}" }.join(' ') version = "-n #{version}" if version display_name = "-d #{display_name.shellescape}" if display_name command = [ resign_path.shellescape, ipa.shellescape, signing_identity.shellescape, , # we are aleady shellescaping this above, when we create the provisioning_options from the provisioning_profiles entitlements, version, display_name, ipa.shellescape ].join(' ') puts command.magenta puts `#{command}` if $?.to_i == 0 UI.success "Successfully signed #{ipa}!" true else UI.error "Something went wrong while code signing #{ipa}" false end end |
#run(options, args) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/sigh/resign.rb', line 6 def run(, args) # get the command line inputs and parse those into the vars we need... ipa, signing_identity, provisioning_profiles, entitlements, version, display_name = get_inputs(, args) # ... then invoke our programmatic interface with these vars resign(ipa, signing_identity, provisioning_profiles, entitlements, version, display_name) end |
#validate_ipa_file(ipa) ⇒ Object
102 103 104 |
# File 'lib/sigh/resign.rb', line 102 def validate_ipa_file(ipa) UI.user_error!("ipa file could not be found or is not an ipa file (#{ipa})") unless File.exist?(ipa) && ipa.end_with?('.ipa') end |
#validate_params(resign_path, ipa, provisioning_profiles) ⇒ Object
92 93 94 95 96 |
# File 'lib/sigh/resign.rb', line 92 def validate_params(resign_path, ipa, provisioning_profiles) validate_resign_path(resign_path) validate_ipa_file(ipa) provisioning_profiles.each { |fst, snd| validate_provisioning_file(snd || fst) } end |
#validate_provisioning_file(provisioning_profile) ⇒ Object
106 107 108 109 110 |
# File 'lib/sigh/resign.rb', line 106 def validate_provisioning_file(provisioning_profile) unless File.exist?(provisioning_profile) && provisioning_profile.end_with?('.mobileprovision') UI.user_error!("Provisioning profile file could not be found or is not a .mobileprovision file (#{provisioning_profile})") end end |
#validate_resign_path(resign_path) ⇒ Object
98 99 100 |
# File 'lib/sigh/resign.rb', line 98 def validate_resign_path(resign_path) UI.user_error!('Could not find resign.sh file. Please try re-installing the gem') unless File.exist?(resign_path) end |