forked from laravel/valet
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Solus Package Manager - eopkg (#127)
* Add support for Solus Package Manager - eopkg * Update service name
- Loading branch information
1 parent
410785f
commit 549b9e5
Showing
2 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters