Sha256: 57a96a2d5c28949e6091c14e9888b49823dc5795ffd757ed06a65b7b961071e4

Contents?: true

Size: 1.11 KB

Versions: 37

Compression:

Stored size: 1.11 KB

Contents

module FreeBSD::Pkg
  include Beaker::CommandFactory

  def pkg_info_pattern(package)
    # This seemingly restrictive pattern prevents false positives...
    "^#{package}-[0-9][0-9a-zA-Z_\\.,]*$"
  end

  def check_pkgng_sh
    'TMPDIR=/dev/null ASSUME_ALWAYS_YES=1 PACKAGESITE=file:///nonexist ' \
    'pkg info -x "pkg(-devel)?\\$" > /dev/null 2>&1'
  end

  def pkgng_active?(opts = {})
    opts = {:accept_all_exit_codes => true}.merge(opts)
    execute("/bin/sh -c '#{check_pkgng_sh}'", opts) { |r| r }.exit_code == 0
  end

  def install_package(package, cmdline_args = nil, opts = {})
    cmd = if pkgng_active?
            "pkg install #{cmdline_args || '-y'} #{package}"
          else
            "pkg_add #{cmdline_args || '-r'} #{package}"
          end
    execute(cmd, opts) { |result| result }
  end

  def check_for_package(package, opts = {})
    opts = {:accept_all_exit_codes => true}.merge(opts)
    cmd = if pkgng_active?
            "pkg info #{package}"
          else
            "pkg_info -Ix '#{pkg_info_pattern(package)}'"
          end
    execute(cmd, opts) { |result| result }.exit_code == 0
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
beaker-3.37.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.36.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.35.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.34.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.33.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.32.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.31.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.30.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.29.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.28.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.27.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.26.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.25.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.24.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.23.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.22.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.21.1 lib/beaker/host/freebsd/pkg.rb
beaker-3.21.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.20.0 lib/beaker/host/freebsd/pkg.rb
beaker-3.19.0 lib/beaker/host/freebsd/pkg.rb