Sha256: 8e90b9a9c52d19e226f1d9912351301f0c609dc91d9ce711b62e412c418e1e72

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

module Sprinkle
  module Installers
    # The user installer helps add users.  You may pass flags as an option.
    # 
    # == Example Usage
    #
    #   package :users do
    #     add_user 'admin', :flags => "--disabled-password"
    #
    #     verify do
    #       has_user 'admin', :in_group = "root"
    #     end
    #   end
    
    class User < Installer
      
      api do
        def add_user(username, options={},  &block)
          install User.new(self, username, options, &block)
        end
      end
      
      verify_api do
        def has_user(user, opts = {})
          if opts[:in_group]
            @commands << "id -nG #{user} | xargs -n1 echo | grep #{opts[:in_group]}"
          else
            @commands << "id #{user}"
          end
        end
      end
      
      def initialize(package, username, options = {}, &block) #:nodoc:
        super package, options, &block
        @username = username
      end
      
      protected 
      
      def install_commands #:nodoc:
        "adduser #{@options[:flags]} #{@username}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sprinkle-0.5.2 lib/sprinkle/installers/user.rb
sprinkle-0.5.1.1 lib/sprinkle/installers/user.rb
sprinkle-0.5.1 lib/sprinkle/installers/user.rb
sprinkle-0.5.0 lib/sprinkle/installers/user.rb