diff --git a/bin/key2nodes b/bin/key2nodes index 0e6085a..3c4f953 100755 --- a/bin/key2nodes +++ b/bin/key2nodes @@ -23,6 +23,7 @@ my (@exprs); my $concurrency = 20; my $fetch_value; my $ssh_cmd = $ENV{SSH_BATCH_SSH_CMD}; +my $pubkey_file = ""; for (@ARGV) { if (defined $fetch_value) { $fetch_value->($_); @@ -50,6 +51,8 @@ for (@ARGV) { $fetch_value = sub { $ssh_cmd = shift }; } elsif ($group eq 'c') { $fetch_value = sub { $concurrency = shift }; + } elsif ($group eq 'k') { + $fetch_value = sub { $pubkey_file = shift }; } else { die "Unknown option: $_\n"; } @@ -72,12 +75,17 @@ if (!defined $home) { die "Can't find the home for the current user.\n"; } -my $pubkey_file = "$home/.ssh/id_rsa.pub"; +my $genkey = 0; +if ($pubkey_file eq ""){ + $pubkey_file = "$home/.ssh/id_rsa.pub"; + $genkey = 1; +} + if (-f $pubkey_file) { if ($verbose) { warn "Found public key file $pubkey_file.\n"; } -} else { +} elsif ($genkey == 1){ my $cmd = "(echo; echo y; echo; echo) | ssh-keygen -q -t rsa"; if ($verbose) { warn "Running command [$cmd]...\n"; @@ -86,6 +94,9 @@ if (-f $pubkey_file) { die "Generating SSH key failed.\n"; } } +else{ + die "Public key file $pubkey_file not found."; +} open my $in, $pubkey_file or die "Can't open $pubkey_file for reading: $!\n"; @@ -236,6 +247,7 @@ OPTIONS: -c Set SSH concurrency limit. (default: 20) -h Print this help. -l List the hosts and do nothing else. + -k SSH Public Key to upload. -p Port for the remote SSH service. -ssh Specify an alternate ssh program. (This overrides the SSH_BATCH_SSH_CMD environment.) @@ -279,6 +291,7 @@ key2nodes - Push SSH public keys to remote clusters -c Set SSH concurrency limit. (default: 20) -h Print this help. -l List the hosts and do nothing else. + -k SSH Public Key to upload. -p Port for the remote SSH service. -ssh Specify an alternate ssh program. (This overrides the SSH_BATCH_SSH_CMD environment.) diff --git a/lib/SSH/Batch/ForNodes.pm b/lib/SSH/Batch/ForNodes.pm index fe69a85..2a950f8 100644 --- a/lib/SSH/Batch/ForNodes.pm +++ b/lib/SSH/Batch/ForNodes.pm @@ -94,7 +94,27 @@ sub parse_line ($$) { } $Vars{$var} = $set; } - } else { + } + elsif(/^\s*include\s*:\s*"?([^"]*)"?\s*$/i){ + my $includefile = $1; + if($includefile =~ /^~\/(.*)$/){ + $includefile = ($ENV{SSH_BATCH_HOME} || File::HomeDir->my_home) . '/' . $1; + } + + if(! -e $includefile){ + die "Include file $includefile does not exist!\n"; + } + open my $rcsub, $includefile or + die "Can't open $includefile for reading: $!\n"; + + load_rc($rcsub, $includefile); + + close $rcsub; + + return; + + } + else { die "Syntax error in $rcfile, line $.: $_\n"; } }