78 lines
1.9 KiB
PHP
78 lines
1.9 KiB
PHP
<?php
|
|
namespace libTononix;
|
|
|
|
use \Nette\Utils\Finder;
|
|
use \Noodlehaus\Config;
|
|
use \Noodlehaus\Parser\Xml;
|
|
use \Noodlehaus\Parser\Properties;
|
|
use \Noodlehaus\Parser\Json;
|
|
|
|
class PrefixManagement
|
|
{
|
|
|
|
protected $cPrefixPath;
|
|
private $oConfiguration;
|
|
|
|
function __construct($prefix = "/home/phablet/.local/system")
|
|
{
|
|
$this->cPrefixPath = $prefix;
|
|
if(!is_dir($this->cPrefixPath))
|
|
{
|
|
$this->cPrefixPath = $this->tryDetectPrefix();
|
|
|
|
}
|
|
$this->setupEnvironment();
|
|
// $this->oConfiguration = new \Noodlehaus\Config($this->cPrefixPath."/etc/tononixOS/prefix.conf", new \Noodlehaus\Parser\Xml);
|
|
|
|
}
|
|
|
|
function tryDetectPrefix()
|
|
{
|
|
foreach(\Nette\Utils\Finder::findFiles('*.stage3-finished')->from(getenv("HOME"))->exclude(['.config','.vscode','.nano','.presage','.ellipsis','.antigen','.android','.npm','.ssh','.pki','anbox-data']) as $key => $file)
|
|
{
|
|
return $key;
|
|
}
|
|
return $false;
|
|
}
|
|
|
|
function setupEnvironment()
|
|
{
|
|
setenv("EPREFIX=".$this->cPrefixPath);
|
|
setenv("BPREFIX=".$this->cPrefixPath);
|
|
setenv("SHELL=".$this->cPrefixPath."/usr/bin/bash");
|
|
$pathArray = array($this->cPrefixPath."/usr/local/bin",
|
|
$this->cPrefixPath."/usr/local/sbin",
|
|
$this->cPrefixPath."/usr/bin",
|
|
$this->cPrefixPath."/usr/sbin",
|
|
$this->cPrefixPath."/bin",
|
|
$this->cPrefixPath."/sbin");
|
|
$pathString = implode(":",$pathArray);
|
|
$pathString = $pathString . ":" . getenv("PATH");
|
|
setenv("PATH=$pathString");
|
|
}
|
|
|
|
function installPackage($packageAtom)
|
|
{
|
|
exec('emerge --oneshot --update $packageAtom', $emergeLog, $retVal);
|
|
return array("log"=>$emergeLog,
|
|
"return" => $retVal);
|
|
}
|
|
|
|
function removePackage($packageAtom)
|
|
{
|
|
exec('emerge --depclean --verbose '.$packageAtom, $emergeLog, $retVal);
|
|
return array("log"=>$emergeLog,
|
|
"return" => $retVal);
|
|
}
|
|
|
|
function syncPackageLists()
|
|
{
|
|
exec('emerge --sync', $emergeLog, $retVal);
|
|
return array("log"=>$emergeLog,
|
|
"return" => $retVal);
|
|
}
|
|
|
|
|
|
|
|
}
|