Class: OSX::ProvisioningProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/keychain_osx/provisioningprofile.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ProvisioningProfile

Returns a new instance of ProvisioningProfile.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/keychain_osx/provisioningprofile.rb', line 8

def initialize(path)

      raise "Provisioning profile '#{path}' does not exist" unless File.exists? path

      @path = path
      @identifiers = []
      @devices = []
      @appstore = true
      @enterprise = false

      uuid = nil
      find_profile_uuid(path)
end

Instance Attribute Details

#appstoreObject (readonly)

Returns the value of attribute appstore.



6
7
8
# File 'lib/keychain_osx/provisioningprofile.rb', line 6

def appstore
  @appstore
end

#devicesObject (readonly)

Returns the value of attribute devices.



6
7
8
# File 'lib/keychain_osx/provisioningprofile.rb', line 6

def devices
  @devices
end

#identifiersObject (readonly)

Returns the value of attribute identifiers.



6
7
8
# File 'lib/keychain_osx/provisioningprofile.rb', line 6

def identifiers
  @identifiers
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/keychain_osx/provisioningprofile.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/keychain_osx/provisioningprofile.rb', line 6

def path
  @path
end

#uuidObject (readonly)

Returns the value of attribute uuid.



6
7
8
# File 'lib/keychain_osx/provisioningprofile.rb', line 6

def uuid
  @uuid
end

Class Method Details

.find_installed_by_uuid(uuid) ⇒ Object



96
97
98
99
100
# File 'lib/keychain_osx/provisioningprofile.rb', line 96

def self.find_installed_by_uuid uuid
    ProvisioningProfile.installed_profiles.each do |p|
        return p if p.uuid == uuid
    end
end

.installed_profile(name) ⇒ Object



102
103
104
# File 'lib/keychain_osx/provisioningprofile.rb', line 102

def self.installed_profile(name)
    self.installed_profiles.select {|p| p.name == name.to_s}.first;
end

.installed_profilesObject



90
91
92
93
94
# File 'lib/keychain_osx/provisioningprofile.rb', line 90

def self.installed_profiles
    Dir["#{self.profiles_path}/*.mobileprovision"].map do |file|
        ProvisioningProfile.new(file)
    end
end

.profiles_pathObject



63
64
65
# File 'lib/keychain_osx/provisioningprofile.rb', line 63

def self.profiles_path
    File.expand_path "~/Library/MobileDevice/Provisioning\ Profiles/"
end

Instance Method Details

#appstore?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/keychain_osx/provisioningprofile.rb', line 55

def appstore?
    @appstore
end

#enterprise?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/keychain_osx/provisioningprofile.rb', line 59

def enterprise?
    @enterprise
end

#find_profile_uuid(path) ⇒ Object



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
# File 'lib/keychain_osx/provisioningprofile.rb', line 22

def find_profile_uuid(path)
    File.open(path, "rb") do |f|
        input = f.read

        if input=~/ProvisionedDevices/
            @appstore = false
        end

        if input=~/<key>ProvisionsAllDevices<\/key>/
            @enterprise = true
        end

        if input=~/<key>ProvisionedDevices<\/key>.*?<array>(.*?)<\/array>/im
            $1.split(/<string>/).each do |id|
                  next if id.nil? or id.strip==""
                  @devices << id.gsub(/<\/string>/,'').strip
            end
        end

        input=~/<key>UUID<\/key>.*?<string>(.*?)<\/string>/im
        @uuid = $1.strip

        input=~/<key>Name<\/key>.*?<string>(.*?)<\/string>/im
        @name = $1.strip

        input=~/<key>ApplicationIdentifierPrefix<\/key>.*?<array>(.*?)<\/array>/im
        $1.split(/<string>/).each do |id|
            next if id.nil? or id.strip==""
            @identifiers << id.gsub(/<\/string>/,'').strip
        end
    end
end

#installObject



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/keychain_osx/provisioningprofile.rb', line 71

def install
    # Do not reinstall if profile is same and is already installed
    return if (self.path == self.install_path.gsub(/\\ /, ' '))

    ProvisioningProfile.installed_profiles.each do |installed|
        if installed.identifiers==self.identifiers and installed.uuid==self.uuid
          installed.uninstall
        end
    end

    FileUtils.mkdir_p(File.dirname(self.install_path))
    FileUtils.cp(self.path, self.install_path)
end

#install_pathObject



67
68
69
# File 'lib/keychain_osx/provisioningprofile.rb', line 67

def install_path
    "#{ProvisioningProfile.profiles_path}/#{self.uuid}.mobileprovision"
end

#uninstallObject



85
86
87
88
# File 'lib/keychain_osx/provisioningprofile.rb', line 85

def uninstall
    command = "rm -f #{self.install_path}"
    OSX::Command::run(command)
end