Sha256: 84b3e5aa14b00ecc9df2a6e054a51ed789a4c7569dcbaabe6bd3156c9bb37445

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 KB

Contents

# == 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.
class ::AutomateIt::AccountManager::PasswdExpect < ::AutomateIt::AccountManager::BaseDriver
  depends_on :programs => %w(passwd expect)

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

  # See AccountManager#passwd
  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
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
automate-it-0.9.2 lib/automateit/account_manager/passwd_expect.rb
automate-it-0.9.1 lib/automateit/account_manager/passwd_expect.rb
automate-it-0.9.0 lib/automateit/account_manager/passwd_expect.rb
automateit-0.71219 lib/automateit/account_manager/passwd_expect.rb
automateit-0.71220 lib/automateit/account_manager/passwd_expect.rb
automateit-0.71221 lib/automateit/account_manager/passwd_expect.rb
automateit-0.71226.1 lib/automateit/account_manager/passwd_expect.rb
automateit-0.80116 lib/automateit/account_manager/passwd_expect.rb
automateit-0.80624 lib/automateit/account_manager/passwd_expect.rb
automateit-0.71230 lib/automateit/account_manager/passwd_expect.rb
automateit-0.71226 lib/automateit/account_manager/passwd_expect.rb