bin/d3helper in depot3-3.0.8 vs bin/d3helper in depot3-3.0.9

- old
+ new

@@ -70,11 +70,15 @@ ### Setup ### Initialization should only be used to set variables ### and set up the infrasctructure. No actual processing/error checking ### until the run method is called. ### - def initialize(args) + def initialize + + # Debugging file? if so, always set debug. + ARGV << "--debug" if D3::DEBUG_FILE.exist? + opts = GetoptLong.new( [ '--help', '-h', '-H', GetoptLong::NO_ARGUMENT ], [ '--debug', '-d', GetoptLong::NO_ARGUMENT ], [ '--import-casper-receipts', GetoptLong::NO_ARGUMENT ], [ '--display-puppy-notification', GetoptLong::NO_ARGUMENT ], @@ -273,32 +277,33 @@ d3_pkg_filenames = D3::Package.all_filenames.invert # this is an array of current d3 receipt ids d3_rcpt_ids = D3::Client::Receipt.all.values.map{|r| r.id} - now = Time.now - JSS::Client.receipts.each do |jss_rcpt| - # jss_rcpt is a Pathname object, the rcpt name is the paths basename + # jss_rcpt is a Pathname object, the rcpt name is the path's basename jss_rcpt_name = jss_rcpt.basename.to_s # do we have a match? pkg_id = d3_pkg_filenames[jss_rcpt_name] - # if not, the filename might end with .zip, but the rcpt name doesnt + + # if not, the filename might end with .zip, but the rcpt name doesn't pkg_id ||= d3_pkg_filenames[jss_rcpt_name + ".zip"] + # if still not, this jss recipt doesn't point to a d3 package. next unless pkg_id # If we're here, the jss receipt might need to be imported, unless its # already been imported next if d3_rcpt_ids.include? pkg_id # If we're here, we need to import the receipt, so get the matching D3 # package and make a receipt from it. D3.log "Importing Casper Receipt #{jss_rcpt_name}", :warn + begin d3_pkg = D3::Package.new id: pkg_id # do we already have a rcpt for the package's basename? if so, # delete it - we can only have on rcpt per basename @@ -310,42 +315,43 @@ d3_rcpt = D3::Client::Receipt.new( :basename => d3_pkg.basename, :version => d3_pkg.version, :revision => d3_pkg.revision, - :admin => D3::AUTO_INSTALL_ADMIN, + :admin => "imported-from-casper", :id => d3_pkg.id, :status => d3_pkg.status , :jamf_rcpt_file => jss_rcpt, - :apple_pkg_ids => nil, + :apple_pkg_ids => d3_pkg.apple_receipt_data.map{|rd| rd[:apple_pkg_id]}, :installed_at => jss_rcpt.mtime, :removable => d3_pkg.removable, :expiration => d3_pkg.expiration, :expiration_path => d3_pkg.expiration_path, :prohibiting_process => d3_pkg.prohibiting_process, :pre_remove_script_id => d3_pkg.pre_remove_script_id, :post_remove_script_id => d3_pkg.post_remove_script_id ) D3::Client::Receipt.add_receipt d3_rcpt, :replace - D3.log "Done. Imported Casper Receipt #{jss_rcpt_name}", :warn rescue D3.log "ERROR importing Casper Receipt #{jss_rcpt_name}: #{$!}", :error end - D3.log "Done importing Casper Receipts for packages in d3", :warn end #JSS::Client.receipts.each do |jss_rcpt| + D3.log "Done importing Casper Receipts for packages in d3", :warn + + end #import_receipts end # class App ############ # Go ############ begin app = nil - app = App.new(ARGV) + app = App.new app.run exit 0 rescue $stderr.puts "An error occurred: #{$!}" $stderr.puts $@ if D3::CONFIG.log_level == :debug or (app and app.debug)