depot3 0.0.0a1 → 3.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +55 -1
  3. data/bin/d3 +323 -0
  4. data/bin/d3admin +1011 -0
  5. data/bin/d3helper +354 -0
  6. data/bin/puppytime +334 -0
  7. data/data/d3/com.pixar.d3.RepoMan.plist +23 -0
  8. data/data/d3/d3.conf.example +507 -0
  9. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftAppKit.dylib +0 -0
  10. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCore.dylib +0 -0
  11. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCoreData.dylib +0 -0
  12. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCoreGraphics.dylib +0 -0
  13. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCoreImage.dylib +0 -0
  14. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftDarwin.dylib +0 -0
  15. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftDispatch.dylib +0 -0
  16. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftFoundation.dylib +0 -0
  17. data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftObjectiveC.dylib +0 -0
  18. data/data/d3/d3RepoMan.app/Contents/Info.plist +56 -0
  19. data/data/d3/d3RepoMan.app/Contents/MacOS/d3RepoMan +0 -0
  20. data/data/d3/d3RepoMan.app/Contents/PkgInfo +1 -0
  21. data/data/d3/d3RepoMan.app/Contents/Resources/Base.lproj/MainMenu.nib +0 -0
  22. data/data/d3/d3RepoMan.app/Contents/Resources/last-foreground-times-template.plist +5 -0
  23. data/data/d3/d3RepoMan.app/Contents/_CodeSignature/CodeResources +214 -0
  24. data/data/d3/puppytime/ImageLicenses.txt +165 -0
  25. data/data/d3/puppytime/notification_image +1 -0
  26. data/data/d3/puppytime/opt_out_image +1 -0
  27. data/data/d3/puppytime/slideshow/2008-07-11_White_German_Shepherd_pup_chilling_at_the_Coker_Arboretum.jpg +0 -0
  28. data/data/d3/puppytime/slideshow/2009-04-21_APBT_pup_on_deck.jpg +0 -0
  29. data/data/d3/puppytime/slideshow/A_puppy_Yorkie.jpg +0 -0
  30. data/data/d3/puppytime/slideshow/Alert_Pug_Puppy.jpg +0 -0
  31. data/data/d3/puppytime/slideshow/Australian_Cattle_Dog_puppies_04.JPG +0 -0
  32. data/data/d3/puppytime/slideshow/Beagle_puppy_Cadet.jpg +0 -0
  33. data/data/d3/puppytime/slideshow/Bernese_Mountain_Dog.jpg +0 -0
  34. data/data/d3/puppytime/slideshow/Bloodhound_Puppy.jpg +0 -0
  35. data/data/d3/puppytime/slideshow/Boston_terrier_with_toy.jpg +0 -0
  36. data/data/d3/puppytime/slideshow/Boxer_puppy_fawn_portrai.jpg +0 -0
  37. data/data/d3/puppytime/slideshow/Caracal_kitten.jpg +0 -0
  38. data/data/d3/puppytime/slideshow/Chihuahua_&_Doberman_Pup.jpg +0 -0
  39. data/data/d3/puppytime/slideshow/Cuccioli_di_Margot_a_35_gg_Basenjis.jpg +0 -0
  40. data/data/d3/puppytime/slideshow/Dalmatian_puppy_03.jpg +0 -0
  41. data/data/d3/puppytime/slideshow/GoldenRetrieverPuppyDaisyParker.JPG +0 -0
  42. data/data/d3/puppytime/slideshow/Green_eyed_beige_Chihuahua.jpg +0 -0
  43. data/data/d3/puppytime/slideshow/Let_Sleeping_Dogs_Lie.jpg +0 -0
  44. data/data/d3/puppytime/slideshow/Meatball_-_French_Bulldog_Puppy.jpg +0 -0
  45. data/data/d3/puppytime/slideshow/Oola_-_9_weeks.jpg +0 -0
  46. data/data/d3/puppytime/slideshow/Pancho0008.JPG +0 -0
  47. data/data/d3/puppytime/slideshow/Pomeranian_orange-sable_Coco.jpg +0 -0
  48. data/data/d3/puppytime/slideshow/Pug_puppy_001.jpg +0 -0
  49. data/data/d3/puppytime/slideshow/Puggle_puppy_6_weeks.JPG +0 -0
  50. data/data/d3/puppytime/slideshow/Puli_kan.jpg +0 -0
  51. data/data/d3/puppytime/slideshow/Puppy_French_Bulldog.jpg +0 -0
  52. data/data/d3/puppytime/slideshow/Rocco_the_Bulldog.jpg +0 -0
  53. data/data/d3/puppytime/slideshow/Rottweiler_Face.jpg +0 -0
  54. data/data/d3/puppytime/slideshow/Saint_Bernard_puppy.jpg +0 -0
  55. data/data/d3/puppytime/slideshow/Scottish_froment.jpg +0 -0
  56. data/data/d3/puppytime/slideshow/Shar_pei_puppy_(age_2_months).jpg +0 -0
  57. data/data/d3/puppytime/slideshow/Shiba-Inu_beim_Spielen_im_Schnee.JPG +0 -0
  58. data/data/d3/puppytime/slideshow/Smooth-coat_Border_Collie_puppy..jpg +0 -0
  59. data/data/d3/puppytime/slideshow/Smooth_Dachshund_puppies.jpg +0 -0
  60. data/data/d3/puppytime/slideshow/Snow_dog.jpg +0 -0
  61. data/data/d3/puppytime/slideshow/Taylor_the_Pembroke_Welsh_Corgi.png +0 -0
  62. data/data/d3/puppytime/slideshow/Weim_Pups_001.jpg +0 -0
  63. data/data/d3/puppytime/slideshow/Westie_pups.jpg +0 -0
  64. data/data/d3/puppytime/slideshow/Yellow_Labrador_puppies_(4165737325).jpg +0 -0
  65. data/lib/d3/admin/add.rb +451 -0
  66. data/lib/d3/admin/auth.rb +470 -0
  67. data/lib/d3/admin/edit.rb +297 -0
  68. data/lib/d3/admin/help.rb +396 -0
  69. data/lib/d3/admin/interactive.rb +972 -0
  70. data/lib/d3/admin/options.rb +454 -0
  71. data/lib/d3/admin/prefs.rb +204 -0
  72. data/lib/d3/admin/report.rb +727 -0
  73. data/lib/d3/admin/state.rb +42 -0
  74. data/lib/d3/admin/validate.rb +413 -0
  75. data/lib/d3/admin.rb +42 -0
  76. data/lib/d3/basename.rb +217 -0
  77. data/lib/d3/client/auth.rb +108 -0
  78. data/lib/d3/client/class_methods.rb +766 -0
  79. data/lib/d3/client/class_variables.rb +47 -0
  80. data/lib/d3/client/cli.rb +187 -0
  81. data/lib/d3/client/environment.rb +134 -0
  82. data/lib/d3/client/help.rb +110 -0
  83. data/lib/d3/client/lists.rb +314 -0
  84. data/lib/d3/client/receipt.rb +1173 -0
  85. data/lib/d3/client.rb +45 -0
  86. data/lib/d3/configuration.rb +319 -0
  87. data/lib/d3/constants.rb +60 -0
  88. data/lib/d3/database.rb +488 -0
  89. data/lib/d3/exceptions.rb +44 -0
  90. data/lib/d3/log.rb +271 -0
  91. data/lib/d3/package/aliases.rb +80 -0
  92. data/lib/d3/package/attributes.rb +97 -0
  93. data/lib/d3/package/class_methods.rb +817 -0
  94. data/lib/d3/package/class_variables.rb +46 -0
  95. data/lib/d3/package/client_actions.rb +293 -0
  96. data/lib/d3/package/constants.rb +58 -0
  97. data/lib/d3/package/constructor.rb +191 -0
  98. data/lib/d3/package/getters.rb +164 -0
  99. data/lib/d3/package/mixins.rb +39 -0
  100. data/lib/d3/package/private_methods.rb +227 -0
  101. data/lib/d3/package/questions.rb +95 -0
  102. data/lib/d3/package/server_actions.rb +683 -0
  103. data/lib/d3/package/setters.rb +326 -0
  104. data/lib/d3/package/validate.rb +448 -0
  105. data/lib/d3/package.rb +51 -0
  106. data/lib/d3/puppytime/pending_puppy.rb +108 -0
  107. data/lib/d3/puppytime/puppy_queue.rb +274 -0
  108. data/lib/d3/puppytime.rb +68 -0
  109. data/lib/d3/state.rb +105 -0
  110. data/lib/d3/utility.rb +325 -0
  111. data/lib/d3/version.rb +1 -1
  112. metadata +162 -9
