Sha256: 454364e4d66f8af8623666b80cc6d4f6a51fc694c6a3f59555396e1112be9358
Contents?: true
Size: 1.26 KB
Versions: 46
Compression:
Stored size: 1.26 KB
Contents
class Facter::Core::Execution::Posix < Facter::Core::Execution::Base DEFAULT_SEARCH_PATHS = ['/sbin', '/usr/sbin'] def search_paths # Make sure facter is usable even for non-root users. Most commands # in /sbin (like ifconfig) can be run as non privileged users as # long as they do not modify anything - which we do not do with facter ENV['PATH'].split(File::PATH_SEPARATOR) + DEFAULT_SEARCH_PATHS end def which(bin) if absolute_path?(bin) return bin if File.executable?(bin) else search_paths.each do |dir| dest = File.join(dir, bin) return dest if File.executable?(dest) end end nil end ABSOLUTE_PATH_REGEX = %r{^/} def absolute_path?(path) !! (path =~ ABSOLUTE_PATH_REGEX) end DOUBLE_QUOTED_COMMAND = /^"(.+?)"(?:\s+(.*))?/ SINGLE_QUOTED_COMMAND = /^'(.+?)'(?:\s+(.*))?/ def expand_command(command) exe = nil args = nil if (match = (command.match(DOUBLE_QUOTED_COMMAND) || command.match(SINGLE_QUOTED_COMMAND))) exe, args = match.captures else exe, args = command.split(/ /,2) end if exe and (expanded = which(exe)) expanded = "'#{expanded}'" if expanded.match(/\s/) expanded << " #{args}" if args return expanded end end end
Version data entries
46 entries across 46 versions & 1 rubygems