Class: Resource::User

Inherits:
Base
  • Object
show all
Defined in:
lib/resource/user.rb

Instance Method Summary collapse

Methods inherited from Base

inherited, #not_if, #set_base_defaults, #should_skip?, #unix_mode

Methods included from ClassAttr

included

Methods included from BlockAttr

included

Constructor Details

#initialize(username, &block) ⇒ User

Returns a new instance of User.



7
8
9
10
11
12
# File 'lib/resource/user.rb', line 7

def initialize username, &block
  set_base_defaults
  @username = username
  @shell = '/bin/bash'
  self.instance_eval(&block)
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/resource/user.rb', line 14

def run
  Execution.block 'Creating new user', @username, @owner do |b|
    b.always_run @always_run
    users = `cat /etc/passwd | grep "/home" |cut -d: -f1`
    users = users.scan(/[a-zA-Z\-_]+/)
    if users.include? @username
      Output.warn 'Aborted, I think this user already exists', users.inspect
    else
      b.run "useradd -b /home  -u #{@uid} -s #{@shell} -g #{@username} -m -k /home/#{@username} #{@username}"
    end
  end
end