lib/jss-api/client.rb in jss-api-0.5.8 vs lib/jss-api/client.rb in jss-api-0.6.1

- old
+ new

@@ -1,28 +1,28 @@ -### Copyright 2014 Pixar -### +### Copyright 2016 Pixar +### ### Licensed under the Apache License, Version 2.0 (the "Apache License") ### with the following modification; you may not use this file except in ### compliance with the Apache License and the following modification to it: ### Section 6. Trademarks. is deleted and replaced with: -### +### ### 6. Trademarks. This License does not grant permission to use the trade ### names, trademarks, service marks, or product names of the Licensor ### and its affiliates, except as required to comply with Section 4(c) of ### the License and to reproduce the content of the NOTICE file. -### +### ### You may obtain a copy of the Apache License at -### +### ### http://www.apache.org/licenses/LICENSE-2.0 -### +### ### Unless required by applicable law or agreed to in writing, software ### distributed under the Apache License with the above modification is ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ### KIND, either express or implied. See the Apache License for the specific ### language governing permissions and limitations under the Apache License. -### ### +### ### module JSS ##################################### @@ -54,11 +54,11 @@ ##################################### ### The Pathname to the jamf binary executable ### As of El Capitan (OS X 10.11) the location has moved. ORIG_JAMF_BINARY = Pathname.new "/usr/sbin/jamf" - ELCAP_JAMF_BINARY = Pathname.new "/usr/local/sbin/jamf" + ELCAP_JAMF_BINARY = Pathname.new "/usr/local/jamf/bin/jamf" JAMF_BINARY = ELCAP_JAMF_BINARY.executable? ? ELCAP_JAMF_BINARY : ORIG_JAMF_BINARY ### The Pathname to the jamfHelper executable JAMF_HELPER = Pathname.new "/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper" @@ -107,11 +107,11 @@ ##################################### ##################################### ### Class Methods ##################################### - + ### ### Get the current IP address as a String. ### ### This handy code doesn't acutally make a UDP connection, ### it just starts to set up the connection, then uses that to get @@ -124,11 +124,11 @@ ### def self.my_ip_address ### turn off reverse DNS resolution temporarily ### @note the 'socket' library has already been required by 'rest-client' orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true - + UDPSocket.open do |s| s.connect '192.168.0.0', 1 s.addr.last end ensure @@ -241,28 +241,27 @@ ### ### @return [Hash] the HardwareDataType data from the system_profiler command ### def self.hardware_data - Plist.parse_xml(`system_profiler SPHardwareDataType -xml`)[0]["_items"][0] + raw = `/usr/sbin/system_profiler SPHardwareDataType -xml 2>/dev/null` + Plist.parse_xml(raw)[0]["_items"][0] end - + ### Run an arbitrary jamf binary command. ### ### @note Most jamf commands require superuser/root privileges. ### - ### Run an arbitrary jamf binary command. - ### ### @param command[String,Symbol] the jamf binary command to run ### The command is the single jamf command that comes after the/usr/bin/jamf. ### ### @param args[String,Array] the arguments passed to the jamf command. ### This is to be passed to Kernel.` (backtick), after being combined with the ### jamf binary and the jamf command ### - ### @param show_output[Boolean] Should the stdout & stderr of the jamf binary be sent to + ### @param verbose[Boolean] Should the stdout & stderr of the jamf binary be sent to ### the current stdout in realtime, as well as returned as a string? ### ### @return [String] the stdout & stderr of the jamf binary. ### ### @example @@ -274,12 +273,11 @@ ### ### ### The details of the Process::Status for the jamf binary process can be captured from $? ### immediately after calling. (See Process::Status) ### - ### - def self.run_jamf(command, args = nil, show_output = false) + def self.run_jamf(command, args = nil, verbose = false) raise JSS::UnmanagedError, "The jamf binary is not installed on this computer." unless self.installed? raise JSS::UnsupportedError, "You must have root privileges to run that jamf binary command" unless ROOTLESS_JAMF_COMMANDS.include? command.to_sym or JSS.superuser? cmd = case args when nil @@ -290,19 +288,22 @@ "#{([JAMF_BINARY.to_s, command] + args).join(' ')}" else raise JSS::InvalidDataError, "args must be a String or Array of Strings" end # case + cmd += " -verbose" if verbose and (not cmd.include? " -verbose") + puts "Running: #{cmd}" if verbose + output = [] IO.popen("#{cmd} 2>&1") do |proc| while line = proc.gets output << line - puts line if show_output + puts line if verbose end end - - return output.join('') - + install_out = output.join('') + install_out.force_encoding("UTF-8") if install_out.respond_to? :force_encoding + return install_out end # run_jamf ### A wrapper for the jamfHelper command, which can display a window on the client machine. ###