diff options
| author | Daniel Weipert <code@drogueronin.de> | 2021-04-20 12:44:20 +0200 | 
|---|---|---|
| committer | Daniel Weipert <code@drogueronin.de> | 2021-04-20 12:44:20 +0200 | 
| commit | 11dc8c730dda2c5bd38cb386f96331c5ce3cac9c (patch) | |
| tree | b2c03112114af00e33ce8e1276194906064fcf93 /src/AptModule.php | |
| parent | d4d5ae3bb6566311b2d42cf888e463b62f6cf0dc (diff) | |
Adds a bunch of new Modules
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 [];      }  }  | 
