From ab97178233e765e04a0ccffb3d29039718ccc12d Mon Sep 17 00:00:00 2001 From: Tonoxis Date: Fri, 18 Jun 2021 00:42:19 -0400 Subject: [PATCH] Added more complete PrefixManagement class, and added skeletons for new KernelManagement Functions. --- .gitignore | 6 +++- KernelManagement.class.php | 30 ++++++++++++++++++- PrefixManagement.class.php | 60 ++++++++++++++++++++++++++++++++++---- composer.json | 4 ++- 4 files changed, 91 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 9491a2f..f2c60ef 100644 --- a/.gitignore +++ b/.gitignore @@ -360,4 +360,8 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd + +# Composer +vendor/ +composer.json.lock \ No newline at end of file diff --git a/KernelManagement.class.php b/KernelManagement.class.php index 327d201..e87a54f 100644 --- a/KernelManagement.class.php +++ b/KernelManagement.class.php @@ -69,7 +69,7 @@ class KernelManagement { $kernelPath = realpath($this->cPrefixPath."/boot/kernel"); } - + // TODO: Finish Function } private function loadConfiguration() @@ -125,6 +125,32 @@ class KernelManagement } + private function __getBootSlot() + { + // This will allow us to know what boot slot we're supposed to be flashing into, perhaps we can make a treble compatible system updater with this? + $bootSlot = trim(`getprop ro.boot.slot_suffix`); + if(empty($bootSlot)) + { + $bootSlot = ""; + } + return $bootSlot; + } + + public function installKernelTree($branch = 'flo', $repository = "https://tonoxisisle.services/git/tononixOS/ubports_kernel_google_msm", $kernelName = "3.4.y-tononixOS") + { + + } + + public function removeKernelTree($kernelName) + { + + } + + public function buildKernel($kernelName) + { + + } + public function detectBootConfiguration() { if(!file_exists($this->cPrefixPath."/boot/old_boot.img")) @@ -141,6 +167,8 @@ class KernelManagement $this->aBootConfiguration['secondaddr'] = $aboot->get("secondaddr"); $this->aBootConfiguration['tagsaddr'] = $aboot->get("tagsaddr"); $this->aBootConfiguration['cmdline'] = $aboot->get("cmdline"); + $bootSlot = $this->__getBootSlot(); + if(!empty($bootSlot)) $this->aBootConfiguration['bootslot'] = $bootSlot; $this->saveConfiguration(); } diff --git a/PrefixManagement.class.php b/PrefixManagement.class.php index 1eb27f5..7dbe1d2 100644 --- a/PrefixManagement.class.php +++ b/PrefixManagement.class.php @@ -1,27 +1,75 @@ cPrefixPath = $prefix; if(!is_dir($this->cPrefixPath)) { - return false; + $this->cPrefixPath = $this->tryDetectPrefix(); + } - + $this->setupEnvironment(); + // $this->oConfiguration = new \Noodlehaus\Config($this->cPrefixPath."/etc/tononixOS/prefix.conf", new \Noodlehaus\Parser\Xml); } function tryDetectPrefix() { - $files = Finder::findFiles('*.stage3-finished')->from(getenv("HOME")); - return $files; + 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); } diff --git a/composer.json b/composer.json index 059018a..1c456a6 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,8 @@ { "require": { "hassankhan/config": "^2.2", - "nette/finder": "^2.5" + "nette/finder": "^2.5", + "czproject/git-php": "^4.0", + "sebastian/version": "^3.0" } }