Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions bin/key2nodes
Original file line number Diff line number Diff line change
Expand Up @@ -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->($_);
Expand Down Expand Up @@ -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";
}
Expand All @@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -236,6 +247,7 @@ OPTIONS:
-c <num> 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> Port for the remote SSH service.
-ssh <path> Specify an alternate ssh program.
(This overrides the SSH_BATCH_SSH_CMD environment.)
Expand Down Expand Up @@ -279,6 +291,7 @@ key2nodes - Push SSH public keys to remote clusters
-c <num> 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> Port for the remote SSH service.
-ssh <path> Specify an alternate ssh program.
(This overrides the SSH_BATCH_SSH_CMD environment.)
Expand Down
22 changes: 21 additions & 1 deletion lib/SSH/Batch/ForNodes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Expand Down