Sha256: 7fc292820c3930ec64bd849ee5437087e402f75e5665e5ce686375772ced7614

Contents?: true

Size: 930 Bytes

Versions: 154

Compression:

Stored size: 930 Bytes

Contents

module Unix::Group
  include Beaker::CommandFactory

  def group_list(&block)
    execute("getent group") do |result|
      groups = []
      result.stdout.each_line do |line|
        groups << (line.match(/^([^:]+)/) or next)[1]
      end

      yield result if block_given?

      groups
    end
  end

  def group_get(name, &block)
    execute("getent group #{name}") do |result|
      fail_test "failed to get group #{name}" unless result.stdout =~ /^#{name}:.*:[0-9]+:/

      yield result if block_given?
    end
  end

  def group_gid(name)
    execute("getent group #{name}") do |result|
      # Format is:
      # wheel:x:10:root
      result.stdout.split(':')[2]
    end
  end

  def group_present(name, &block)
    execute("if ! getent group #{name}; then groupadd #{name}; fi", {}, &block)
  end

  def group_absent(name, &block)
    execute("if getent group #{name}; then groupdel #{name}; fi", {}, &block)
  end
end

Version data entries

154 entries across 154 versions & 1 rubygems

Version Path
beaker-3.18.0 lib/beaker/host/unix/group.rb
beaker-3.17.0 lib/beaker/host/unix/group.rb
beaker-3.16.0 lib/beaker/host/unix/group.rb
beaker-3.15.0 lib/beaker/host/unix/group.rb
beaker-3.14.0 lib/beaker/host/unix/group.rb
beaker-3.13.0 lib/beaker/host/unix/group.rb
beaker-3.12.0 lib/beaker/host/unix/group.rb
beaker-3.11.0 lib/beaker/host/unix/group.rb
beaker-3.10.0 lib/beaker/host/unix/group.rb
beaker-3.9.0 lib/beaker/host/unix/group.rb
beaker-3.8.0 lib/beaker/host/unix/group.rb
beaker-3.7.0 lib/beaker/host/unix/group.rb
beaker-3.6.0 lib/beaker/host/unix/group.rb
beaker-2.52.0 lib/beaker/host/unix/group.rb
beaker-3.5.0 lib/beaker/host/unix/group.rb
beaker-3.4.0 lib/beaker/host/unix/group.rb
beaker-3.3.0 lib/beaker/host/unix/group.rb
beaker-3.2.0 lib/beaker/host/unix/group.rb
beaker-3.1.0 lib/beaker/host/unix/group.rb
beaker-3.0.0 lib/beaker/host/unix/group.rb