summaryrefslogtreecommitdiff
path: root/src/Module/Modules/AptModule.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Module/Modules/AptModule.php')
-rw-r--r--src/Module/Modules/AptModule.php54
1 files changed, 0 insertions, 54 deletions
diff --git a/src/Module/Modules/AptModule.php b/src/Module/Modules/AptModule.php
deleted file mode 100644
index ccf4892..0000000
--- a/src/Module/Modules/AptModule.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-
-namespace PHPIAC\Module\Modules;
-
-use PHPIAC\Module\ModuleInterface;
-use PHPIAC\Module\State;
-use phpseclib3\Net\SSH2;
-
-class AptModule implements ModuleInterface
-{
- /**
- * AptModule constructor.
- *
- * @param string $package
- * @param string $state
- */
- public function __construct(
- private string $package,
- private string $state = State::PRESENT
- ) {}
-
- /**
- * @inheritDoc
- */
- public function checkState(): bool
- {
- global $ssh;
- /**@var SSH2 $ssh*/
- $ssh->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"],
- };
- }
-}