mirror of
https://github.com/duncs/clusterssh.git
synced 2025-07-03 01:43:25 +00:00
Move .csshrc to .csshrc.DISABLED
Move the old config file to one side since it should no longer be used and the error was more annoying than useful Also catch perltidy from previous commit
This commit is contained in:
parent
7755a60161
commit
a7296983e6
3 changed files with 76 additions and 46 deletions
|
@ -10,6 +10,7 @@ use Carp;
|
|||
use Try::Tiny;
|
||||
|
||||
use FindBin qw($Script);
|
||||
use File::Copy;
|
||||
|
||||
use base qw/ App::ClusterSSH::Base /;
|
||||
use App::ClusterSSH::Cluster;
|
||||
|
@ -130,23 +131,22 @@ sub validate_args {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (@unknown_config) {
|
||||
croak(
|
||||
App::ClusterSSH::Exception::Config->throw(
|
||||
unknown_config => \@unknown_config,
|
||||
error => $self->loc(
|
||||
'Unknown configuration parameters: [_1]'.$/,
|
||||
'Unknown configuration parameters: [_1]' . $/,
|
||||
join( ',', @unknown_config )
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! $self->{comms} ) {
|
||||
if ( !$self->{comms} ) {
|
||||
croak(
|
||||
App::ClusterSSH::Exception::Config->throw(
|
||||
error => $self->loc( 'Invalid variable: comms'.$/),
|
||||
error => $self->loc( 'Invalid variable: comms' . $/ ),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -154,17 +154,20 @@ sub validate_args {
|
|||
if ( !$self->{ $self->{comms} } ) {
|
||||
croak(
|
||||
App::ClusterSSH::Exception::Config->throw(
|
||||
error => $self->loc( 'Invalid variable: [_1]'.$/, $self->{comms}),
|
||||
error => $self->loc(
|
||||
'Invalid variable: [_1]' . $/,
|
||||
$self->{comms}
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
# # Don't search for the path to the binary - assume it is on the path
|
||||
# # or defined correctly in the config.
|
||||
# if( !-e $self->{ $self->{comms} } )
|
||||
# {
|
||||
# $self->{ $self->{comms} } = $self->find_binary( $self->{comms} );
|
||||
# }
|
||||
|
||||
# # Don't search for the path to the binary - assume it is on the path
|
||||
# # or defined correctly in the config.
|
||||
# if( !-e $self->{ $self->{comms} } )
|
||||
# {
|
||||
# $self->{ $self->{comms} } = $self->find_binary( $self->{comms} );
|
||||
# }
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
@ -178,7 +181,8 @@ sub parse_config_file {
|
|||
croak(
|
||||
App::ClusterSSH::Exception::Config->throw(
|
||||
error => $self->loc(
|
||||
'File [_1] does not exist or cannot be read'.$/, $config_file
|
||||
'File [_1] does not exist or cannot be read' . $/,
|
||||
$config_file
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -233,16 +237,6 @@ sub parse_config_file {
|
|||
sub load_configs {
|
||||
my ( $self, @configs ) = @_;
|
||||
|
||||
if ( -e $ENV{HOME} . '/.csshrc' ) {
|
||||
warn(
|
||||
$self->loc(
|
||||
'NOTICE: [_1] is no longer used - please see documentation and remove',
|
||||
$ENV{HOME} . '/.csshrc'
|
||||
),
|
||||
$/
|
||||
);
|
||||
}
|
||||
|
||||
for my $config (
|
||||
'/etc/csshrc',
|
||||
$ENV{HOME} . '/.csshrc',
|
||||
|
@ -276,6 +270,30 @@ sub load_configs {
|
|||
sub write_user_config_file {
|
||||
my ($self) = @_;
|
||||
|
||||
# attempt to move the old config file to one side
|
||||
if ( -f "$ENV{HOME}/.csshrc" ) {
|
||||
eval { move( "$ENV{HOME}/.csshrc", "$ENV{HOME}/.csshrc.DISABLED" ) };
|
||||
|
||||
if ($@) {
|
||||
croak(
|
||||
App::ClusterSSH::Exception::Config->throw(
|
||||
error => $self->loc(
|
||||
'Unable to move [_1] to [_2]: [_3]' . $/,
|
||||
'$HOME/.csshrc', '$HOME/.csshrc.DISABLED', $@
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
warn(
|
||||
$self->loc(
|
||||
'Moved [_1] to [_2]' . $/, '$HOME/.csshrc',
|
||||
'$HOME/.csshrc.DISABLED'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return if ( -f "$ENV{HOME}/.clusterssh/config" );
|
||||
|
||||
if ( !-d "$ENV{HOME}/.clusterssh" ) {
|
||||
|
@ -283,7 +301,7 @@ sub write_user_config_file {
|
|||
croak(
|
||||
App::ClusterSSH::Exception::Config->throw(
|
||||
error => $self->loc(
|
||||
'Unable to create directory [_1]: [_2]'.$/,
|
||||
'Unable to create directory [_1]: [_2]' . $/,
|
||||
'$HOME/.clusterssh', $!
|
||||
),
|
||||
),
|
||||
|
@ -297,29 +315,36 @@ sub write_user_config_file {
|
|||
print CONFIG "$_=$self->{$_}\n";
|
||||
}
|
||||
close(CONFIG);
|
||||
warn(
|
||||
$self->loc(
|
||||
'Created new configuration file within [_1]' . $/,
|
||||
'$HOME/.clusterssh/'
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
croak(
|
||||
App::ClusterSSH::Exception::Config->throw(
|
||||
error => $self->loc(
|
||||
'Unable to write default [_1]: [_2]'.$/,
|
||||
'$HOME/.clusterssh/config',
|
||||
$!
|
||||
'Unable to write default [_1]: [_2]' . $/,
|
||||
'$HOME/.clusterssh/config', $!
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return $self if ( !%old_clusters );
|
||||
|
||||
if ( open( my $fh, ">", "$ENV{HOME}/.clusterssh/clusters" ) ) {
|
||||
print $fh '# '
|
||||
. $self->loc('Tag definitions moved from old .csshrc file'), $/;
|
||||
foreach ( sort( keys(%old_clusters) ) ) {
|
||||
print $fh $_, ' ', join( ' ', $old_clusters{$_} ), $/;
|
||||
if (%old_clusters) {
|
||||
if ( open( my $fh, ">", "$ENV{HOME}/.clusterssh/clusters" ) ) {
|
||||
print $fh '# '
|
||||
. $self->loc('Tag definitions moved from old .csshrc file'),
|
||||
$/;
|
||||
foreach ( sort( keys(%old_clusters) ) ) {
|
||||
print $fh $_, ' ', join( ' ', $old_clusters{$_} ), $/;
|
||||
}
|
||||
close($fh);
|
||||
}
|
||||
close($fh);
|
||||
}
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -331,7 +356,7 @@ sub find_binary {
|
|||
if ( !$binary ) {
|
||||
croak(
|
||||
App::ClusterSSH::Exception::Config->throw(
|
||||
error => $self->loc('argument not provided').$/,
|
||||
error => $self->loc('argument not provided') . $/,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -383,7 +408,8 @@ sub find_binary {
|
|||
croak(
|
||||
App::ClusterSSH::Exception::Config->throw(
|
||||
error => $self->loc(
|
||||
'"[_1]" binary not found - please amend $PATH or the cssh config file'.$/,
|
||||
'"[_1]" binary not found - please amend $PATH or the cssh config file'
|
||||
. $/,
|
||||
$binary
|
||||
),
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue