don't use hardcoded paths

This commit is contained in:
Christoph Klaffl 2018-09-12 10:00:09 +02:00
parent 22160deb8e
commit 9b2c2f29dc
No known key found for this signature in database
GPG Key ID: FC1C525C2A47CC28
1 changed files with 18 additions and 15 deletions

33
syncoid
View File

@ -48,17 +48,20 @@ my $debug = $args{'debug'};
my $quiet = $args{'quiet'};
my $resume = !$args{'no-resume'};
my $zfscmd = '/sbin/zfs';
my $sshcmd = '/usr/bin/ssh';
my $pscmd = '/bin/ps';
# for compatibility reasons, older versions used hardcoded command paths
$ENV{'PATH'} = $ENV{'PATH'} . ":/bin:/usr/bin:/sbin";
my $pvcmd = '/usr/bin/pv';
my $mbuffercmd = '/usr/bin/mbuffer';
my $sudocmd = '/usr/bin/sudo';
my $zfscmd = 'zfs';
my $sshcmd = 'ssh';
my $pscmd = 'ps';
my $pvcmd = 'pv';
my $mbuffercmd = 'mbuffer';
my $sudocmd = 'sudo';
my $mbufferoptions = '-q -s 128k -m 16M 2>/dev/null';
# currently using ls to check for file existence because we aren't depending on perl
# currently using which to check for command existence because we aren't depending on perl
# being present on remote machines.
my $lscmd = '/bin/ls';
my $whichcmd = 'which';
if (length $args{'sshcipher'}) {
$args{'sshcipher'} = "-c $args{'sshcipher'}";
@ -564,11 +567,11 @@ sub checkcommands {
if ($debug) { print "DEBUG: compression forced off from command line arguments.\n"; }
} else {
if ($debug) { print "DEBUG: checking availability of $compressargs{'rawcmd'} on source...\n"; }
$avail{'sourcecompress'} = `$sourcessh $lscmd $compressargs{'rawcmd'} 2>/dev/null`;
$avail{'sourcecompress'} = `$sourcessh $whichcmd $compressargs{'rawcmd'} 2>/dev/null`;
if ($debug) { print "DEBUG: checking availability of $compressargs{'rawcmd'} on target...\n"; }
$avail{'targetcompress'} = `$targetssh $lscmd $compressargs{'rawcmd'} 2>/dev/null`;
$avail{'targetcompress'} = `$targetssh $whichcmd $compressargs{'rawcmd'} 2>/dev/null`;
if ($debug) { print "DEBUG: checking availability of $compressargs{'rawcmd'} on local machine...\n"; }
$avail{'localcompress'} = `$lscmd $compressargs{'rawcmd'} 2>/dev/null`;
$avail{'localcompress'} = `$whichcmd $compressargs{'rawcmd'} 2>/dev/null`;
}
my ($s,$t);
@ -620,7 +623,7 @@ sub checkcommands {
}
if ($debug) { print "DEBUG: checking availability of $mbuffercmd on source...\n"; }
$avail{'sourcembuffer'} = `$sourcessh $lscmd $mbuffercmd 2>/dev/null`;
$avail{'sourcembuffer'} = `$sourcessh $whichcmd $mbuffercmd 2>/dev/null`;
if ($avail{'sourcembuffer'} eq '') {
if (!$quiet) { print "WARN: $mbuffercmd not available on source $s - sync will continue without source buffering.\n"; }
$avail{'sourcembuffer'} = 0;
@ -629,7 +632,7 @@ sub checkcommands {
}
if ($debug) { print "DEBUG: checking availability of $mbuffercmd on target...\n"; }
$avail{'targetmbuffer'} = `$targetssh $lscmd $mbuffercmd 2>/dev/null`;
$avail{'targetmbuffer'} = `$targetssh $whichcmd $mbuffercmd 2>/dev/null`;
if ($avail{'targetmbuffer'} eq '') {
if (!$quiet) { print "WARN: $mbuffercmd not available on target $t - sync will continue without target buffering.\n"; }
$avail{'targetmbuffer'} = 0;
@ -640,7 +643,7 @@ sub checkcommands {
# if we're doing remote source AND remote target, check for local mbuffer as well
if ($sourcehost ne '' && $targethost ne '') {
if ($debug) { print "DEBUG: checking availability of $mbuffercmd on local machine...\n"; }
$avail{'localmbuffer'} = `$lscmd $mbuffercmd 2>/dev/null`;
$avail{'localmbuffer'} = `$whichcmd $mbuffercmd 2>/dev/null`;
if ($avail{'localmbuffer'} eq '') {
$avail{'localmbuffer'} = 0;
if (!$quiet) { print "WARN: $mbuffercmd not available on local machine - sync will continue without local buffering.\n"; }
@ -648,7 +651,7 @@ sub checkcommands {
}
if ($debug) { print "DEBUG: checking availability of $pvcmd on local machine...\n"; }
$avail{'localpv'} = `$lscmd $pvcmd 2>/dev/null`;
$avail{'localpv'} = `$whichcmd $pvcmd 2>/dev/null`;
if ($avail{'localpv'} eq '') {
if (!$quiet) { print "WARN: $pvcmd not available on local machine - sync will continue without progress bar.\n"; }
$avail{'localpv'} = 0;