@@ -0,0 +1,164 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+
26
+ module D3
27
+ class Package < JSS::Package
28
+
29
+ ### @return [String,nil] - The name of the pre-install script for this pkg, or nil if none
30
+ ###
31
+ def pre_install_script_name
32
+ return nil unless @pre_install_script_id
33
+ JSS::Script.map_all_ids_to(:name)[@pre_install_script_id]
34
+ end
35
+
36
+ ### @return [String,nil] - The name of the post install script for this pkg, or nil if none
37
+ ###
38
+ def post_install_script_name
39
+ return nil unless @post_install_script_id
40
+ JSS::Script.map_all_ids_to(:name)[@post_install_script_id]
41
+ end
42
+
43
+ ### @return [String,nil] - The name of the pre remove script for this pkg, or nil if none
44
+ ###
45
+ def pre_remove_script_name
46
+ return nil unless @pre_remove_script_id
47
+ JSS::Script.map_all_ids_to(:name)[@pre_remove_script_id]
48
+ end
49
+
50
+ ### @return [String,nil] - The name of the post remove script for this pkg, or nil if none
51
+ ###
52
+ def post_remove_script_name
53
+ return nil unless @post_remove_script_id
54
+ JSS::Script.map_all_ids_to(:name)[@post_remove_script_id]
55
+ end
56
+
57
+ ### @return [Hash{Symbol=>Integer}] The type and ids of all pre- and post- scripts
58
+ ### for this pkg.
59
+ def script_ids
60
+ {
61
+ :pre_install => @pre_install_script_id,
62
+ :post_install => @post_install_script_id,
63
+ :pre_remove => @pre_remove_script_id,
64
+ :post_remove => @post_remove_script_id
65
+ }
66
+ end
67
+
68
+ ### @return [Hash{Symbol=>String}] The type and names of all pre- and post- scripts
69
+ ### for this pkg.
70
+ def script_names
71
+ {
72
+ :pre_install => @pre_install_script_name,
73
+ :post_install => @post_install_script_name,
74
+ :pre_remove => @pre_remove_script_name,
75
+ :post_remove => @post_remove_script_name
76
+ }
77
+ end
78
+
79
+ ### Generate a human-readable string of details about this installer
80
+ ###
81
+ ### @return [String] the package details in a human readble format.
82
+ ###
83
+ def formatted_details
84
+ os_disp = JSS.to_s_and_a(@os_requirements)[:stringform]
85
+ auto_disp = JSS.to_s_and_a(@auto_groups)[:stringform]
86
+ excl_disp = JSS.to_s_and_a(@excluded_groups)[:stringform]
87
+
88
+ msg = <<-END_DEETS
89
+ Edition: #{edition}
90
+ Status: #{@status}
91
+ ---- Description ----
92
+ #{@notes.gsub("\r", "\n") if @notes}
93
+ ---------------------
94
+ Added by: #{@added_by or 'unknown'}
95
+ Added date: #{@added_date ? @added_date.strftime('%Y-%m-%d') : 'unknown'}
96
+ Casper Package: #{@name} (id: #{@id})
97
+ Filename: #{@filename}
98
+ Category: #{@category or 'None'}
99
+ Needs reboot (puppytime): #{@reboot_required or 'false'}
100
+ Un-installable: #{removable? or 'false'}
101
+ Pre-install script: #{pre_install_script_name or 'None'}
102
+ Post-install script: #{post_install_script_name or 'None'}
103
+ Pre-remove script: #{pre_remove_script_name or 'None'}
104
+ Post-remove script: #{post_remove_script_name or 'None'}
105
+ CPU limitation: #{@required_processor or 'None'}
106
+ OS limitations: #{os_disp.empty? ? 'None' : os_disp}
107
+ Uninstalls older versions: #{@remove_first or 'false'}
108
+ Installation prohibited by process: #{@prohibiting_process or 'None'}
109
+ Auto installed for groups: #{auto_disp.empty? ? 'None' : auto_disp}
110
+ Excluded for groups: #{excl_disp.empty? ? 'None' : excl_disp}
111
+ Expiration period: #{@expiration.to_i} days
112
+ Expiration path: #{@expiration_path}
113
+ Released by: #{@released_by or '-'}
114
+ Release date: #{@release_date ? @release_date.strftime('%Y-%m-%d') : '-'}
115
+ END_DEETS
116
+ end #formatted_details
117
+
118
+ ### The index of this package
119
+ ### This is an array of paths (as Strings) from the pkg's Casper index
120
+ ###
121
+ ### @param files_only[Boolean] ignore directories, only return files
122
+ ###
123
+ ### @return [Array<String>]
124
+ ###
125
+ def index (files_only = false)
126
+ q = "SELECT file FROM #{PKG_CONTENTS_TABLE} WHERE package_id = #{@id}"
127
+ q += " AND mode NOT LIKE 'd%'" if files_only
128
+ @index = []
129
+ JSS::DB_CNX.db.query(q).each {|record| @index << record[0]}
130
+ @index
131
+ end
132
+
133
+ ### Get an array of files installed by this pkg
134
+ ### Note that this does not show directories.
135
+ ### use #index to see dirs as well
136
+ ###
137
+ ### @return [Array<Pathname>] the files installed
138
+ ###
139
+ def installed_files
140
+ index :files_only
141
+ end
142
+
143
+ ### An Array of ids of all Casper policies using this package
144
+ ###
145
+ ### @return [Array<Integer>] the policy ids using this package.
146
+ ###
147
+ def policy_ids
148
+ qry = <<-ENDQ
149
+ SELECT p.policy_id
150
+ FROM policies p
151
+ JOIN policy_packages pp
152
+ ON p.policy_id = pp.policy_id
153
+ WHERE pp.package_id = '#{@id}'
154
+ ENDQ
155
+ res = JSS::DB_CNX.db.query qry
156
+ pols = []
157
+ res.each{|r| pols << r[0].to_i }
158
+ res.free
159
+ pols
160
+ end
161
+
162
+
163
+ end # class Package
164
+ end # module D3
@@ -0,0 +1,39 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+
26
+ module D3
27
+ class Package < JSS::Package
28
+
29
+ ################# Mixin Modules #################
30
+
31
+ ### The D3::Basename module provides common attributes and methods related to
32
+ ### d3's use of 'basenames' and 'editions'
33
+ include D3::Basename
34
+
35
+ include D3::Package::Validate
36
+
37
+
38
+ end # class Package
39
+ end # module D3
@@ -0,0 +1,227 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+
26
+ module D3
27
+ class Package < JSS::Package
28
+
29
+ ################# Private Instance Methods #################
30
+ private
31
+
32
+ ### Is there a process running that would prevent installation?
33
+ ###
34
+ ### @return [Boolean]
35
+ ###
36
+ def install_prohibited_by_process?
37
+ return false unless @prohibiting_process
38
+ D3.prohibited_by_process_running? @prohibiting_process
39
+ end #
40
+
41
+ ### If needed, uninstall any previously installed versions of this basename
42
+ ###
43
+ def remove_previous_installs_if_needed (verbose = false)
44
+ if @remove_first && D3::Client::Receipt.basenames.include?(@basename)
45
+ previous_rcpt = D3::Client::Receipt.all[@basename]
46
+ if previous_rcpt.removable?
47
+ D3.log "Uninstalling previously installed version of #{@basename}" , :info
48
+ begin
49
+ D3::Client.set_env :uninstalling_before_install, previous_rcpt.edition
50
+ previous_rcpt.uninstall(verbose)
51
+ ensure
52
+ D3::Client.unset_env :uninstalling_before_install
53
+ end # begin
54
+ else
55
+ D3.log "Previously installed version of #{@basename} is not uninstallable, not uninstalling.", :info
56
+ end # if previous_rcpt.removable?
57
+ end # @remove_first && D3::Client::Receipt.basenames
58
+ end # remove_previous_installs_if_needed
59
+
60
+ ### Create a new D3 receipt for this pkg and store it in the
61
+ ### receipts datastore.
62
+ ###
63
+ ### @return [void]
64
+ ###
65
+ def write_rcpt
66
+ new_rcpt = D3::Client::Receipt.new( :basename => @basename,
67
+ :version => @version,
68
+ :revision => @revision,
69
+ :admin => @admin,
70
+ :installed_at => Time.now,
71
+ :id => @id,
72
+ :status => @status,
73
+ :jamf_rcpt_file => @receipt,
74
+ :apple_pkg_ids => @apple_receipt_data.map{|r| r[:apple_pkg_id]},
75
+ :removable => removable?,
76
+ :pre_remove_script_id => @pre_remove_script_id,
77
+ :post_remove_script_id => @post_remove_script_id,
78
+ :expiration => @expiration_to_apply.to_i,
79
+ :expiration_path => @expiration_path,
80
+ :custom_expiration => @custom_expiration,
81
+ :prohibiting_process => @prohibiting_process)
82
+
83
+ D3::Client::Receipt.add_receipt new_rcpt, :replace
84
+
85
+ end # write_rcpt
86
+
87
+ ### Dump this pkg as a YAML marshalled string, for archiving
88
+ ###
89
+ ### @reutrn [String] the YAML representation of this pkg
90
+ ###
91
+ def package_yaml
92
+ YAML.dump self
93
+ end
94
+
95
+ def added_by= (name)
96
+ @added_by = name
97
+ end
98
+
99
+ def added_date= (date)
100
+ @added_date = date
101
+ end
102
+
103
+ def released_by= (name)
104
+ @released_by = name
105
+ end
106
+
107
+ def release_date= (date)
108
+ @release_date = date
109
+ end
110
+
111
+ def apple_receipt_data= (data)
112
+ @apple_receipt_data = data
113
+ end
114
+
115
+ ### Given one of the keys of the D3::Database::PACKAGE_TABLE[:field_definitions] hash,
116
+ ### convert the matching attribute value with the :to_sql Proc and return it.
117
+ ### If there is no matching attribute, assume the argument is a value
118
+ ### and return it Mysql.quoted.
119
+ ###
120
+ ### @param key[Symbol] the attribute to convert to SQL
121
+ ###
122
+ ### @return [String] the attribute value converted to an SQL-happy format
123
+ ###
124
+ def to_sql(key)
125
+ if key.is_a?(Symbol) and self.respond_to?(key)
126
+ return 'NULL' if self.send(key).to_s.empty?
127
+ if P_FIELDS[key] and P_FIELDS[key][:to_sql]
128
+ return Mysql.quote(P_FIELDS[key][:to_sql].call(self.send(key)).to_s)
129
+ else
130
+ return Mysql.quote(self.send(key).to_s)
131
+ end # if P_FIELDS[key] and P_FIELDS[key][:to_sql]
132
+ else
133
+ return Mysql.quote(key.to_s)
134
+ end # if key.is_a?(Symbol)
135
+ end # to_sql(key)
136
+
137
+ ### Given one of the keys of the D3::Database::PACKAGE_TABLE[:field_definitions] hash,
138
+ ### and a value from an SQL query, convert the SQL value to the appropriate Ruby value
139
+ ### with the :to_ruby Proc and return it
140
+ ###
141
+ ### @param key[Symbol] the attribute to convert to SQL
142
+ ###
143
+ ### @return [Object] the attribute value converted to an SQL-happy format
144
+ ###
145
+ def to_ruby(key, sql_val)
146
+ # Note = the d3pkgdata has already been 'rubyized' via the D3::Database.table_records method
147
+ # (which was used by D3::Package.package_data)
148
+ return sql_val unless P_FIELDS[key][:to_ruby]
149
+ return P_FIELDS[key][:to_ruby].call(sql_val)
150
+ end
151
+
152
+ ### Make this package not live, which could be described as killing it, but
153
+ ### I think it would be more like 'zombification',
154
+ ### leaving no pkg live for this basename
155
+ ###
156
+ ### @return [void]
157
+ ###
158
+ def deprecate(admin = @admin)
159
+
160
+ raise JSS::InvalidDataError, "Only live packages can be deprecated." unless @status == :live
161
+ @status = :deprecated
162
+ stmt = JSS::DB_CNX.db.prepare "UPDATE #{P_TABLE[:table_name]} SET #{P_FIELDS[:status][:field_name]} = #{to_sql :status} WHERE #{P_FIELDS[:id][:field_name]} = '#{@id}'"
163
+
164
+ stmt_result = stmt.execute
165
+
166
+ # update our knowledge of the world
167
+ D3::Package.package_data :refresh
168
+
169
+ @status
170
+ end
171
+
172
+ ### Delete any scripts associated with this pkg
173
+ ### but only if they aren't associated with other d3 pkgs or casper policies
174
+ ###
175
+ ### @return [Array<String>] a textual list of scripts and whether they were
176
+ ### deleted or not (and why not)
177
+ ###
178
+ def delete_pkg_scripts
179
+
180
+ # gather the ids of all scripts used by all policies
181
+ # this is a hash of arrays pol_name => [id,id,id]
182
+ policy_scripts = D3.policy_scripts
183
+
184
+ script_deletion_actions = []
185
+
186
+ scripts = [:pre_install_id , :post_install_id , :pre_remove_id , :post_remove_id ]
187
+
188
+ scripts.each do |script_type|
189
+
190
+ type_display = script_type.to_s.chomp('_id')
191
+
192
+ victim_script_id = self.send script_type
193
+ victim_script_name = JSS::Script.map_all_ids_to(:name)[victim_script_id]
194
+
195
+ # skip if not in jss
196
+ next unless JSS::Script.all_ids.include? victim_script_id
197
+
198
+ # these d3 pkg editions use this script
199
+ d3_users = (D3::Package.packages_for_script(victim_script_id) - [@id])
200
+ d3_users.map!{|pkgid| D3::Package.ids_to_editions[pkgid]}
201
+
202
+ # these policies use this script
203
+ policy_users = []
204
+ policy_scripts.each do |pol, pol_scripts|
205
+ policy_users << pol if pol_scripts.include? victim_script_id
206
+ end
207
+
208
+ if d3_users.empty? and policy_users.empty?
209
+ # delete the script!
210
+ JSS::Script.new(id: victim_script_id).delete
211
+ script_deletion_actions << "deleted #{type_display} script '#{victim_script_name}'"
212
+ else
213
+ # add the info to the returned report
214
+ d3_users.each {|edition| script_deletion_actions << "#{type_display} script '#{victim_script_name}' is in use by d3 package: #{edition}"}
215
+ policy_users.each {|pol_name| script_deletion_actions << "#{type_display} script '#{victim_script_name}' is in use by policy: #{pol_name}"}
216
+ end # if both empty
217
+
218
+ end # scripts.each do |script_type|
219
+
220
+ return script_deletion_actions
221
+
222
+ end # delete_scripts
223
+
224
+
225
+
226
+ end # class Package
227
+ end # module D3
@@ -0,0 +1,95 @@
1
+ ### Copyright 2016 Pixar
2
+ ###
3
+ ### Licensed under the Apache License, Version 2.0 (the "Apache License")
4
+ ### with the following modification; you may not use this file except in
5
+ ### compliance with the Apache License and the following modification to it:
6
+ ### Section 6. Trademarks. is deleted and replaced with:
7
+ ###
8
+ ### 6. Trademarks. This License does not grant permission to use the trade
9
+ ### names, trademarks, service marks, or product names of the Licensor
10
+ ### and its affiliates, except as required to comply with Section 4(c) of
11
+ ### the License and to reproduce the content of the NOTICE file.
12
+ ###
13
+ ### You may obtain a copy of the Apache License at
14
+ ###
15
+ ### http://www.apache.org/licenses/LICENSE-2.0
16
+ ###
17
+ ### Unless required by applicable law or agreed to in writing, software
18
+ ### distributed under the Apache License with the above modification is
19
+ ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ ### KIND, either express or implied. See the Apache License for the specific
21
+ ### language governing permissions and limitations under the Apache License.
22
+ ###
23
+ ###
24
+
25
+
26
+ module D3
27
+ class Package < JSS::Package
28
+
29
+ ### @return [Boolean] Does this pkg have a pre-install script?
30
+ def pre_install_script?
31
+ not @pre_install_script_id.nil?
32
+ end
33
+
34
+ ### @return [Boolean] Does this pkg have a post-install script?
35
+ def post_install_script?
36
+ not @post_install_script_id.nil?
37
+ end
38
+
39
+ ### @return [Boolean] Does this pkg have a pre-remove script?
40
+ def pre_remove_script?
41
+ not @pre_remove_script_id.nil?
42
+ end
43
+
44
+ ### @return [Boolean] Does this pkg have a post-remove script?
45
+ def post_remove_script?
46
+ not @post_remove_script_id.nil?
47
+ end
48
+
49
+ ### @return [Boolean] Is this pkg in on the server?
50
+ ###
51
+ def created?
52
+ @in_jss and @in_d3
53
+ end
54
+
55
+ ### @return [Boolean] Is this pkg on the server?
56
+ ###
57
+ def saved?
58
+ not (@need_to_update or @need_to_update_d3)
59
+ end
60
+
61
+ ### @return [Boolean] Is this pkg in pilot? (saved, but never made live)
62
+ ###
63
+ def deprecated?
64
+ @status == :deprecated
65
+ end
66
+
67
+ ### @return [Boolean] Is this pkg in pilot? (saved, but never made live)
68
+ ###
69
+ def skipped?
70
+ @status == :skipped
71
+ end
72
+
73
+ ### @return [Boolean] Is this pkg installed on this machine via d3?
74
+ ### Note: this overrides JSS::Package#installed?
75
+ ###
76
+ def installed?
77
+ D3::Client::Receipt.basenames.include?(@basename) and D3::Client::Receipt.all[@basename].id == @id
78
+ end
79
+
80
+ ### @return [Boolean] Does this pkg expire by default?
81
+ ###
82
+ def expires?
83
+ @expiration.to_i > 0 && @expiration_path
84
+ end
85
+
86
+ ### @return [Boolean] Is this pkg 'indexed' in the jss, so that it can be removable?
87
+ ###
88
+ def indexed?
89
+ not index.empty?
90
+ end # indexed?
91
+
92
+
93
+
94
+ end # class Package
95
+ end # module D3