@@ -22,36 +22,29 @@ def exists?
22
22
# if already installed, check if it is the right one.
23
23
# if not installed, return false.
24
24
# if we are removing, don't care if it is the right one.
25
- if Facter . value ( :profiles ) . include? resource [ :name ]
25
+ state = getinstalledstate
26
+ if state != false
26
27
if resource [ :ensure ] == :absent
27
28
return true
28
29
else
29
- return current
30
+ begin
31
+ return state [ 'install_date' ] . to_time == getreceipts [ resource [ :name ] ] [ 'install_date' ]
32
+ rescue NoMethodError
33
+ # no matching receipt
34
+ return false
35
+ end
30
36
end
31
37
else
32
38
return false
33
39
end
34
40
end
35
41
36
- def getinstalleddate
37
- # must be rerun as the output from Facter's earlier run is now
38
- # outdated, but this only runs on refresh so not horrible.
39
- output = Puppet ::Util ::Execution . execute ( '/usr/sbin/system_profiler SPConfigurationProfileDataType -xml' )
40
-
41
- for item in Puppet ::Util ::Plist . parse_plist ( output ) [ 0 ] [ '_items' ] [ 0 ] [ '_items' ]
42
- if item [ 'spconfigprofile_profile_identifier' ] == resource [ :name ]
43
- return DateTime . parse ( item [ 'spconfigprofile_install_date' ] . scan ( /\( ([^\) ]+)\) / ) . last . first )
44
- end
45
- end
46
- end
47
-
48
42
def getreceipts
49
43
begin
50
- receipts = Puppet ::Util ::Plist . read_plist_file ( Facter . value ( :puppet_vardir ) + '/mobileconfigs/receipts.plist' )
44
+ receipts = Puppet ::Util ::Plist . read_plist_file ( Puppet [ :vardir ] + '/mobileconfigs/receipts.plist' )
51
45
rescue IOError , Errno ::ENOENT
52
46
receipts = { }
53
47
end
54
-
55
48
receipts
56
49
end
57
50
@@ -61,15 +54,28 @@ def writereceipt
61
54
# code from the fact but needs to re-run immediately.
62
55
receipts = getreceipts
63
56
64
- receipts [ resource [ :name ] ] = { 'install_date' => getinstalleddate }
57
+ receipts [ resource [ :name ] ] = { 'install_date' => getinstalledstate [ 'install_date' ] }
65
58
66
- Puppet ::Util ::Plist . write_plist_file ( receipts , Facter . value ( :puppet_vardir ) + '/mobileconfigs/receipts.plist' )
59
+ Puppet ::Util ::Plist . write_plist_file ( receipts , Puppet [ :vardir ] + '/mobileconfigs/receipts.plist' )
67
60
end
68
61
69
- def current
70
- return getinstalleddate . to_time == getreceipts [ resource [ :name ] ] [ 'install_date' ]
71
- rescue NoMethodError
72
- # no matching receipt
62
+ def getinstalledstate
63
+ output = Puppet ::Util ::Execution . execute ( '/usr/sbin/system_profiler SPConfigurationProfileDataType -xml' )
64
+
65
+ data = Puppet ::Util ::Plist . parse_plist ( output ) [ 0 ] [ '_items' ]
66
+
67
+ unless data . empty?
68
+ for item in data [ 0 ] [ '_items' ]
69
+ if item [ 'spconfigprofile_profile_identifier' ] == resource [ :name ]
70
+ return {
71
+ 'identifier' => item [ 'spconfigprofile_profile_identifier' ] ,
72
+ 'display_name' => item [ '_name' ] ,
73
+ 'uuid' => item [ 'spconfigprofile_profile_uuid' ] ,
74
+ 'install_date' => DateTime . parse ( item [ 'spconfigprofile_install_date' ] . scan ( /\( ([^\) ]+)\) / ) . last . first )
75
+ }
76
+ end
77
+ end
78
+ end
73
79
return false
74
80
end
75
81
end
0 commit comments