Class: Pindo::Command::Deploy::Resign

Inherits:
Pindo::Command::Deploy show all
Extended by:
Executable, Plistbuddyexecutable
Includes:
Pindo::Command::DeployOptions
Defined in:
lib/pindo/command/deploy/resign.rb

Constant Summary

Constants inherited from Pindo::Command

Pindo::Command::DEFAULT_OPTIONS, Pindo::Command::DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes included from Pindo::Command::DeployOptions

#additional_args, #apple_id, #args_adhoc_flag, #args_appconfig, #args_appconfig_dir, #args_appconfig_fullname, #args_apple_id, #args_appstore_flag, #args_array, #args_bundle_id, #args_dev_flag, #args_repo_name, #argv_temp, #bundle_id, #bundle_id_extension, #bundle_id_extensionad, #bundle_id_extensionporn, #bundle_id_imessage, #bundle_id_keyboard, #bundle_id_pushcontent, #bundle_id_pushservice, #bundle_id_siri, #bundle_id_siriui, #bundle_id_watchapp, #bundle_id_watchapp_extension, #bundle_id_widget, #config_json, #deploy_acount_id, #deploy_group_id, #deploy_icloud_id, #deploy_identifier, #deploy_identifier_extension, #deploy_identifier_extensionad, #deploy_identifier_extensionporn, #deploy_identifier_imessage, #deploy_identifier_keyboard, #deploy_identifier_pushcontent, #deploy_identifier_pushservice, #deploy_identifier_siri, #deploy_identifier_siriui, #deploy_identifier_watchapp, #deploy_identifier_watchapp_extension, #deploy_identifier_widget, #deploy_repo_name, #group_id, #icloud_id, #newconfuse_flag, #oldconfuse_flag

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plistbuddyexecutable

plistbuddy_execute_command, plistbuddyexecutable

Methods included from Executable

capture_command, executable, execute_command, which, which!

Methods included from Pindo::Command::DeployOptions

#check_config_version, #get_build_type_args, #get_bundle_id_map, #get_confuse_type_args, #init_deploy_params, #init_develop_params, #print_params_info, #validate!

Methods inherited from Pindo::Command::Deploy

#get_create_cert_match_values

Methods inherited from Pindo::Command

run, #validate!

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Methods included from Githelper

#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag

Constructor Details

#initialize(argv) ⇒ Resign

Returns a new instance of Resign.



38
39
40
41
42
# File 'lib/pindo/command/deploy/resign.rb', line 38

def initialize(argv)
    
    @ipa_file_name = argv.option('ipa')
    super(argv)
end

Class Method Details

.optionsObject



32
33
34
35
36
# File 'lib/pindo/command/deploy/resign.rb', line 32

def self.options
  [
    ['--ipa=', 'iap file name.']
  ].concat(super)
end

Instance Method Details

#extract_zip(file, destination) ⇒ Object



264
265
266
267
268
269
270
271
272
# File 'lib/pindo/command/deploy/resign.rb', line 264

def extract_zip(file, destination)
    FileUtils.mkdir_p(destination)
    Zip::File.open(file) do |zip_file|
      zip_file.each do |f|
        fpath = File.join(destination, f.name)
        zip_file.extract(f, fpath) unless File.exist?(fpath)
      end
    end
end

#get_resign_ipa_name(ipa_name: nil) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/pindo/command/deploy/resign.rb', line 190

def get_resign_ipa_name(ipa_name: nil)
    
    ipa_base_name = File.basename(ipa_name, ".ipa")
    ipa_dir = File.dirname(ipa_name)
        
    resign_ipa_name =  ipa_base_name + "_resigned.ipa"
    resign_ipa_full_name = File.join(ipa_dir, resign_ipa_name)
    FileUtils.cp_r(ipa_name, resign_ipa_full_name)
    puts resign_ipa_full_name

    tmp_time = "tmp_" +Time.now.strftime('%y%m%d_%H%M%S')
    tmp_dir = File.join(ipa_dir, tmp_time)
    if !File.exist?(tmp_dir)
        FileUtils.mkdir(tmp_dir) 
    end

    command = "unzip -q \"#{resign_ipa_full_name}\" -d #{tmp_dir}"

    puts command
    system command

    payload_path = File.join(tmp_dir, "Payload")
    if File.exist?(payload_path)
        FileUtils.rm_rf(resign_ipa_full_name)
    end

    
    modify_content_path = ""
    Dir.foreach(payload_path) do |file|  
        if file =~ /(.*).app/
            modify_content_path = File.join(payload_path, file);
            break;
        end
    end

    modify_ipa_info_plist(modify_content_path:modify_content_path)

    current_dir = Dir.pwd
    if File.exist?(payload_path)
        Dir.chdir(tmp_dir)
        command = "zip -qry \"#{resign_ipa_full_name}\" * "
        puts command
        system command
        Dir.chdir(current_dir)
    end

    if File.exist?(resign_ipa_full_name)
        FileUtils.rm_rf(tmp_dir)
    end

    return resign_ipa_full_name
