depot3 0.0.0a1 → 3.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +55 -1
- data/bin/d3 +323 -0
- data/bin/d3admin +1011 -0
- data/bin/d3helper +354 -0
- data/bin/puppytime +334 -0
- data/data/d3/com.pixar.d3.RepoMan.plist +23 -0
- data/data/d3/d3.conf.example +507 -0
- data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftAppKit.dylib +0 -0
- data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCore.dylib +0 -0
- data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCoreData.dylib +0 -0
- data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCoreGraphics.dylib +0 -0
- data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftCoreImage.dylib +0 -0
- data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftDarwin.dylib +0 -0
- data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftDispatch.dylib +0 -0
- data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftFoundation.dylib +0 -0
- data/data/d3/d3RepoMan.app/Contents/Frameworks/libswiftObjectiveC.dylib +0 -0
- data/data/d3/d3RepoMan.app/Contents/Info.plist +56 -0
- data/data/d3/d3RepoMan.app/Contents/MacOS/d3RepoMan +0 -0
- data/data/d3/d3RepoMan.app/Contents/PkgInfo +1 -0
- data/data/d3/d3RepoMan.app/Contents/Resources/Base.lproj/MainMenu.nib +0 -0
- data/data/d3/d3RepoMan.app/Contents/Resources/last-foreground-times-template.plist +5 -0
- data/data/d3/d3RepoMan.app/Contents/_CodeSignature/CodeResources +214 -0
- data/data/d3/puppytime/ImageLicenses.txt +165 -0
- data/data/d3/puppytime/notification_image +1 -0
- data/data/d3/puppytime/opt_out_image +1 -0
- data/data/d3/puppytime/slideshow/2008-07-11_White_German_Shepherd_pup_chilling_at_the_Coker_Arboretum.jpg +0 -0
- data/data/d3/puppytime/slideshow/2009-04-21_APBT_pup_on_deck.jpg +0 -0
- data/data/d3/puppytime/slideshow/A_puppy_Yorkie.jpg +0 -0
- data/data/d3/puppytime/slideshow/Alert_Pug_Puppy.jpg +0 -0
- data/data/d3/puppytime/slideshow/Australian_Cattle_Dog_puppies_04.JPG +0 -0
- data/data/d3/puppytime/slideshow/Beagle_puppy_Cadet.jpg +0 -0
- data/data/d3/puppytime/slideshow/Bernese_Mountain_Dog.jpg +0 -0
- data/data/d3/puppytime/slideshow/Bloodhound_Puppy.jpg +0 -0
- data/data/d3/puppytime/slideshow/Boston_terrier_with_toy.jpg +0 -0
- data/data/d3/puppytime/slideshow/Boxer_puppy_fawn_portrai.jpg +0 -0
- data/data/d3/puppytime/slideshow/Caracal_kitten.jpg +0 -0
- data/data/d3/puppytime/slideshow/Chihuahua_&_Doberman_Pup.jpg +0 -0
- data/data/d3/puppytime/slideshow/Cuccioli_di_Margot_a_35_gg_Basenjis.jpg +0 -0
- data/data/d3/puppytime/slideshow/Dalmatian_puppy_03.jpg +0 -0
- data/data/d3/puppytime/slideshow/GoldenRetrieverPuppyDaisyParker.JPG +0 -0
- data/data/d3/puppytime/slideshow/Green_eyed_beige_Chihuahua.jpg +0 -0
- data/data/d3/puppytime/slideshow/Let_Sleeping_Dogs_Lie.jpg +0 -0
- data/data/d3/puppytime/slideshow/Meatball_-_French_Bulldog_Puppy.jpg +0 -0
- data/data/d3/puppytime/slideshow/Oola_-_9_weeks.jpg +0 -0
- data/data/d3/puppytime/slideshow/Pancho0008.JPG +0 -0
- data/data/d3/puppytime/slideshow/Pomeranian_orange-sable_Coco.jpg +0 -0
- data/data/d3/puppytime/slideshow/Pug_puppy_001.jpg +0 -0
- data/data/d3/puppytime/slideshow/Puggle_puppy_6_weeks.JPG +0 -0
- data/data/d3/puppytime/slideshow/Puli_kan.jpg +0 -0
- data/data/d3/puppytime/slideshow/Puppy_French_Bulldog.jpg +0 -0
- data/data/d3/puppytime/slideshow/Rocco_the_Bulldog.jpg +0 -0
- data/data/d3/puppytime/slideshow/Rottweiler_Face.jpg +0 -0
- data/data/d3/puppytime/slideshow/Saint_Bernard_puppy.jpg +0 -0
- data/data/d3/puppytime/slideshow/Scottish_froment.jpg +0 -0
- data/data/d3/puppytime/slideshow/Shar_pei_puppy_(age_2_months).jpg +0 -0
- data/data/d3/puppytime/slideshow/Shiba-Inu_beim_Spielen_im_Schnee.JPG +0 -0
- data/data/d3/puppytime/slideshow/Smooth-coat_Border_Collie_puppy..jpg +0 -0
- data/data/d3/puppytime/slideshow/Smooth_Dachshund_puppies.jpg +0 -0
- data/data/d3/puppytime/slideshow/Snow_dog.jpg +0 -0
- data/data/d3/puppytime/slideshow/Taylor_the_Pembroke_Welsh_Corgi.png +0 -0
- data/data/d3/puppytime/slideshow/Weim_Pups_001.jpg +0 -0
- data/data/d3/puppytime/slideshow/Westie_pups.jpg +0 -0
- data/data/d3/puppytime/slideshow/Yellow_Labrador_puppies_(4165737325).jpg +0 -0
- data/lib/d3/admin/add.rb +451 -0
- data/lib/d3/admin/auth.rb +470 -0
- data/lib/d3/admin/edit.rb +297 -0
- data/lib/d3/admin/help.rb +396 -0
- data/lib/d3/admin/interactive.rb +972 -0
- data/lib/d3/admin/options.rb +454 -0
- data/lib/d3/admin/prefs.rb +204 -0
- data/lib/d3/admin/report.rb +727 -0
- data/lib/d3/admin/state.rb +42 -0
- data/lib/d3/admin/validate.rb +413 -0
- data/lib/d3/admin.rb +42 -0
- data/lib/d3/basename.rb +217 -0
- data/lib/d3/client/auth.rb +108 -0
- data/lib/d3/client/class_methods.rb +766 -0
- data/lib/d3/client/class_variables.rb +47 -0
- data/lib/d3/client/cli.rb +187 -0
- data/lib/d3/client/environment.rb +134 -0
- data/lib/d3/client/help.rb +110 -0
- data/lib/d3/client/lists.rb +314 -0
- data/lib/d3/client/receipt.rb +1173 -0
- data/lib/d3/client.rb +45 -0
- data/lib/d3/configuration.rb +319 -0
- data/lib/d3/constants.rb +60 -0
- data/lib/d3/database.rb +488 -0
- data/lib/d3/exceptions.rb +44 -0
- data/lib/d3/log.rb +271 -0
- data/lib/d3/package/aliases.rb +80 -0
- data/lib/d3/package/attributes.rb +97 -0
- data/lib/d3/package/class_methods.rb +817 -0
- data/lib/d3/package/class_variables.rb +46 -0
- data/lib/d3/package/client_actions.rb +293 -0
- data/lib/d3/package/constants.rb +58 -0
- data/lib/d3/package/constructor.rb +191 -0
- data/lib/d3/package/getters.rb +164 -0
- data/lib/d3/package/mixins.rb +39 -0
- data/lib/d3/package/private_methods.rb +227 -0
- data/lib/d3/package/questions.rb +95 -0
- data/lib/d3/package/server_actions.rb +683 -0
- data/lib/d3/package/setters.rb +326 -0
- data/lib/d3/package/validate.rb +448 -0
- data/lib/d3/package.rb +51 -0
- data/lib/d3/puppytime/pending_puppy.rb +108 -0
- data/lib/d3/puppytime/puppy_queue.rb +274 -0
- data/lib/d3/puppytime.rb +68 -0
- data/lib/d3/state.rb +105 -0
- data/lib/d3/utility.rb +325 -0
- data/lib/d3/version.rb +1 -1
- metadata +162 -9
data/lib/d3/admin/add.rb
ADDED
@@ -0,0 +1,451 @@
|
|
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
|
+
module Admin
|
28
|
+
module Add
|
29
|
+
extend self
|
30
|
+
|
31
|
+
### These are the symbols representing all the possible commandline options
|
32
|
+
### used for defining new packages.
|
33
|
+
NEW_PKG_OPTIONS = %w{
|
34
|
+
version
|
35
|
+
revision
|
36
|
+
package_name
|
37
|
+
description
|
38
|
+
filename
|
39
|
+
category
|
40
|
+
oses
|
41
|
+
cpu_type
|
42
|
+
reboot
|
43
|
+
removable
|
44
|
+
remove_first
|
45
|
+
prohibiting_process
|
46
|
+
auto_groups
|
47
|
+
excluded_groups
|
48
|
+
pre_install
|
49
|
+
post_install
|
50
|
+
pre_remove
|
51
|
+
post_remove
|
52
|
+
expiration
|
53
|
+
expiration_path
|
54
|
+
source_path
|
55
|
+
}.map{|i| i.to_sym}
|
56
|
+
|
57
|
+
### If we need to build the pkg, these options are needed
|
58
|
+
BUILD_OPTIONS = [:workspace, :package_build_type]
|
59
|
+
|
60
|
+
### If we are building a .pkg these options are needed
|
61
|
+
PKG_OPTIONS = [:pkg_identifier, :pkg_preserve_owners]
|
62
|
+
|
63
|
+
### Continuously loop through displaying the add-package menu, and getting
|
64
|
+
### new values, until the user types 'x'.
|
65
|
+
###
|
66
|
+
### @param options[OpenStruct] the starting values to offer the user
|
67
|
+
###
|
68
|
+
### @return [OpenStruct] the new_package_options with validated data
|
69
|
+
###
|
70
|
+
def loop_thru_add_walkthru (options)
|
71
|
+
|
72
|
+
inherited_line = options.inherited_from ? "with values inherited from '#{options.inherited_from}'" : "with global default values"
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
choice = nil
|
77
|
+
|
78
|
+
# loop until the user types an x
|
79
|
+
while choice != "x"
|
80
|
+
walkthru_menu_header = <<-END_HEADER
|
81
|
+
------------------------------------
|
82
|
+
Adding pilot d3 package '#{options.edition or options.basename}'
|
83
|
+
#{inherited_line}
|
84
|
+
------------------------------------
|
85
|
+
END_HEADER
|
86
|
+
menu_options = NEW_PKG_OPTIONS
|
87
|
+
if options.source_path and get_package_type_from_source(options.source_path) == :root_folder
|
88
|
+
menu_options += BUILD_OPTIONS
|
89
|
+
menu_options += PKG_OPTIONS if options.package_build_type == :pkg
|
90
|
+
end
|
91
|
+
|
92
|
+
choice = D3::Admin::Interactive.get_menu_choice( walkthru_menu_header, walkthru_menu_lines(menu_options, options) )
|
93
|
+
|
94
|
+
if choice == 'x'
|
95
|
+
(options, errors) = validate_all_new_package_options options
|
96
|
+
if errors.empty?
|
97
|
+
break # while
|
98
|
+
else
|
99
|
+
puts "***** ERRORS *****"
|
100
|
+
puts errors.join "\n"
|
101
|
+
puts "*****"
|
102
|
+
puts "Type return to continue, ^c to exit"
|
103
|
+
gets
|
104
|
+
choice = 'not x'
|
105
|
+
end # if errors empty
|
106
|
+
else
|
107
|
+
|
108
|
+
# the number they chose becomes an option key like :reboot
|
109
|
+
chosen_opt = menu_options[choice]
|
110
|
+
|
111
|
+
# Here the value we're actually editing
|
112
|
+
current_opt_value = options[chosen_opt]
|
113
|
+
|
114
|
+
# if we're editing version or revision, and the current pkg or filenames are
|
115
|
+
# based on them then make a note to update the names when we get the new values
|
116
|
+
if chosen_opt == :basename or chosen_opt == :version or chosen_opt == :revision
|
117
|
+
update_edition = true
|
118
|
+
update_pkg_name = options.package_name.start_with? options.edition
|
119
|
+
update_filename = options.filename.start_with? options.edition
|
120
|
+
else
|
121
|
+
update_edition = false
|
122
|
+
update_pkg_name = false
|
123
|
+
update_filename = false
|
124
|
+
end
|
125
|
+
|
126
|
+
# if editing the source or the buildtype, we might have to update the
|
127
|
+
# names as well
|
128
|
+
if chosen_opt == :source_path or chosen_opt == :package_build_type
|
129
|
+
update_pkg_name = options.package_name =~ /\.(m?pkg|dmg)$/
|
130
|
+
update_filename = true
|
131
|
+
end
|
132
|
+
|
133
|
+
# prompt for a new value and put it in place
|
134
|
+
options[chosen_opt] = D3::Admin::Interactive.get_value(chosen_opt, current_opt_value, nil)
|
135
|
+
|
136
|
+
# if we edited the version or revision, we might need to update names and edition
|
137
|
+
options.edition = "#{options.basename}-#{options.version}-#{options.revision}" if update_edition
|
138
|
+
options.package_name = "#{options.edition}.#{options.package_build_type}" if update_pkg_name
|
139
|
+
options.filename = "#{options.edition}.#{options.package_build_type}" if update_filename
|
140
|
+
|
141
|
+
# if we edited the source path, we might need to update the names and the pkg build type
|
142
|
+
if chosen_opt == :source_path and options.source_path.extname =~ /\.(m?pkg|dmg)$/
|
143
|
+
options.package_name.sub(/\.(m?pkg|dmg)$/, options.source_path.extname)
|
144
|
+
options.filename.sub(/\.(m?pkg|dmg)$/, options.source_path.extname)
|
145
|
+
options.package_build_type = options.source_path.extname == ".dmg" ? :dmg : :pkg
|
146
|
+
end
|
147
|
+
|
148
|
+
# ditto if we edited the package_build_type
|
149
|
+
if chosen_opt == :package_build_type
|
150
|
+
options.package_name.sub(/\.(m?pkg|dmg)$/, options.package_build_type.to_s)
|
151
|
+
options.filename.sub(/\.(m?pkg|dmg)$/, options.package_build_type.to_s)
|
152
|
+
end
|
153
|
+
|
154
|
+
end #if choice == x
|
155
|
+
end # while choice not x
|
156
|
+
|
157
|
+
# return the options
|
158
|
+
options
|
159
|
+
|
160
|
+
end # loop_thru_add_walkthru
|
161
|
+
|
162
|
+
### Regenerate the walkthru menu lines
|
163
|
+
###
|
164
|
+
### @param menu_options[Array<Symbol>] the option keys that will be in
|
165
|
+
### the menu
|
166
|
+
###
|
167
|
+
### @param current_options[OpenStruct] the current option values
|
168
|
+
###
|
169
|
+
### @return [Array<String>] the lines of the walkthru menu
|
170
|
+
###
|
171
|
+
def walkthru_menu_lines (menu_options, current_options)
|
172
|
+
display_lines = []
|
173
|
+
|
174
|
+
menu_options.each_index do |i|
|
175
|
+
# the option symbol, like :reboot
|
176
|
+
#opt = NEW_PKG_OPTIONS[i]
|
177
|
+
opt = menu_options[i]
|
178
|
+
opt_def = D3::Admin::OPTIONS[opt]
|
179
|
+
label = opt_def[:label]
|
180
|
+
value = current_options[opt]
|
181
|
+
converter = opt_def[:display_conversion]
|
182
|
+
value_display = converter ? converter.call(value) : value
|
183
|
+
display_lines[i] = "#{label}: #{value_display}"
|
184
|
+
end
|
185
|
+
return display_lines
|
186
|
+
end # def walkthru_menu_lines
|
187
|
+
|
188
|
+
### Validate commandline options when adding a package without walkthru
|
189
|
+
### using defaults as needed.
|
190
|
+
### Some values will be prompted for if needed, since they
|
191
|
+
### are required and can't use defaults.
|
192
|
+
###
|
193
|
+
### @param cli_options[OpenStruct] the values from the command line
|
194
|
+
###
|
195
|
+
### @param new_package_options[OpenStruct] the repository for the
|
196
|
+
### validated data
|
197
|
+
###
|
198
|
+
### @return [OpenStruct] the new_package_options with validated data
|
199
|
+
###
|
200
|
+
def add_pilot_cli (cli_options)
|
201
|
+
(new_package_options, errors) = validate_all_new_package_options (cli_options)
|
202
|
+
if errors.empty?
|
203
|
+
return new_package_options
|
204
|
+
else
|
205
|
+
puts "***** ERRORS *****"
|
206
|
+
puts errors.join "\n"
|
207
|
+
puts "*****"
|
208
|
+
raise ArgumentError, "Errors in commandline options, see above."
|
209
|
+
end # if errors empty
|
210
|
+
end #validate_cli_add_pilot
|
211
|
+
|
212
|
+
### Validate all possible options for making a new pkg.
|
213
|
+
###
|
214
|
+
### This is used for both walkthru's and cli-specified options.
|
215
|
+
### Even though the walkthru validates options as they are entered,
|
216
|
+
### some need to be checked after all have been provided, e.g.
|
217
|
+
### possibly overlapping groups, edition conflicts, etc.
|
218
|
+
###
|
219
|
+
### @param options_from_user[OpenStruct] the collection of all options to check as a group.
|
220
|
+
### either from a walkthru or the command line
|
221
|
+
###
|
222
|
+
### @return [Array<OpenStruct, Array>] An array with two items: the possibly-validated options
|
223
|
+
### and an array of error messages, which should be empty if all options are valid.
|
224
|
+
###
|
225
|
+
def validate_all_new_package_options (options_from_user)
|
226
|
+
|
227
|
+
# what do we need to check
|
228
|
+
opts_to_check = NEW_PKG_OPTIONS
|
229
|
+
if options_from_user.source_path and get_package_type_from_source(options_from_user.source_path) == :root_folder
|
230
|
+
opts_to_check += BUILD_OPTIONS
|
231
|
+
opts_to_check += PKG_OPTIONS if options_from_user.package_build_type == :pkg
|
232
|
+
end
|
233
|
+
|
234
|
+
# gather the errors in here to be reported all at once
|
235
|
+
errors = []
|
236
|
+
|
237
|
+
# basic checks
|
238
|
+
opts_to_check.each do |opt|
|
239
|
+
puts "checking #{opt}: #{options_from_user[opt]}" if D3::Admin.debug
|
240
|
+
if options_from_user[opt] == D3::Admin::DFT_REQUIRED
|
241
|
+
errors << "Missing required value for #{D3::Admin::OPTIONS[opt][:label]}"
|
242
|
+
next
|
243
|
+
end
|
244
|
+
|
245
|
+
(valid, validated) = D3::Admin::Validate.validate(options_from_user[opt], D3::Admin::OPTIONS[opt][:validate])
|
246
|
+
if valid
|
247
|
+
options_from_user[opt] = validated
|
248
|
+
else
|
249
|
+
errors << validated
|
250
|
+
end
|
251
|
+
end # opts_to_check.each
|
252
|
+
|
253
|
+
# now check the edition
|
254
|
+
new_edition = "#{options_from_user.basename}-#{options_from_user.version}-#{options_from_user.revision}"
|
255
|
+
if D3::Package::Validate.edition_exist? new_edition
|
256
|
+
errors << "A package with edition '#{new_edition}' already exists in d3."
|
257
|
+
else
|
258
|
+
options_from_user.edition = new_edition
|
259
|
+
end
|
260
|
+
|
261
|
+
# group overlaps
|
262
|
+
begin
|
263
|
+
D3::Package::Validate.validate_non_overlapping_groups options_from_user[:auto_groups], options_from_user[:excluded_groups]
|
264
|
+
rescue JSS::InvalidDataError
|
265
|
+
errors << "Auto and Excluded group-lists can't contain groups in common."
|
266
|
+
end
|
267
|
+
|
268
|
+
# expiration path if expiration
|
269
|
+
if options_from_user[:expiration] > 0
|
270
|
+
errors << "expiration path cannot be empty if expiration is > 0 ." unless options_from_user[:expiration_path]
|
271
|
+
end
|
272
|
+
return [options_from_user, errors]
|
273
|
+
end # validate_all_new_package_options
|
274
|
+
|
275
|
+
### Figure out the default values for all options for creating a new package
|
276
|
+
###
|
277
|
+
### @param basename[String] the basename for the new pkg
|
278
|
+
###
|
279
|
+
### @return [OpenStruct] an ostruct with the default values
|
280
|
+
###
|
281
|
+
def get_default_options(basename, no_inherit)
|
282
|
+
|
283
|
+
dft_opts = OpenStruct.new
|
284
|
+
|
285
|
+
# first populate the opts from the defined defaults for anything that's still nil
|
286
|
+
D3::Admin::OPTIONS.each {|opt, settings| dft_opts[opt] = settings[:default]}
|
287
|
+
|
288
|
+
dft_opts.basename = basename
|
289
|
+
|
290
|
+
# next we grab stuff from the most recent pkg with this baseneme
|
291
|
+
# and apply anything there, if a basename was given
|
292
|
+
unless no_inherit
|
293
|
+
if D3::Package.all_basenames.include? basename
|
294
|
+
prev_pkg = D3::Package.most_recent_package_for(basename)
|
295
|
+
if prev_pkg
|
296
|
+
dft_opts = self.default_options_from_package(prev_pkg, dft_opts)
|
297
|
+
dft_opts.inherited_from = prev_pkg.edition
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end # if basename
|
301
|
+
|
302
|
+
# edition if available
|
303
|
+
if dft_opts.version and dft_opts.revision
|
304
|
+
dft_opts.edition = "#{dft_opts.basename}-#{dft_opts.version}-#{dft_opts.revision}"
|
305
|
+
else
|
306
|
+
dft_opts.edition = nil
|
307
|
+
end
|
308
|
+
|
309
|
+
# and if we have an edition, we have default pkg and file names
|
310
|
+
if dft_opts.edition
|
311
|
+
dft_opts.package_name = "#{dft_opts.edition}"
|
312
|
+
dft_opts.filename = "#{dft_opts.edition}.#{dft_opts.package_build_type}"
|
313
|
+
end
|
314
|
+
|
315
|
+
# then: any values stored in the admin prefs are applied...
|
316
|
+
# use the workspace from the prefs if it exists
|
317
|
+
dft_opts.workspace = D3::Admin::Prefs.prefs[:workspace]
|
318
|
+
dft_opts.workspace ||= D3::Admin::DFT_WORKSPACE
|
319
|
+
|
320
|
+
|
321
|
+
# use the pkg_identifier_prefix from the prefs
|
322
|
+
pfx = D3::Admin::Prefs.prefs[:apple_pkg_id_prefix]
|
323
|
+
pfx ||= D3::Admin::DFT_PKG_ID_PREFIX
|
324
|
+
dft_opts.pkg_identifier ||= "#{pfx}.#{basename}".gsub(/\.+/, '.')
|
325
|
+
|
326
|
+
# We now have our defaults for a new pkg
|
327
|
+
return dft_opts
|
328
|
+
|
329
|
+
end # populate_default_options
|
330
|
+
|
331
|
+
### Get default values from an existing d3 package, and use them to
|
332
|
+
### override the defined defaults
|
333
|
+
###
|
334
|
+
### @param pkg[D3::Package] the package from which to extract the values
|
335
|
+
###
|
336
|
+
### @param dft_opts[OpenStruct] an Ostruct with the defined defaults already
|
337
|
+
### populated
|
338
|
+
###
|
339
|
+
### @return [OpenStruct] an ostruct with the default values
|
340
|
+
###
|
341
|
+
def default_options_from_package(pkg, dft_opts = OpenStruct.new)
|
342
|
+
|
343
|
+
# populate the opts from the pkg, if the pkg has a value
|
344
|
+
D3::Admin::OPTIONS.keys.each do |opt|
|
345
|
+
next unless pkg.respond_to?(opt)
|
346
|
+
pkg_val = pkg.send(opt)
|
347
|
+
next if pkg_val.nil?
|
348
|
+
dft_opts[opt] = pkg_val
|
349
|
+
end # do opt
|
350
|
+
|
351
|
+
# bump the revision by 1
|
352
|
+
dft_opts.revision += 1
|
353
|
+
|
354
|
+
# never use the older package name or filename
|
355
|
+
dft_opts.package_name = nil
|
356
|
+
dft_opts.filename = nil
|
357
|
+
|
358
|
+
# grab the first pkg-id if it exists
|
359
|
+
# we might use it to if making a new pkg
|
360
|
+
if pkg.apple_receipt_data and pkg.apple_receipt_data[0] and pkg.apple_receipt_data[0][:apple_pkg_id]
|
361
|
+
dft_opts.pkg_identifier = pkg.apple_receipt_data[0][:apple_pkg_id]
|
362
|
+
end
|
363
|
+
|
364
|
+
dft_opts
|
365
|
+
end # default_values_from_package(pkg)
|
366
|
+
|
367
|
+
### Given a source_path, check if its a dmg, or .pkg
|
368
|
+
### Assumes the source_path has been checked and
|
369
|
+
### is valid.
|
370
|
+
###
|
371
|
+
### @param source_path[Pathname] the path to check
|
372
|
+
###
|
373
|
+
### @return [Symbol] :dmg, :pkg, or :root_folder
|
374
|
+
###
|
375
|
+
def get_package_type_from_source (source_path)
|
376
|
+
if source_path.to_s.end_with? ".dmg"
|
377
|
+
return :dmg
|
378
|
+
elsif source_path.to_s =~ /\.m?pkg$/
|
379
|
+
return :pkg
|
380
|
+
else
|
381
|
+
return :root_folder
|
382
|
+
end # if .source_path.to_s.end_with? ".dmg"
|
383
|
+
end
|
384
|
+
|
385
|
+
### Add the new pkg to d3
|
386
|
+
###
|
387
|
+
### @param new_package_options[OpenStruct] the verified options for the new package.
|
388
|
+
###
|
389
|
+
### @return [Integer] the JSS id of the new package
|
390
|
+
###
|
391
|
+
def add_new_package (new_package_options)
|
392
|
+
|
393
|
+
# new_package_options should now have all the validated data we need to make a new pkg
|
394
|
+
new_pilot = D3::Package.new(:id => :new,
|
395
|
+
:basename => new_package_options.basename,
|
396
|
+
:name => new_package_options.package_name,
|
397
|
+
:version => new_package_options.version,
|
398
|
+
:revision => new_package_options.revision,
|
399
|
+
:filename => new_package_options.filename,
|
400
|
+
:admin => ENV["USER"])
|
401
|
+
|
402
|
+
D3::Admin::Add::NEW_PKG_OPTIONS.each do |opt|
|
403
|
+
setter = "#{opt}=".to_sym
|
404
|
+
new_pilot.send setter, new_package_options.send(opt) if new_pilot.respond_to? setter
|
405
|
+
end
|
406
|
+
|
407
|
+
# do we need to build the pkg?
|
408
|
+
unless new_package_options.source_path.extname =~ /\.(m?pkg|dmg)$/
|
409
|
+
if new_package_options.package_build_type == :pkg
|
410
|
+
puts "Building .pkg..."
|
411
|
+
new_pkg_path = JSS::Composer.mk_pkg(new_package_options.package_name,
|
412
|
+
new_package_options.version,
|
413
|
+
new_package_options.source_path,
|
414
|
+
:pkg_id => new_package_options.pkg_identifier,
|
415
|
+
:out_dir => new_package_options.workspace,
|
416
|
+
:preserve_ownership => new_package_options.pkg_preserve_owners )
|
417
|
+
|
418
|
+
new_package_options.source_path = new_pkg_path
|
419
|
+
|
420
|
+
elsif new_package_options.package_build_type == :dmg
|
421
|
+
puts "Building .dmg..."
|
422
|
+
new_pkg_path = JSS::Composer.mk_dmg(new_package_options.package_name,
|
423
|
+
new_package_options.source_path,
|
424
|
+
new_package_options.workspace)
|
425
|
+
|
426
|
+
new_package_options.source_path = new_pkg_path
|
427
|
+
end # if new_package_options.package_build_type
|
428
|
+
end # unless
|
429
|
+
|
430
|
+
# save to d3
|
431
|
+
puts "Saving new pilot #{new_package_options.edition} to the server..."
|
432
|
+
|
433
|
+
new_pkg_id = new_pilot.save
|
434
|
+
|
435
|
+
puts "Indexing..."
|
436
|
+
# make the index - all d3 pkgs are indexed in the JSS
|
437
|
+
new_pilot.mk_index :local_filepath => new_package_options.source_path
|
438
|
+
|
439
|
+
# upload to dist point
|
440
|
+
# if its a .pkg, the apple rcpt data is updated during the upload
|
441
|
+
puts "Uploading to the Master Distribution Point..."
|
442
|
+
new_pilot.upload_master_file new_package_options.source_path, D3::Admin::Auth.rw_credentials(:dist)[:password]
|
443
|
+
|
444
|
+
return new_pkg_id
|
445
|
+
|
446
|
+
end # add_new_package
|
447
|
+
|
448
|
+
end # module Add
|
449
|
+
end # module Admin
|
450
|
+
end # module D3
|
451
|
+
|