Module: Chef::Provider::Package::Freebsd::PortsHelper

Included in:
Pkg, Port
Defined in:
lib/chef/provider/package/freebsd/base.rb

Instance Method Summary collapse

Instance Method Details

#makefile_variable_value(variable, dir = nil) ⇒ Object


58
59
60
61
62
# File 'lib/chef/provider/package/freebsd/base.rb', line 58

def makefile_variable_value(variable, dir = nil)
  options = dir ? { cwd: dir } : {}
  make_v = shell_out_compact_timeout!("make", "-V", variable, options.merge!(env: nil, returns: [0, 1]))
  make_v.exitstatus == 0 ? make_v.stdout.strip.split($OUTPUT_RECORD_SEPARATOR).first : nil # $\ is the line separator, i.e. newline.
end

#port_dir(port) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/chef/provider/package/freebsd/base.rb', line 36

def port_dir(port)
  case port

  # When the package name starts with a '/' treat it as the full path to the ports directory.
  when /^\//
    port

  # Otherwise if the package name contains a '/' not at the start (like 'www/wordpress') treat
  # as a relative path from /usr/ports.
  when /\//
    "/usr/ports/#{port}"

  # Otherwise look up the path to the ports directory using 'whereis'
  else
    whereis = shell_out_compact_timeout!("whereis", "-s", port, env: nil)
    unless path = whereis.stdout[/^#{Regexp.escape(port)}:\s+(.+)$/, 1]
      raise Chef::Exceptions::Package, "Could not find port with the name #{port}"
    end
    path
  end
end

#supports_ports?Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/chef/provider/package/freebsd/base.rb', line 32

def supports_ports?
  ::File.exist?("/usr/ports/Makefile")
end