end

#modify_ipa_info_plist(modify_content_path: nil) ⇒ Object



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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/pindo/command/deploy/resign.rb', line 74

def modify_ipa_info_plist(modify_content_path: nil)


    main_info_plist = File.join(modify_content_path, "Info.plist")
    puts main_info_plist
    
    if !File.exist?("/usr/local/bin/PlistBuddy")
        command = 'ln -s /usr/libexec/PlistBuddy /usr/local/bin/PlistBuddy'
        system command
    end                
    
    old_bundle_id_command = '/usr/local/bin/PlistBuddy -c "Print :CFBundleIdentifier" ' +main_info_plist
    puts old_bundle_id_command
    old_bundle_id = ""
    IO.popen(old_bundle_id_command) { |f| old_bundle_id = f.gets }
    puts old_bundle_id


    exchange_bundleid_command = '/usr/local/bin/PlistBuddy -c "Set :CFBundleIdentifier ' + @bundle_id + '" ' +  main_info_plist
    puts exchange_bundleid_command
    system exchange_bundleid_command

    plugin_path = File.join(modify_content_path, "PlugIns")
    if File.exist?(plugin_path)
        Dir.foreach(plugin_path) do |file|  
            if file =~ /(.*).appex/
                
                appex_path = File.join(plugin_path, file);
                tmp_info_plist = File.join(appex_path, "Info.plist");

                old_bundle_id_command = '/usr/local/bin/PlistBuddy -c "Print :CFBundleIdentifier" ' +tmp_info_plist
                puts old_bundle_id_command
                old_plugin_bundle_id = ""
                IO.popen(old_bundle_id_command) { |f| old_plugin_bundle_id = f.gets }
                puts old_plugin_bundle_id

                puts "puts old_bundle_id = #{old_plugin_bundle_id}"
                if old_plugin_bundle_id.include?(".content")
                    new_plugin_bundle_id = @bundle_id + ".content"
                    exchange_bundleid_command = '/usr/local/bin/PlistBuddy -c "Set :CFBundleIdentifier ' + new_plugin_bundle_id + '" ' +  tmp_info_plist
                    puts exchange_bundleid_command
                    system exchange_bundleid_command
                end

                if old_plugin_bundle_id.include?(".service")
                    new_plugin_bundle_id = @bundle_id + ".service"
                    exchange_bundleid_command = '/usr/local/bin/PlistBuddy -c "Set :CFBundleIdentifier ' + new_plugin_bundle_id + '" ' +  tmp_info_plist
                    puts exchange_bundleid_command
                    system exchange_bundleid_command
                end

                if old_plugin_bundle_id.include?(".imessage")
                    new_plugin_bundle_id = @bundle_id + ".imessage"
                    exchange_bundleid_command = '/usr/local/bin/PlistBuddy -c "Set :CFBundleIdentifier ' + new_plugin_bundle_id + '" ' +  tmp_info_plist
                    puts exchange_bundleid_command
                    system exchange_bundleid_command
                end

                if old_plugin_bundle_id.include?(".keyboard")
                    new_plugin_bundle_id = @bundle_id + ".keyboard"
                    exchange_bundleid_command = '/usr/local/bin/PlistBuddy -c "Set :CFBundleIdentifier ' + new_plugin_bundle_id + '" ' +  tmp_info_plist
                    puts exchange_bundleid_command
                    system exchange_bundleid_command
                end

                if old_plugin_bundle_id.include?(".siri")
                    new_plugin_bundle_id = @bundle_id + ".siri"
                    exchange_bundleid_command = '/usr/local/bin/PlistBuddy -c "Set :CFBundleIdentifier ' + new_plugin_bundle_id + '" ' +  tmp_info_plist
                    puts exchange_bundleid_command
                    system exchange_bundleid_command
                end

                if old_plugin_bundle_id.include?(".widget")
                    new_plugin_bundle_id = @bundle_id + ".widget"
                    exchange_bundleid_command = '/usr/local/bin/PlistBuddy -c "Set :CFBundleIdentifier ' + new_plugin_bundle_id + '" ' +  tmp_info_plist
                    puts exchange_bundleid_command
                    system exchange_bundleid_command
                end

                if old_plugin_bundle_id.include?(".siriui")
                    new_plugin_bundle_id = @bundle_id + ".siriui"
                    exchange_bundleid_command = '/usr/local/bin/PlistBuddy -c "Set :CFBundleIdentifier ' + new_plugin_bundle_id + '" ' +  tmp_info_plist
                    puts exchange_bundleid_command
                    system exchange_bundleid_command
                end


                if old_plugin_bundle_id.include?(".extension")
                    new_plugin_bundle_id = @bundle_id + ".extension"
                    exchange_bundleid_command = '/usr/local/bin/PlistBuddy -c "Set :CFBundleIdentifier ' + new_plugin_bundle_id + '" ' +  tmp_info_plist
                    puts exchange_bundleid_command
                    system exchange_bundleid_command
                end

                if old_plugin_bundle_id.include?(".extensionad")
                    new_plugin_bundle_id = @bundle_id + ".extensionad"
                    exchange_bundleid_command = '/usr/local/bin/PlistBuddy -c "Set :CFBundleIdentifier ' + new_plugin_bundle_id + '" ' +  tmp_info_plist
                    puts exchange_bundleid_command
                    system exchange_bundleid_command
                end

                if old_plugin_bundle_id.include?(".extensionporn")
                    new_plugin_bundle_id = @bundle_id + ".extensionporn"
                    exchange_bundleid_command = '/usr/local/bin/PlistBuddy -c "Set :CFBundleIdentifier ' + new_plugin_bundle_id + '" ' +  tmp_info_plist
                    puts exchange_bundleid_command
                    system exchange_bundleid_command
                end
  

            end
        end
        
    end

