Skip to content

Commit

Permalink
Add support for Solus Package Manager - eopkg (#127)
Browse files Browse the repository at this point in the history
* Add support for Solus Package Manager - eopkg

* Update service name
  • Loading branch information
ivanmaxlogiudice authored and jmarcher committed Jul 24, 2019
1 parent 410785f commit 549b9e5
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 1 deletion.
113 changes: 113 additions & 0 deletions cli/Valet/PackageManagers/Eopkg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace Valet\PackageManagers;

use DomainException;
use Valet\CommandLine;
use Valet\Contracts\PackageManager;

class Eopkg implements PackageManager
{
public $cli;

/**
* Create a new Eopkg instance.
*
* @param CommandLine $cli
* @return void
*/
public function __construct(CommandLine $cli)
{
$this->cli = $cli;
}

/**
* Get array of installed packages
*
* @param string $package
* @return array
*/
public function packages($package)
{
$query = "dpkg -l {$package} | grep '^ii' | sed 's/\s\+/ /g' | cut -d' ' -f2";

return explode(PHP_EOL, $this->cli->run($query));
}

/**
* Determine if the given package is installed.
*
* @param string $package
* @return bool
*/
public function installed($package)
{
return in_array($package, $this->packages($package));
}

/**
* Ensure that the given package is installed.
*
* @param string $package
* @return void
*/
public function ensureInstalled($package)
{
if (! $this->installed($package)) {
$this->installOrFail($package);
}
}

/**
* Install the given package and throw an exception on failure.
*
* @param string $package
* @return void
*/
public function installOrFail($package)
{
output('<info>['.$package.'] is not installed, installing it now via Eopkg...</info> 🍻');

$this->cli->run(trim('eopkg install -y '.$package), function ($exitCode, $errorOutput) use ($package) {
output($errorOutput);

throw new DomainException('Eopkg was unable to install ['.$package.'].');
});
}

/**
* Configure package manager on valet install.
*
* @return void
*/
public function setup()
{
// Nothing to do
}

/**
* Restart dnsmasq in Ubuntu.
*/
public function nmRestart($sm)
{
$sm->restart(['NetworkManager']);
}

/**
* Determine if package manager is available on the system.
*
* @return bool
*/
public function isAvailable()
{
try {
$output = $this->cli->run('which eopkg', function ($exitCode, $output) {
throw new DomainException('Eopkg not available');
});

return $output != '';
} catch (DomainException $e) {
return false;
}
}
}
4 changes: 3 additions & 1 deletion cli/Valet/Valet.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Valet\PackageManagers\PackageKit;
use Valet\PackageManagers\Pacman;
use Valet\PackageManagers\Yum;
use Valet\PackageManagers\Eopkg;
use Valet\ServiceManagers\LinuxService;
use Valet\ServiceManagers\Systemd;

Expand Down Expand Up @@ -124,7 +125,8 @@ public function getAvailablePackageManager()
Dnf::class,
Pacman::class,
Yum::class,
PackageKit::class
PackageKit::class,
Eopkg::class
])->first(function ($pm) {
return resolve($pm)->isAvailable();
}, function () {
Expand Down

0 comments on commit 549b9e5

Please sign in to comment.