From d4d5ae3bb6566311b2d42cf888e463b62f6cf0dc Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Mon, 19 Apr 2021 11:00:50 +0200 Subject: Initial commit --- src/AptModule.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/AptModule.php (limited to 'src/AptModule.php') diff --git a/src/AptModule.php b/src/AptModule.php new file mode 100644 index 0000000..9b882e8 --- /dev/null +++ b/src/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