Module: FreeBSD::Pkg
Instance Attribute Summary
Attributes included from Beaker::CommandFactory
Instance Method Summary collapse
- #check_for_package(package, opts = {}) ⇒ Object
- #check_pkgng_sh ⇒ Object
- #install_package(package, cmdline_args = nil, _version = nil, opts = {}) ⇒ Object
- #pkg_info_pattern(package) ⇒ Object
- #pkgng_active?(opts = {}) ⇒ Boolean
- #uninstall_package(package, cmdline_args = nil, opts = {}) ⇒ Object
Methods included from Beaker::CommandFactory
Instance Method Details
#check_for_package(package, opts = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/beaker/host/freebsd/pkg.rb', line 37 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 |
#check_pkgng_sh ⇒ Object
9 10 11 12 |
# File 'lib/beaker/host/freebsd/pkg.rb', line 9 def check_pkgng_sh 'TMPDIR=/dev/null ASSUME_ALWAYS_YES=1 PACKAGESITE=file:///nonexist ' \ 'pkg info -x "pkg(-devel)?\\$" > /dev/null 2>&1' end |
#install_package(package, cmdline_args = nil, _version = nil, opts = {}) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/beaker/host/freebsd/pkg.rb', line 19 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 |
#pkg_info_pattern(package) ⇒ Object
4 5 6 7 |
# File 'lib/beaker/host/freebsd/pkg.rb', line 4 def pkg_info_pattern(package) # This seemingly restrictive pattern prevents false positives... "^#{package}-[0-9][0-9a-zA-Z_\\.,]*$" end |
#pkgng_active?(opts = {}) ⇒ Boolean
14 15 16 17 |
# File 'lib/beaker/host/freebsd/pkg.rb', line 14 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 |
#uninstall_package(package, cmdline_args = nil, opts = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/beaker/host/freebsd/pkg.rb', line 28 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 |