Module: Mac::Pkg

Includes:
Beaker::CommandFactory
Included in:
Host
Defined in:
lib/beaker/host/mac/pkg.rb

Instance Attribute Summary

Attributes included from Beaker::CommandFactory

#assertions

Instance Method Summary collapse

Methods included from Beaker::CommandFactory

#execute, #fail_test

Instance Method Details

#check_for_package(name) ⇒ Object



4
5
6
# File 'lib/beaker/host/mac/pkg.rb', line 4

def check_for_package(name)
  raise "Package #{name} cannot be queried on #{self}"
end

#determine_if_x86_64Boolean

Examine the host system to determine the architecture

Returns:

  • (Boolean)

    true if x86_64, false otherwise



72
73
74
75
# File 'lib/beaker/host/mac/pkg.rb', line 72

def determine_if_x86_64
  result = exec(Beaker::Command.new("uname -a | grep x86_64"), :expect_all_exit_codes => true)
  result.exit_code == 0
end

#generic_install_dmg(dmg_file, pkg_base, pkg_name) ⇒ Object

Install a package from a specified dmg

@example: Install vagrant from URL

mymachost.generic_install_dmg('https://releases.hashicorp.com/vagrant/1.8.4/vagrant_1.8.4.dmg', 'Vagrant', 'Vagrant.pkg')

Parameters:

  • dmg_file (String)

    The dmg file, including path if not relative. Can be a URL.

  • pkg_base (String)

    The base name of the directory that the dmg attaches to under ‘/Volumes`

  • pkg_name (String)

    The name of the package file that should be used by the installer. If the specified package is not found, a wildcard search will be performed to locate and install the first ‘.pkg` file in the volume.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/beaker/host/mac/pkg.rb', line 27

def generic_install_dmg(dmg_file, pkg_base, pkg_name)
  execute("test -f #{dmg_file}", :accept_all_exit_codes => true) do |result|
    execute("curl -O #{dmg_file}") unless result.exit_code == 0
  end
  dmg_name = File.basename(dmg_file, '.dmg')
  execute("hdiutil attach #{dmg_name}.dmg")

  # First check if the specific package exists, otherwise use wildcard
  specific_pkg_path = "/Volumes/#{pkg_base}/#{pkg_name}"
  execute("test -f #{specific_pkg_path}", :accept_all_exit_codes => true) do |result|
    if result.exit_code == 0
      # $pkg_name package found so install it
      execute("installer -pkg #{specific_pkg_path} -target /")
    else
      # else find and install the first *.pkg file in the volume
      execute <<~SCRIPT
        # find the first .pkg file in the mounted volume
        pkg=$(find /Volumes/#{pkg_base} -name "*.pkg" -type f -print -quit)
        if [ -n "$pkg" ]; then
          echo "Installing $pkg"
          installer -pkg "$pkg" -target /
        else
          echo "ERROR: No .pkg files found in /Volumes/#{pkg_base}/"
          exit 1
        fi
      SCRIPT
    end
  end
end

#install_package(name, _cmdline_args = '', _version = nil) ⇒ Object



8
9
10
11
12
# File 'lib/beaker/host/mac/pkg.rb', line 8

def install_package(name, _cmdline_args = '', _version = nil)
  # strip off any .dmg extension, if it exists
  name = File.basename(name, '.dmg')
  generic_install_dmg("#{name}.dmg", name, "#{name}.pkg")
end

#uninstall_package(name, _cmdline_args = '') ⇒ Object



57
58
59
# File 'lib/beaker/host/mac/pkg.rb', line 57

def uninstall_package(name, _cmdline_args = '')
  raise "Package #{name} cannot be uninstalled on #{self}"
end

#upgrade_package(name, _cmdline_args = '') ⇒ Object

Upgrade an installed package to the latest available version

Parameters:

  • name (String)

    The name of the package to update

  • cmdline_args (String)

    Additional command line arguments for the package manager



66
67
68
# File 'lib/beaker/host/mac/pkg.rb', line 66

def upgrade_package(name, _cmdline_args = '')
  raise "Package #{name} cannot be upgraded on #{self}"
end