From 370345b6e902af325bc92692aaa7cb2f0da100ee Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 27 Jan 2023 12:58:56 +0100 Subject: [PATCH] wip #5700 @0.5 --- src/CommandLine/CloneProgram.php | 107 +++++++++++++++++++ src/CommandLine/CloneUserpassProgram.php | 124 +++++++++++++++++++++++ src/CommandLine/LFTP.php | 60 +++++++++++ src/CommandLine/Rclone.php | 103 ++----------------- src/CommandLine/Rsync.php | 81 +-------------- 5 files changed, 302 insertions(+), 173 deletions(-) create mode 100644 src/CommandLine/CloneProgram.php create mode 100644 src/CommandLine/CloneUserpassProgram.php create mode 100644 src/CommandLine/LFTP.php diff --git a/src/CommandLine/CloneProgram.php b/src/CommandLine/CloneProgram.php new file mode 100644 index 0000000..60cb1ab --- /dev/null +++ b/src/CommandLine/CloneProgram.php @@ -0,0 +1,107 @@ +_prog, $output, $error); + } + + + /** + * @return string + */ + public function getProg() + { + return $this->_prog; + } + + /** + * @param bool $dryRun + */ + public function setDryRun(bool $dryRun): void + { + $this->_dryRun = $dryRun; + } + + /** + * @return bool + */ + public function isDryRun(): bool + { + return $this->_dryRun; + } + + + public function getSrc() + { + return $this->_src; + } + + public function getDest() + { + return $this->_dest; + } + + public function getMirror() + { + return $this->_mirror; + } + + public function setSrc($src) + { + $this->_src = $src; + return $this; + } + + public function setDest($dest) + { + $this->_dest = $dest; + return $this; + } + + public function setMirror($mirror) + { + $this->_mirror = $mirror; + return $this; + } + + public function setCloneArg($name, $value = null) + { + $this->_cloneArgs[] = [$name, $value]; + } +} \ No newline at end of file diff --git a/src/CommandLine/CloneUserpassProgram.php b/src/CommandLine/CloneUserpassProgram.php new file mode 100644 index 0000000..167b10b --- /dev/null +++ b/src/CommandLine/CloneUserpassProgram.php @@ -0,0 +1,124 @@ +_username; + } + + /** + * @param string $username + */ + public function setUsername(string $username): void + { + $this->_username = $username; + } + + /** + * @return string + */ + public function getPassword(): string + { + return $this->_password; + } + + /** + * @param string $password + */ + public function setPassword(string $password): void + { + $this->_password = $password; + } + + /** + * @return int + */ + public function getPort(): int + { + return $this->_port; + } + + /** + * @param int $port + */ + public function setPort(int $port): void + { + $this->_port = $port; + } + + /** + * @param string $protocol + */ + public function setProtocol(string $protocol): void + { + $this->_protocol = $protocol; + } + + /** + * @return string + */ + public function getProtocol(): string + { + return $this->_protocol; + } + + /** + * @return string + */ + public function getHost(): string + { + return $this->_host; + } + + /** + * @param string $host + */ + public function setHost(string $host): void + { + $this->_host = $host; + } + + public function setServer(IServer $server) + { + $this->setProtocol($server->getProtocol()); + $this->setHost($server->getHost()); + $this->setPort($server->getPort()); + $this->setUsername($server->getUsername()); + $this->setPassword($server->getPassword()); + } +} \ No newline at end of file diff --git a/src/CommandLine/LFTP.php b/src/CommandLine/LFTP.php new file mode 100644 index 0000000..a1be0ee --- /dev/null +++ b/src/CommandLine/LFTP.php @@ -0,0 +1,60 @@ +isPassiveMode()?'1':'0'), + 'mkdir -p ' . $this->getDest(), + 'cd ' . $this->getDest(), + 'lcd ' .$this->getSrc(), + 'mirror -Rve --parallel=5' + ]; + + //$lftp->setManualArg( . '> mirror -Rv ' . $package); + + + $this->setArg('u', $this->getUsername() . ',' . $this->getPassword()); + $this->setArg('p', $this->getPort()); + $this->setArg('e', implode(';', $commandes)); + $this->setArg(null, $u['host']); + } + + /** + * @return bool + */ + public function isPassiveMode(): bool + { + return $this->_passiveMode; + } + + /** + * @param bool $passiveMode + */ + public function setPassiveMode(bool $passiveMode): void + { + $this->_passiveMode = $passiveMode; + } + +} \ No newline at end of file diff --git a/src/CommandLine/Rclone.php b/src/CommandLine/Rclone.php index 30c6069..94634b5 100644 --- a/src/CommandLine/Rclone.php +++ b/src/CommandLine/Rclone.php @@ -4,118 +4,27 @@ namespace Cubist\Util\CommandLine; use Cubist\Util\CommandLine; -class Rclone extends CommandLine +class Rclone extends CloneUserpassProgram { - protected $_prog = '/usr/bin/rclone'; - /** - * @var string - */ - protected $_src; - /** - * @var string - */ - protected $_dest; - /** - * @var bool - */ - protected $_mirror = false; - - /** - * @var bool - */ - protected $_dryRun = false; - /** * @var string */ protected $_protocol = 'local'; - protected $_rcloneArgs = []; - - public function __construct($output = null, $error = true) - { - parent::__construct($this->_prog, $output, $error); - } - - public function getSrc() - { - return $this->_src; - } - - public function getDest() - { - return $this->_dest; - } - - public function getMirror() - { - return $this->_mirror; - } - - public function setSrc($src) - { - $this->_src = $src; - return $this; - } - - public function setDest($dest) - { - $this->_dest = $dest; - return $this; - } - - public function setMirror($mirror) - { - $this->_mirror = $mirror; - return $this; - } - - public function setRcloneArg($name, $value = null) - { - $this->_rcloneArgs[] = [$name, $value]; - } - - /** - * @param bool $dryRun - */ - public function setDryRun(bool $dryRun): void - { - $this->_dryRun = $dryRun; - } - - /** - * @return string - */ - public function getProtocol(): string - { - return $this->_protocol; - } - - /** - * @param string $protocol - */ - public function setProtocol(string $protocol): void - { - $this->_protocol = $protocol; - } - - /** - * @return bool - */ - public function isDryRun(): bool - { - return $this->_dryRun; - } protected function _preExecute() { parent::_preExecute(); $this->setArg(null, $this->getMirror() ? 'sync' : 'copy'); $this->setArg(null, $this->getSrc()); + $this->setArg('sftp-host', $this->getHost()); + $this->setArg('sftp-port', $this->getPort()); + $this->setArg('sftp-user', $this->getUsername()); + $this->setArg('sftp-pass', $this->getPassword()); if ($this->isDryRun()) { $this->setArg('dry-run'); } - foreach ($this->_rcloneArgs as $name => $value) { + foreach ($this->_cloneArgs as $name => $value) { $this->setArg($name, $value); } switch ($this->getProtocol()) { diff --git a/src/CommandLine/Rsync.php b/src/CommandLine/Rsync.php index c7e190f..c73a94c 100644 --- a/src/CommandLine/Rsync.php +++ b/src/CommandLine/Rsync.php @@ -5,21 +5,16 @@ namespace Cubist\Util\CommandLine; use Cubist\Util\CommandLine; use Cubist\Util\Files\Files; -class Rsync extends CommandLine +class Rsync extends CloneProgram { protected $_port = 22; - protected $_src; - protected $_dest; - protected $_mirror = false; + protected $_excludes = array(); protected $_deleteExcluded = false; - protected $_prog = '/usr/bin/rsync'; + protected $_sshKey = null; - /** - * @var bool - */ - protected $_dryRun = false; + public function getSshKey() { @@ -54,59 +49,11 @@ class Rsync extends CommandLine return $this; } - public function getSrc() - { - return $this->_src; - } - - public function getDest() - { - return $this->_dest; - } - - public function getMirror() - { - return $this->_mirror; - } - - public function setSrc($src) - { - $this->_src = $src; - return $this; - } - - public function setDest($dest) - { - $this->_dest = $dest; - return $this; - } - - public function setMirror($mirror) - { - $this->_mirror = $mirror; - return $this; - } - public function addExclude($exclude) { $this->_excludes[] = $exclude; } - /** - * @return string - */ - public function getProg() - { - return $this->_prog; - } - - /** - * @param string $prog - */ - public function setProg($prog) - { - $this->_prog = $prog; - } public function _fixPath($path) { @@ -124,7 +71,6 @@ class Rsync extends CommandLine $src = $this->getSrc(); $mirror = $this->getMirror(); - $destDistant = stristr($dest, '@'); if ($destDistant) { list($distServer, $distDir) = explode(':', $dest, 2); @@ -132,7 +78,6 @@ class Rsync extends CommandLine $dest = $distServer . ':\'' . $distDir . '\''; } - if (!file_exists($dest)) { if (!$destDistant) { Files::mkdir($dest); @@ -170,27 +115,11 @@ class Rsync extends CommandLine public function __construct($src, $dest, $mirror = false, $output = null, $error = true) { - parent::__construct($this->_prog, $output, $error); + parent::__construct($output, $error); $this->setSrc($src); $this->setDest($dest); $this->setMirror($mirror); } - /** - * @param bool $dryRun - */ - public function setDryRun(bool $dryRun): void - { - $this->_dryRun = $dryRun; - } - - /** - * @return bool - */ - public function isDryRun(): bool - { - return $this->_dryRun; - } - } -- 2.39.5