diff options
Diffstat (limited to 'src/AptModule.php')
-rw-r--r-- | src/AptModule.php | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/AptModule.php b/src/AptModule.php index 9b882e8..c133521 100644 --- a/src/AptModule.php +++ b/src/AptModule.php @@ -2,41 +2,33 @@ namespace PHPIAC\Modules; +use PHPIAC\Connection; use PHPIAC\Module\Module; use PHPIAC\Module\State; -use phpseclib3\Net\SSH2; class AptModule extends Module { - /** - * AptModule constructor. - * - * @param string $package - * @param string $state - */ - public function __construct( - private string $package, - private string $state = State::PRESENT - ) {} + protected string $package; + + protected string $state = State::PRESENT; + protected bool $updateCache = false; /** * @inheritDoc */ public function checkState(): bool { - global $ssh; - /**@var SSH2 $ssh*/ - $ssh->enablePTY(); + Connection::enablePty(); - $ssh->exec("dpkg -l $this->package | grep 'ii'"); - $dpkg = $ssh->read(); + Connection::exec("dpkg -l $this->package | grep 'ii'"); + $dpkg = Connection::read(); $state = match ($this->state) { State::PRESENT => str_starts_with($dpkg, 'ii'), State::ABSENT => str_contains($dpkg, 'no packages found'), }; - $ssh->disablePTY(); + Connection::disablePty(); return $state; } @@ -46,9 +38,13 @@ class AptModule extends Module */ public function getCommands(): array { - return match ($this->state) { - State::PRESENT => ["sudo apt install -y $this->package"], - State::ABSENT => ["sudo apt remove -y $this->package"], - }; + if ($this->state === State::PRESENT) { + Connection::exec("sudo apt install -y $this->package"); + } + else if ($this->state === State::ABSENT) { + Connection::exec("sudo apt remove -y $this->package"); + } + + return []; } } |