Last active
October 24, 2016 13:36
-
-
Save hfossli/53f5e190fc15401959c610ad98dfa4df to your computer and use it in GitHub Desktop.
Remove duplicate .mobileprovision files locally on your machine
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
# If you prefer to have this in yor fastfile | |
fastlane_version "1.90.0" | |
default_platform :ios | |
platform :ios do | |
lane :duplicates do |options| | |
remove_local_duplicate_profiles | |
end | |
def remove_local_duplicate_profiles | |
entries = {} | |
path = File.expand_path '~/Library/MobileDevice/Provisioning Profiles' | |
puts "Searching through locally installed mobileprovision files..." | |
Dir.glob("#{path}/*.mobileprovision") do |item| | |
info = Helper.backticks "/usr/libexec/PlistBuddy -c 'Print :CreationDate' -c 'Print :Name' -c 'Print :TeamName' /dev/stdin <<< $(security cms -D -i '#{item}')", print: false | |
values = info.split "\n" | |
entry = { | |
:creation_date => values[0], | |
:name => values[1], | |
:team => values[2], | |
:path => item | |
} | |
key = "#{entry[:team]} > #{entry[:name]}" | |
same_key_entries = entries[key] | |
unless same_key_entries | |
same_key_entries = [] | |
entries[key] = same_key_entries | |
end | |
same_key_entries.push entry | |
end | |
puts "...done!" | |
dupes = entries.find_all { |k,profiles| profiles.count > 1 } | |
dupes.each { |k,profiles| | |
sorted = profiles.sort_by { |a| a[:creation_date] } | |
keeping = sorted[0] | |
puts "Keeping profile: '#{keeping[:name]}' (#{File.basename keeping[:path]}) #{keeping[:creation_date]}" | |
sorted.drop(1).each { |entry| | |
puts " > Deleting profile: '#{entry[:name]}' (#{File.basename entry[:path]}) #{entry[:creation_date]}" | |
Helper.backticks "rm '#{entry[:path]}'" | |
} | |
} | |
end | |
end |
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
# Generic / not related to Fastlane | |
entries = {} | |
path = File.expand_path '~/Library/MobileDevice/Provisioning Profiles' | |
puts "Searching through locally installed mobileprovision files..." | |
Dir.glob("#{path}/*.mobileprovision") do |item| | |
info = `/usr/libexec/PlistBuddy -c 'Print :CreationDate' -c 'Print :Name' -c 'Print :TeamName' /dev/stdin <<< $(security cms -D -i '#{item}')` | |
values = info.split "\n" | |
entry = { | |
:creation_date => values[0], | |
:name => values[1], | |
:team => values[2], | |
:path => item | |
} | |
key = "#{entry[:team]} > #{entry[:name]}" | |
same_key_entries = entries[key] | |
unless same_key_entries | |
same_key_entries = [] | |
entries[key] = same_key_entries | |
end | |
same_key_entries.push entry | |
end | |
puts "...done!" | |
dupes = entries.find_all { |k,profiles| profiles.count > 1 } | |
dupes.each { |k,profiles| | |
sorted = profiles.sort_by { |a| a[:creation_date] } | |
keeping = sorted[0] | |
puts "Keeping profile: '#{keeping[:name]}' (#{File.basename keeping[:path]}) #{keeping[:creation_date]}" | |
sorted.drop(1).each { |entry| | |
puts " > Deleting profile: '#{entry[:name]}' (#{File.basename entry[:path]}) #{entry[:creation_date]}" | |
`rm '#{entry[:path]}'` | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment