Class: AutomateIt::AccountManager::PasswdExpect

Inherits:
BaseDriver 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.

Constant Summary

Constants inherited from Plugin::Driver

Plugin::Driver::BASE_DRIVER_NAME

Constants included from Constants

Constants::HELPERS_DIR, Constants::INSTALL_DIR, Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE

Instance Attribute Summary

Attributes inherited from Plugin::Driver

#manager

Attributes inherited from Common

#interpreter

Instance Method Summary collapse

Methods inherited from Plugin::Driver

abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token, #setup

Methods inherited from Plugin::Base

#setup, #token, token

Methods inherited from Common

#initialize, #log, #nitpick, #noop, #noop=, #noop?, #preview, #preview=, #preview?, #preview_for, #setup, #superuser?, #writing, #writing=, #writing?

Constructor Details

This class inherits a constructor from AutomateIt::Common

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}"
        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