From 82e4d1ca348748e8cdde86f65e62221968cabed5 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 18 Apr 2021 21:46:12 +0200 Subject: Slight refactoring --- src/Module/Modules/AptModule.php | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/Module/Modules/AptModule.php (limited to 'src/Module/Modules') diff --git a/src/Module/Modules/AptModule.php b/src/Module/Modules/AptModule.php new file mode 100644 index 0000000..ccf4892 --- /dev/null +++ b/src/Module/Modules/AptModule.php @@ -0,0 +1,54 @@ +enablePTY(); + + $ssh->exec("dpkg -l $this->package | grep 'ii'"); + $dpkg = $ssh->read(); + + $state = match ($this->state) { + State::PRESENT => str_starts_with($dpkg, 'ii'), + State::ABSENT => str_contains($dpkg, 'no packages found'), + }; + + $ssh->disablePTY(); + + return $state; + } + + /** + * @inheritDoc + */ + public function getCommands(): array + { + return match ($this->state) { + State::PRESENT => ["sudo apt install -y $this->package"], + State::ABSENT => ["sudo apt remove -y $this->package"], + }; + } +} -- cgit v1.2.3