lib/puppet/provider/tpm_ownership/trousers.rb
def tpm_takeownership(expect_array, cmd = 'tpm_takeownership' )
    require 'expect'
    require 'pty'

    pty_timeout = 15

    PTY.spawn( cmd ) do |r,w,pid|
      w.sync = true

      expect_array.each do |reg,stdin|
        begin
          r.expect( reg, pty_timeout) do |s|
            w.puts stdin
            debug( [reg, stdin, s] )
          end
        rescue Errno::EIO
        end
      end

      Process.wait(pid) # set $? to the correct exit code
    end
    exit_code = $?
    debug( ['exit code', exit_code] )

    exit_code.exitstatus == 0 ? true : false
  end
# Interact with a tpm_takeownership using stdin
#
# @param command [String] The command to interact with
# @param stdin [Array<Regex, String>] List of pairs [regex, string] to print as stdin
# @return [Boolean] <= 0 is true, anything else is false
Interact with a tpm_takeownership using stdin
Interact with a tpm_takeownership using stdin
def tpm_takeownership(expect_array, cmd = 'tpm_takeownership' )
    require 'expect'
    require 'pty'
    pty_timeout = 15
    PTY.spawn( cmd ) do |r,w,pid|
      w.sync = true
      expect_array.each do |reg,stdin|
        begin
          r.expect( reg, pty_timeout) do |s|
            w.puts stdin
            debug( [reg, stdin, s] )
          end
        rescue Errno::EIO
        end
      end
      Process.wait(pid) 
    end
    exit_code = $?
    debug( ['exit code', exit_code] )
    exit_code.exitstatus == 0 ? true : false
  end
def tpm_takeownership ( expect_array , cmd = 'tpm_takeownership' ) require 'expect' require 'pty' pty_timeout = 15 PTY . spawn ( cmd ) do | r , w , pid | w . sync = true expect_array . each do | reg , stdin | begin r . expect ( reg , pty_timeout ) do | s | w . puts stdin debug ( [ reg , stdin , s ] ) end rescue Errno :: EIO end end Process . wait ( pid ) end exit_code = $? debug ( [ 'exit code' , exit_code ] ) exit_code . exitstatus == 0 ? true : false end
Interact with a tpm_takeownership using stdin
Interact with a tpm_takeownership using stdin
# set $? to the correct exit code
<= 0 is true, anything else is false
< = 0 is true anything else is false
Boolean
expect_array
cmd
command
The command to interact with
The command to interact with
stdin
List of pairs [regex, string] to print as stdin
List of pairs [ regex string ] to print as stdin