Module: Jamf::Client::JamfBinary::ClassMethods
- Defined in:
- lib/jamf/client/jamf_binary.rb
Overview
class Methods
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
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/jamf/client/jamf_binary.rb', line 101 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
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/jamf/client/jamf_binary.rb', line 115 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)
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/jamf/client/jamf_binary.rb', line 89 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 |