ios_android_toolbox 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,83 +3,17 @@
3
3
  require 'rubygems'
4
4
  require 'parsedate'
5
5
  require 'time'
6
+ require 'ios_android_toolbox/ios_prov_profile'
6
7
 
7
- DEBUG=false
8
- PROV_PROFILE_DIR=ENV['HOME']+'/Library/MobileDevice/Provisioning Profiles'
9
- UUID_REGEX='[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}'
8
+ include IosAndroidToolbox
10
9
 
11
- profile_file = ARGV.shift
12
- profile_file or raise "Please specify a provisioning profile name"
10
+ class InstallProvProfile
11
+ def run(args)
12
+ profile_path = args.shift
13
+ profile_path or raise "Please specify a provisioning profile name"
13
14
 
14
- prov_profile = File.open(profile_file).read
15
-
16
- def uuid_for_profile(contents)
17
- # <key>UUID</key>
18
- # <string>06AF2826-608D-4CE9-99AE-AA917FF1641E</string>
19
- if /<key>UUID<\/key>\s*<string>(#{UUID_REGEX})<\/string>/.match(contents)
20
- puts "Found UUID: #{$1}" if DEBUG
21
- uuid = $1
22
- else
23
- nil
24
- end
25
- end
26
-
27
- def app_id_from_profile(contents)
28
- # <key>application-identifier</key>
29
- # <string>NDVAA33T9J.com.favequest.FFSApp.87.ircpa</string>
30
- if /<key>application-identifier<\/key>\s*<string>[A-Za-z0-9]+\.([^<]+)<\/string>/.match(contents)
31
- puts "Found app Id: #{$1}" if DEBUG
32
- app_id = $1
33
- else
34
- nil
35
- end
36
- end
37
-
38
- def creation_date_from_profile(contents)
39
- # <key>CreationDate</key>
40
- # <date>2011-08-30T02:11:55Z</date>
41
- if /<key>CreationDate<\/key>\s*<date>([^<]+)<\/date>/.match(contents)
42
- #creation_date = Date.strptime($1, '%Y-%m-%dT%h:%M:%sZ')
43
- creation_date = Time.parse($1)
44
- puts "Found Creation date: #{creation_date.to_s}" if DEBUG
45
- creation_date
46
- else
47
- nil
48
- end
49
- end
50
-
51
- def has_provisioned_devices(contents)
52
- # <key>ProvisionedDevices</key>
53
- /<key>ProvisionedDevices<\/key>/.match(contents)
54
- end
55
-
56
- new_uuid = uuid_for_profile(prov_profile)
57
- new_app_id = app_id_from_profile(prov_profile)
58
- new_cdate = creation_date_from_profile(prov_profile)
59
- new_is_dev = has_provisioned_devices(prov_profile)
60
-
61
- `mkdir -p "(#{PROV_PROFILE_DIR}"; chmod 755 "#{PROV_PROFILE_DIR}"` if !File.directory?(PROV_PROFILE_DIR)
62
-
63
- # Look through each file in the list
64
- Dir.foreach(PROV_PROFILE_DIR) do |item|
65
- next if item == '.' or item == '..'
66
-
67
- next if !/#{UUID_REGEX}\.mobileprovision/.match(item)
68
- puts "Prov. profile: #{item}" if DEBUG
69
-
70
- old_prov_profile = File.open(PROV_PROFILE_DIR+"/"+item).read
71
-
72
- old_uuid = uuid_for_profile(old_prov_profile)
73
- old_app_id = app_id_from_profile(old_prov_profile)
74
- old_cdate = creation_date_from_profile(old_prov_profile)
75
- old_is_dev = has_provisioned_devices(old_prov_profile)
76
-
77
- if old_app_id == new_app_id and old_cdate < new_cdate and old_is_dev == new_is_dev
78
- puts "Removing stale Prov Profile: #{item}"
79
- File.unlink PROV_PROFILE_DIR+'/'+item
80
- end
15
+ IosProvisioningProfile.install(profile_path)
16
+ end
81
17
  end
82
18
 
83
- new_profile_path = PROV_PROFILE_DIR+"/#{new_uuid}.mobileprovision"
84
- puts "Installing new prov profile into #{new_profile_path}"
85
- `cp -f "#{profile_file}" "#{new_profile_path}"`
19
+ InstallProvProfile.new.run(ARGV)
@@ -0,0 +1,128 @@
1
+ require 'fileutils'
2
+
3
+ module IosAndroidToolbox
4
+ class IosProvisioningProfile
5
+ PROV_PROFILE_DIR=ENV['HOME']+'/Library/MobileDevice/Provisioning Profiles'
6
+ UUID_REGEX='[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}'
7
+
8
+ DEBUG=false
9
+
10
+ attr_reader :contents
11
+
12
+ def uuid
13
+ # <key>UUID</key>
14
+ # <string>06AF2826-608D-4CE9-99AE-AA917FF1641E</string>
15
+ if /<key>UUID<\/key>\s*<string>(#{UUID_REGEX})<\/string>/.match(contents)
16
+ puts "Found UUID: #{$1}" if DEBUG
17
+ uuid = $1
18
+ else
19
+ nil
20
+ end
21
+ end
22
+
23
+ def app_id
24
+ # <key>application-identifier</key>
25
+ # <string>NDVAA33T9J.com.favequest.FFSApp.87.ircpa</string>
26
+ if /<key>application-identifier<\/key>\s*<string>[A-Za-z0-9]+\.([^<]+)<\/string>/.match(contents)
27
+ puts "Found app Id: #{$1}" if DEBUG
28
+ app_id = $1
29
+ else
30
+ nil
31
+ end
32
+ end
33
+
34
+ def creation_date
35
+ # <key>CreationDate</key>
36
+ # <date>2011-08-30T02:11:55Z</date>
37
+ if /<key>CreationDate<\/key>\s*<date>([^<]+)<\/date>/.match(contents)
38
+ #creation_date = Date.strptime($1, '%Y-%m-%dT%h:%M:%sZ')
39
+ creation_date = Time.parse($1)
40
+ puts "Found Creation date: #{creation_date.to_s}" if DEBUG
41
+ creation_date
42
+ else
43
+ nil
44
+ end
45
+ end
46
+
47
+ def has_provisioned_devices?
48
+ # <key>ProvisionedDevices</key>
49
+ /<key>ProvisionedDevices<\/key>/.match(contents)
50
+ end
51
+
52
+ def initialize(contents)
53
+ # If we specify a path, read it first
54
+ begin
55
+ if File.exists? contents and not File.directory? contents
56
+ contents = File.open(contents).read
57
+ end
58
+ rescue
59
+ end
60
+ @contents = contents
61
+ end
62
+
63
+ def self.remove_stale_equivalent_profiles(path)
64
+ new_profile = IosProvisioningProfile.new(path)
65
+
66
+ # Look through each file in the list
67
+ # Dir.glob(File.join(PROV_PROFILE_DIR,"*.mobileprovision")) do |installed_profile_path|
68
+
69
+ # next if not /#{UUID_REGEX}\.mobileprovision$/.match(installed_profile_path)
70
+ # puts "Examining prov. profile: #{installed_profile_path}" if DEBUG
71
+
72
+ # installed_profile = IosProvisioningProfile.new(File.open(installed_profile_path).read)
73
+
74
+ self.loop_through_existing_profiles do |installed_profile|
75
+ if installed_profile.app_id == new_profile.app_id and
76
+ installed_profile.creation_date < new_profile.creation_date and
77
+ installed_profile.has_provisioned_devices? == new_profile.has_provisioned_devices?
78
+ puts "Removing stale Prov Profile: #{installed_profile_path}"
79
+ File.delete installed_profile_path
80
+ end
81
+ end
82
+ end
83
+
84
+ def self.install(path)
85
+ if not File.directory? PROV_PROFILE_DIR
86
+ FileUtils.mkdir_p PROV_PROFILE_DIR
87
+ FileUtils.chmod 0755, PROV_PROFILE_DIR
88
+ end
89
+
90
+ new_profile = IosProvisioningProfile.new(path)
91
+ new_path = File.join(PROV_PROFILE_DIR, new_profile.uuid+".mobileprovision")
92
+
93
+ if File.expand_path(path) != File.expand_path(new_path)
94
+ if profile_worth_installing? path
95
+ self.remove_stale_equivalent_profiles(path)
96
+ FileUtils.copy(path, new_path)
97
+ end
98
+ else
99
+ puts "Cannot install new profile over itself!"
100
+ end
101
+ end
102
+
103
+ def self.profile_worth_installing?(path)
104
+ new_profile = IosProvisioningProfile.new(path)
105
+ loop_through_existing_profiles do |installed_profile|
106
+ if installed_profile.app_id == new_profile.app_id
107
+ return false if installed_profile.creation_date >= new_profile.creation_date
108
+ end
109
+ end
110
+
111
+ true
112
+ end
113
+
114
+ private
115
+ def self.loop_through_existing_profiles(&block)
116
+ # Look through each file in the list
117
+ Dir.glob(File.join(PROV_PROFILE_DIR,"*.mobileprovision")) do |installed_profile_path|
118
+
119
+ next if not /#{UUID_REGEX}\.mobileprovision$/.match(installed_profile_path)
120
+ puts "Examining prov. profile: #{installed_profile_path}" if DEBUG
121
+
122
+ installed_profile = IosProvisioningProfile.new(File.open(installed_profile_path).read)
123
+
124
+ yield installed_profile
125
+ end
126
+ end
127
+ end
128
+ end
@@ -1,3 +1,3 @@
1
1
  module IosAndroidToolbox
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ios_android_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 13
10
- version: 0.0.13
9
+ - 14
10
+ version: 0.0.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Igor Sales
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-26 00:00:00 Z
18
+ date: 2012-08-21 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: ""
@@ -58,6 +58,7 @@ files:
58
58
  - lib/ios_android_toolbox/android.rb
59
59
  - lib/ios_android_toolbox/base.rb
60
60
  - lib/ios_android_toolbox/ios.rb
61
+ - lib/ios_android_toolbox/ios_prov_profile.rb
61
62
  - lib/ios_android_toolbox/version.rb
62
63
  homepage: ""
63
64
  licenses: []