Class: AutomateIt::AccountManager::PasswdExpect

Inherits:
BaseDriver
  • Object
show all
Defined in:
lib/automateit/account_manager/passwd_expect.rb

Overview

AccountManager::PasswdExpect

An AccountManager driver for the passwd command found on Unix-like systems using the expect program as a wrapper because the Ruby PTY implementation is unreliable.

Instance Method Summary collapse

Instance Method Details

#passwd(user, password, opts = {}) ⇒ Object

See AccountManager#passwd



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/automateit/account_manager/passwd_expect.rb', line 15

def passwd(user, password, opts={})
  _passwd_helper(user, password, opts) do |user, password, opts|
    log.silence(Logger::WARN) do
      interpreter.mktemp do |filename|
        # Script derived from /usr/share/doc/expect/examples/autopasswd
        interpreter.render(:text => <<-HERE, :to => filename)
set password "#{password}"
spawn passwd "#{user}"
expect "assword:"
sleep 0.1
send "$password\\r"
expect "assword:"
sleep 0.1
send "$password\\r"
expect eof
        HERE

        cmd = "expect #{filename} #{user} #{password}"
        cmd << " > /dev/null" if opts[:quiet]
        return(interpreter.sh cmd)
      end
    end
  end
end

#suitability(method, *args) ⇒ Object

:nodoc:



9
10
11
12
# File 'lib/automateit/account_manager/passwd_expect.rb', line 9

def suitability(method, *args) # :nodoc:
  # Level must be higher than PasswdPTY
  return available? ? 9 : 0
end