Sha256: 0f1a0adf6bdc5037019aaf679349b345c38e2247c60798b18ee9aae0dc9f4c1d

Contents?: true

Size: 934 Bytes

Versions: 8

Compression:

Stored size: 934 Bytes

Contents

module Unix::Group
  include Beaker::CommandFactory

  def group_list()
    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)
    execute("getent group #{name}") do |result|
      fail_test "failed to get group #{name}" unless /^#{name}:.*:[0-9]+:/.match?(result.stdout)

      yield result if block_given?
      result
    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

8 entries across 8 versions & 1 rubygems

Version Path
beaker-4.42.0 lib/beaker/host/unix/group.rb
beaker-4.41.2 lib/beaker/host/unix/group.rb
beaker-4.41.1 lib/beaker/host/unix/group.rb
beaker-4.41.0 lib/beaker/host/unix/group.rb
beaker-4.40.2 lib/beaker/host/unix/group.rb
beaker-4.40.1 lib/beaker/host/unix/group.rb
beaker-4.40.0 lib/beaker/host/unix/group.rb
beaker-4.39.0 lib/beaker/host/unix/group.rb