Last active
October 4, 2019 20:47
-
-
Save stephanecopin/efc8d3a4b0c45f21d9035f2ef08ae793 to your computer and use it in GitHub Desktop.
The code for a Ruby Step on Bitrise allowing to import profiles from a zip archive from the Generic File Storage (must be the env var `ADDITIONAL_PROVISIONING_PROFILES_ARCHIVE_URL`), if hitting the 30 prov profiles limit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
require 'tmpdir' | |
require 'English' | |
prov_profiles_install_path = '~/Library/MobileDevice/Provisioning Profiles' | |
prov_profiles_archive_url = ENV['ADDITIONAL_PROVISIONING_PROFILES_ARCHIVE_URL'] | |
temporary_dir = File.join(Dir.tmpdir, "additional_prov_profiles") | |
FileUtils.mkdir_p(temporary_dir) | |
begin | |
archive_path = File.join(temporary_dir, 'prov_profiles.zip') | |
archive_data = `curl -s -L #{prov_profiles_archive_url}` | |
raise "Failed to download archive at #{prov_profiles_archive_url}; aborting" unless $CHILD_STATUS.success? | |
File.write(archive_path, archive_data) | |
prov_profiles_dir = File.join(temporary_dir, 'prov_profiles') | |
raise "Couldn't unzip #{prov_profiles_archive_url}; aborting" unless system('unzip', '-q', archive_path, '-d', prov_profiles_dir) | |
FileUtils.mkdir_p(prov_profiles_install_path) | |
plist_dir = File.join(temporary_dir, 'prov_profile_plists') | |
FileUtils.mkdir_p(plist_dir) | |
Dir.glob(File.join(prov_profiles_dir, '**/*.mobileprovision')) do |prov_profile| | |
basename = File.basename(prov_profile) | |
name = File.basename(prov_profile, '.mobileprovision') | |
puts "Installing #{name}..." | |
plist_info_base_path = File.join(plist_dir, basename) | |
plist_info_path = "#{plist_info_base_path}.plist" | |
File.write(plist_info_path, `security cms -D -i '#{prov_profile}'`) | |
raise "Couldn't parse provisioning profile; aborting" unless $CHILD_STATUS.success? | |
uuid = `defaults read '#{File.expand_path(plist_info_base_path)}' UUID` | |
raise "Couldn't read UUID from prov profile; aborting" unless $CHILD_STATUS.success? | |
FileUtils.mv(prov_profile, File.join(prov_profiles_install_path, "#{uuid}.mobileprovision")) | |
puts "Successfully installed #{name}." | |
end | |
ensure | |
FileUtils.rm_rf(temporary_dir) | |
end | |
puts 'Successfully installed provisioning profiles.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment