From 9b2c2f29dc126c8629d2d2612331b07b2e71c30d Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Wed, 12 Sep 2018 10:00:09 +0200 Subject: [PATCH 1/4] don't use hardcoded paths --- syncoid | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/syncoid b/syncoid index 30aef49..257e652 100755 --- a/syncoid +++ b/syncoid @@ -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; From be50481374be1265ddbaee0decd65a6b39634366 Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Fri, 7 Dec 2018 17:03:49 +0100 Subject: [PATCH 2/4] use more portable/POSIX compatible ways to check for command existence --- syncoid | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/syncoid b/syncoid index e618eb8..cb57c28 100755 --- a/syncoid +++ b/syncoid @@ -62,7 +62,7 @@ my $sudocmd = 'sudo'; my $mbufferoptions = '-q -s 128k -m 16M 2>/dev/null'; # currently using which to check for command existence because we aren't depending on perl # being present on remote machines. -my $whichcmd = 'which'; +my $checkcmd = 'command -v'; if (length $args{'sshcipher'}) { $args{'sshcipher'} = "-c $args{'sshcipher'}"; @@ -769,11 +769,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 $whichcmd $compressargs{'rawcmd'} 2>/dev/null`; + $avail{'sourcecompress'} = `$sourcessh $checkcmd $compressargs{'rawcmd'} 2>/dev/null`; if ($debug) { print "DEBUG: checking availability of $compressargs{'rawcmd'} on target...\n"; } - $avail{'targetcompress'} = `$targetssh $whichcmd $compressargs{'rawcmd'} 2>/dev/null`; + $avail{'targetcompress'} = `$targetssh $checkcmd $compressargs{'rawcmd'} 2>/dev/null`; if ($debug) { print "DEBUG: checking availability of $compressargs{'rawcmd'} on local machine...\n"; } - $avail{'localcompress'} = `$whichcmd $compressargs{'rawcmd'} 2>/dev/null`; + $avail{'localcompress'} = `$checkcmd $compressargs{'rawcmd'} 2>/dev/null`; } my ($s,$t); @@ -825,7 +825,7 @@ sub checkcommands { } if ($debug) { print "DEBUG: checking availability of $mbuffercmd on source...\n"; } - $avail{'sourcembuffer'} = `$sourcessh $whichcmd $mbuffercmd 2>/dev/null`; + $avail{'sourcembuffer'} = `$sourcessh $checkcmd $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; @@ -834,7 +834,7 @@ sub checkcommands { } if ($debug) { print "DEBUG: checking availability of $mbuffercmd on target...\n"; } - $avail{'targetmbuffer'} = `$targetssh $whichcmd $mbuffercmd 2>/dev/null`; + $avail{'targetmbuffer'} = `$targetssh $checkcmd $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; @@ -845,7 +845,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'} = `$whichcmd $mbuffercmd 2>/dev/null`; + $avail{'localmbuffer'} = `$checkcmd $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"; } @@ -853,7 +853,7 @@ sub checkcommands { } if ($debug) { print "DEBUG: checking availability of $pvcmd on local machine...\n"; } - $avail{'localpv'} = `$whichcmd $pvcmd 2>/dev/null`; + $avail{'localpv'} = `$checkcmd $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; From 941a770c12ab318ebc366dd24b7a6cd5a504d15a Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Fri, 7 Dec 2018 17:05:53 +0100 Subject: [PATCH 3/4] updated comment regarding command existence check --- syncoid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncoid b/syncoid index cb57c28..9530b00 100755 --- a/syncoid +++ b/syncoid @@ -60,7 +60,7 @@ my $pvcmd = 'pv'; my $mbuffercmd = 'mbuffer'; my $sudocmd = 'sudo'; my $mbufferoptions = '-q -s 128k -m 16M 2>/dev/null'; -# currently using which to check for command existence because we aren't depending on perl +# currently using POSIX compatible command to check for program existence because we aren't depending on perl # being present on remote machines. my $checkcmd = 'command -v'; From 89f1d4e9a69fe088f391034e72e2c55120986783 Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Sat, 8 Dec 2018 14:13:54 +0100 Subject: [PATCH 4/4] run compress commands bare too --- syncoid | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/syncoid b/syncoid index 9530b00..495f712 100755 --- a/syncoid +++ b/syncoid @@ -673,51 +673,51 @@ sub compressargset { decomargs => '', }, 'gzip' => { - rawcmd => '/bin/gzip', + rawcmd => 'gzip', args => '-3', - decomrawcmd => '/bin/zcat', + decomrawcmd => 'zcat', decomargs => '', }, 'pigz-fast' => { - rawcmd => '/usr/bin/pigz', + rawcmd => 'pigz', args => '-3', - decomrawcmd => '/usr/bin/pigz', + decomrawcmd => 'pigz', decomargs => '-dc', }, 'pigz-slow' => { - rawcmd => '/usr/bin/pigz', + rawcmd => 'pigz', args => '-9', - decomrawcmd => '/usr/bin/pigz', + decomrawcmd => 'pigz', decomargs => '-dc', }, 'zstd-fast' => { - rawcmd => '/usr/bin/zstd', + rawcmd => 'zstd', args => '-3', - decomrawcmd => '/usr/bin/zstd', + decomrawcmd => 'zstd', decomargs => '-dc', }, 'zstd-slow' => { - rawcmd => '/usr/bin/zstd', + rawcmd => 'zstd', args => '-19', - decomrawcmd => '/usr/bin/zstd', + decomrawcmd => 'zstd', decomargs => '-dc', }, 'xz' => { - rawcmd => '/usr/bin/xz', + rawcmd => 'xz', args => '', - decomrawcmd => '/usr/bin/xz', + decomrawcmd => 'xz', decomargs => '-d', }, 'lzo' => { - rawcmd => '/usr/bin/lzop', + rawcmd => 'lzop', args => '', - decomrawcmd => '/usr/bin/lzop', + decomrawcmd => 'lzop', decomargs => '-dfc', }, 'lz4' => { - rawcmd => '/usr/bin/lz4', + rawcmd => 'lz4', args => '', - decomrawcmd => '/usr/bin/lz4', + decomrawcmd => 'lz4', decomargs => '-dc', }, );