Sha256: 972c7f7acf45640fa969173f4fdc666c5f0e5435310332ec64d78528ead76766

Contents?: true

Size: 1.41 KB

Versions: 14

Compression:

Stored size: 1.41 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, _version = 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 uninstall_package(package, cmdline_args = nil, opts = {})
    cmd = if pkgng_active?
            "pkg delete #{cmdline_args || '-y'} #{package}"
          else
            "pkg_delete #{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

14 entries across 14 versions & 1 rubygems

Version Path
beaker-6.4.1 lib/beaker/host/freebsd/pkg.rb
beaker-6.4.0 lib/beaker/host/freebsd/pkg.rb
beaker-6.3.0 lib/beaker/host/freebsd/pkg.rb
beaker-6.2.0 lib/beaker/host/freebsd/pkg.rb
beaker-6.1.0 lib/beaker/host/freebsd/pkg.rb
beaker-5.8.1 lib/beaker/host/freebsd/pkg.rb
beaker-5.8.0 lib/beaker/host/freebsd/pkg.rb
beaker-5.7.0 lib/beaker/host/freebsd/pkg.rb
beaker-5.6.0 lib/beaker/host/freebsd/pkg.rb
beaker-5.5.0 lib/beaker/host/freebsd/pkg.rb
beaker-5.4.0 lib/beaker/host/freebsd/pkg.rb
beaker-5.3.1 lib/beaker/host/freebsd/pkg.rb
beaker-5.3.0 lib/beaker/host/freebsd/pkg.rb
beaker-5.2.0 lib/beaker/host/freebsd/pkg.rb