end

#resign_profile_dict(profil_info_array: nil) ⇒ Object



274
275
276
277
278
279
280
281
282
283
284
# File 'lib/pindo/command/deploy/resign.rb', line 274

def resign_profile_dict(profil_info_array: nil)
  

  resign_dict = {}
  profil_info_array.each do |profil_info|
      resign_dict[profil_info["bundle_id"]] = profil_info["profile_path"]
  end

  return resign_dict
  
end

#runObject



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
# File 'lib/pindo/command/deploy/resign.rb', line 44

def run


    args_temp = []
    args = get_build_type_args()
    args_temp = args_temp | args


    Pindo::Command::Deploy::Cert::run(args_temp)

    if @ipa_file_name
        new_ipa_filename = File.expand_path(@ipa_file_name)
    else
        current_dir = Dir.pwd
                new_project_fullname = ""
                Dir.foreach(current_dir) do |file|  
                    if file =~ /(.*).ipa/
                        new_ipa_filename = File.join(current_dir, file)
                        break;
                    end
                end 
        end
    if new_ipa_filename && new_ipa_filename != "" then
        resign_ipa_name = get_resign_ipa_name(ipa_name: new_ipa_filename)
        sign_ipa_with_new_cert(ipa_name: resign_ipa_name)
    end


end

#sign_ipa_with_new_cert(ipa_name: nil) ⇒ Object



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/pindo/command/deploy/resign.rb', line 243

def sign_ipa_with_new_cert(ipa_name: nil)

    profil_info_array = pindo_single_config.get_cert_info
    bundle_id_signing_identity = profil_info_array.first['signing_identity']
    # puts "bundle_id_signing_identity : #{bundle_id_signing_identity}"

    profile_dict = resign_profile_dict(profil_info_array: profil_info_array)

    # puts 
    # puts "profile_dict :"
    # puts
    # puts profile_dict


    # resign(ipa, signing_identity, provisioning_profiles, entitlements, รงรงรง, display_name, short_version, bundle_version, new_bundle_id, use_app_entitlements, keychain_path)

    Sigh::Resign.resign(ipa_name, bundle_id_signing_identity, profile_dict, nil, nil, nil, nil, nil, @bundle_id, true, nil)
             
end