Module: Jamf::Client::JamfBinary
- Included in:
- Jamf::Client
- Defined in:
- lib/jamf/client/jamf_binary.rb
Overview
Module for working with the Jamf Binary on a managed client mac This should be extended into Jamf::Client
Constant Summary collapse
- USR_LOCAL_BIN_FOLDER =
The bin folder with the jamf binary and a few other things
Pathname.new '/usr/local/jamf/bin'
- ORIG_JAMF_BINARY =
The Pathname to the jamf binary executable Before SIP (macOS 10.10 and below)
Pathname.new '/usr/sbin/jamf'
- SIP_JAMF_BINARY =
The Pathname to the jamf binary executable After SIP (OS X 10.11 and above)
USR_LOCAL_BIN_FOLDER + 'jamf'
- JAMF_BINARY =
The path to the jamf binary
SIP_JAMF_BINARY.executable? ? SIP_JAMF_BINARY : ORIG_JAMF_BINARY
- ROOTLESS_JAMF_COMMANDS =
These jamf commands don't need root privs (most do)
%i[ about checkJSSConnection getARDFields getComputerName help listUsers version ].freeze
- JAMF_VERBOSE_OPT =
the option that makes the jamf binary verbose
' -verbose'.freeze
Instance Method Summary collapse
- #build_jamf_command(command, args) ⇒ Object
- #execute_jamf(cmd, verbose) ⇒ Object
-
#run_jamf(command, args = nil, verbose = false) ⇒ String
Run an arbitrary jamf binary command.
Instance Method Details
#build_jamf_command(command, args) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/jamf/client/jamf_binary.rb', line 104 def build_jamf_command(command, args) case args when nil "#{JAMF_BINARY} #{command}" when String "#{JAMF_BINARY} #{command} #{args}" when Array ([JAMF_BINARY.to_s, command] + args).join(' ') else raise Jamf::InvalidDataError, 'args must be a String or Array of Strings' end # case end |
#execute_jamf(cmd, verbose) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/jamf/client/jamf_binary.rb', line 118 def execute_jamf(cmd, verbose) puts "Running: #{cmd}" if verbose output = '' IO.popen("#{cmd} 2>&1") do |proc| loop do line = proc.gets break unless line output << line puts line if verbose end end output.force_encoding('UTF-8') output end |
#run_jamf(command, args = nil, verbose = false) ⇒ String
Note:
Most jamf commands require superuser/root privileges.
Run an arbitrary jamf binary command.
The details of the Process::Status for the jamf binary process can be captured from $CHILD_STATUS immediately after calling. (See Process::Status)
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/jamf/client/jamf_binary.rb', line 92 def run_jamf(command, args = nil, verbose = false) raise Jamf::UnmanagedError, 'The jamf binary is not installed on this computer.' unless installed? unless ROOTLESS_JAMF_COMMANDS.include?(command.to_sym) || JSS.superuser? raise Jamf::UnsupportedError, 'You must have root privileges to run that jamf binary command' end cmd = build_jamf_command command, args cmd += " #{JAMF_VERBOSE_OPT}" if verbose && !cmd.include?(JAMF_VERBOSE_OPT) execute_jamf cmd, verbose end |