Sha256: a0f5a8ec23f3e2e066decba216981d4410b263b43f7d8fb0abb01e29f59a37a8

Contents?: true

Size: 1.68 KB

Versions: 14

Compression:

Stored size: 1.68 KB

Contents

module Windows::Pkg
  include Beaker::CommandFactory

  def check_for_command(name)
    result = exec(Beaker::Command.new("which #{name}"), :acceptable_exit_codes => (0...127))
    result.exit_code == 0
  end

  def check_for_package(name)
    result = exec(Beaker::Command.new("cygcheck #{name}"), :acceptable_exit_codes => (0...127))
    result.exit_code == 0
  end

  def install_package(name, cmdline_args = '')
    cygwin = ""
    rootdir = ""

    arch = identify_windows_architecture

    if arch == '64'
      rootdir = "c:\\\\cygwin64"
      cygwin = "setup-x86_64.exe"
    else #32 bit version
      rootdir = "c:\\\\cygwin"
      cygwin = "setup-x86.exe"
    end

    if not check_for_command(cygwin)
      execute("curl --retry 5 http://cygwin.com/#{cygwin} -o /cygdrive/c/Windows/System32/#{cygwin}")
    end
    execute("#{cygwin} -q -n -N -d -R #{cmdline_args} #{rootdir} -s http://cygwin.osuosl.org -P #{name}")
  end

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

  private

  # @api private
  def identify_windows_architecture
    arch = nil
    execute("echo '' | wmic os get osarchitecture",
            :acceptable_exit_codes => (0...127)) do |result|

      arch = if result.exit_code == 0
        result.stdout =~ /64/ ? '64' : '32'
      else
        identify_windows_architecture_from_os_name_for_win2003
      end
    end
    arch
  end

  # @api private
  def identify_windows_architecture_from_os_name_for_win2003
    arch = nil
    execute("echo '' | wmic os get name | grep x64",
            :acceptable_exit_codes => (0...127)) do |result|
      arch = result.exit_code == 0 ? '64' : '32'
    end
    arch
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
beaker-1.17.7 lib/beaker/host/windows/pkg.rb
beaker-1.17.6 lib/beaker/host/windows/pkg.rb
beaker-1.17.5 lib/beaker/host/windows/pkg.rb
beaker-1.17.4 lib/beaker/host/windows/pkg.rb
beaker-1.17.3 lib/beaker/host/windows/pkg.rb
beaker-1.17.2 lib/beaker/host/windows/pkg.rb
beaker-1.17.1 lib/beaker/host/windows/pkg.rb
beaker-1.17.0 lib/beaker/host/windows/pkg.rb
beaker-1.16.0 lib/beaker/host/windows/pkg.rb
beaker-1.15.0 lib/beaker/host/windows/pkg.rb
beaker-1.14.1 lib/beaker/host/windows/pkg.rb
beaker-1.14.0 lib/beaker/host/windows/pkg.rb
beaker-1.13.1 lib/beaker/host/windows/pkg.rb
beaker-1.13.0 lib/beaker/host/windows/pkg.rb