From: Jennie 'Seven' Evers-Corvina Date: Mon, 13 Dec 2010 21:41:02 +0000 (-0800) Subject: I've gotten much farther X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=855df2eadc51a09150128ab3ceea047fa778b382;p=p5sagit%2FIPC-PerlSSH-MultiHop.git I've gotten much farther --- diff --git a/t/scratch.t b/t/scratch.t index d4b4f22..4fa718e 100644 --- a/t/scratch.t +++ b/t/scratch.t @@ -2,6 +2,8 @@ use strictures 1; use Test::More; +use Carp; +use Devel::Dwarn; { package Net::SSH::Perl::ProxiedIPC; @@ -23,11 +25,24 @@ use Test::More; Net::SSH::Perl::WithSocks->new(); } + sub _ssh_env_vars { + $_[0]->{ssh_env_vars} ||= $_[0]->_build_ssh_env_vars; + } + + sub _build_ssh_env_vars { + return {}; + # this needs work I think. First off, it won't work. + # +{ $_[0]->_firsthop_perlssh->eval(; 'chomp(my @env = `ssh-agent`); my %new_env; foreach (@env) { /^(.*?)=(.*)/; $ENV{$1} =$new_env{$1}=$2; } return %new_env;' ); } + } + sub _open_perlssh { my( $self, @hosts ) = @_; my $ssh = $self->_ssh; - my $command = join ' ', (map "ssh -o StrictHostKeyChecking=no -A $_", @hosts), "perl"; - my( $read, $write ) = $ssh->open2($command); + + my %vars = %{ $self->_ssh_env_vars }; + my $env_str = ''; $env_str .= "$_='$vars{$_}' " foreach ( keys %vars ); + my $command = join ' ', $env_str, (map "ssh -o StrictHostKeyChecking=no -A $_", @hosts), "perl"; + my( $read, $write ) = $ssh->open2("sh -c $env_str $command"); my $readfunc = sub { sysread( $read, $_[0], $_[1] ) }; my $writefunc = sub { syswrite( $write, $_[0] ) }; @@ -61,7 +76,9 @@ $perlssh->eval( "use File::HomeDir" ); my $homedir2 = $perlssh->eval( 'File::HomeDir->my_home' ); is( $homedir2, "/home/test", 'got $ENV{HOME} the smart way' ); -my $local_env = $perlssh->eval( 'chomp(my @env = `ssh-agent`); my %new_env; foreach (@env) { /^(.*?)=(.*)/; $ENV{$1} =$new_env{$1}=$2; } return \%new_env;' ); +my $new_env = $perlssh->eval( 'chomp(my @env = `ssh-agent`); my %new_env; foreach (@env) { /^(.*?)=(.*)/; $ENV{$1} =$new_env{$1}=$2; } my $output; $output .= "$_=$new_env{$_}" foreach ( keys %new_env ); $output;' ); +Dwarn %{ $new_env }; +$perlssh->_ssh_env_vars( %{ $new_env } ); my @test_hosts = ( 'stagetwo@localhost', 'stagethree@localhost' ); my ($cmd2, $pssh2) = $pipc->_open_perlssh(@test_hosts);