From 1cbfb63abd0173b1bd0d2cda53048c9c6c5afbe3 Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Thu, 21 Jul 2022 16:42:07 +0530 Subject: [PATCH 1/5] fix to md5 sum --- src/Helpers/Build.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 78663e2..cce36ff 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -209,7 +209,8 @@ $tmp = explode(" ", file_get_contents($path . '.md5sum')); $ret = $tmp[0]; } elseif ($this->commandExists('md5sum')) { - exec('md5sum ' . $path. ' > '.$path.'.md5sum'); + $dir = rtrim($path, $this->filename); + exec("cd $dir && md5sum " . $this->filename. ' > '.$path.'.md5sum'); $tmp = explode(" ", file_get_contents($path . '.md5sum')); $ret = $tmp[0]; } else { -- GitLab From 4e753b85803d175b618ffe965fc4cab51049993e Mon Sep 17 00:00:00 2001 From: Nivesh Krishna Date: Fri, 22 Jul 2022 10:18:25 +0000 Subject: [PATCH 2/5] skip all files that are not e-number-*.zip --- src/Helpers/Builds.php | 55 ++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index fc9d7f0..dc0a413 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -176,44 +176,35 @@ if (count($files) > 2) { foreach ($files as $file) { - $filename = pathinfo($file, PATHINFO_FILENAME); - - if (preg_match("/IMG/i", $filename)) { - continue; - } - - if (preg_match("/latest/i", $filename)) { + // Skip all files except for the ones that match the pattern + // filename starting with e- and ending with .zip are considered as valid files + if (!preg_match("/^e-[0-9\.]+-(.*)-$device\.zip$/i", $file)) { continue; } + $build = null; - $extension = pathinfo($file, PATHINFO_EXTENSION); - - if ($extension == 'zip') { - $build = null; - - // If APC is enabled - if (extension_loaded('apcu') && ini_get('apc.enabled')) { - $build = apcu_fetch($file); + // If APC is enabled + if (extension_loaded('apcu') && ini_get('apc.enabled')) { + $build = apcu_fetch($file); - // If not found there, we have to find it with the old fashion method... - if ($build === false) { - $build = new Build($file, $dir, $this->logger); - // ...and then save it for 72h until it expires again - apcu_store($file, $build, 72*60*60); - } - } else { + // If not found there, we have to find it with the old fashion method... + if ($build === false) { $build = new Build($file, $dir, $this->logger); + // ...and then save it for 72h until it expires again + apcu_store($file, $build, 72*60*60); } - - if ($build->includeInResults($this->postData['params'])) { - array_push($this->builds, $build); - } - - $sourceIncremental = isset($this->postData['params']['source_incremental']) ? $this->postData['params']['source_incremental'] : NULL; - if ($build->isValid($this->postData['params']) && $sourceIncremental && strcmp($sourceIncremental, $build->getIncremental()) === 0) { - $this->currentBuild = $build; - $this->logger->info($build->getIncremental().' is the current build'); - } + } else { + $build = new Build($file, $dir, $this->logger); + } + + if ($build->includeInResults($this->postData['params'])) { + array_push($this->builds, $build); + } + + $sourceIncremental = isset($this->postData['params']['source_incremental']) ? $this->postData['params']['source_incremental'] : NULL; + if ($build->isValid($this->postData['params']) && $sourceIncremental && strcmp($sourceIncremental, $build->getIncremental()) === 0) { + $this->currentBuild = $build; + $this->logger->info($build->getIncremental().' is the current build'); } } } -- GitLab From 8200c314f083538248ef0e00f6445fd362f8e096 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Wed, 2 Nov 2022 15:37:20 +0000 Subject: [PATCH 3/5] remove maintenance number on older updater --- src/Helpers/Build.php | 5 ++++- src/Helpers/Builds.php | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index cce36ff..7e2df2d 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -51,7 +51,7 @@ * @param type $fileName The current filename of the build * @param type $physicalPath The current path where the build lives */ - public function __construct($fileName, $physicalPath, $logger) + public function __construct($fileName, $physicalPath, $logger, $shouldDisplayPatch = false) { $this->logger = $logger; @@ -90,6 +90,9 @@ $this->apiLevel = $this->getBuildPropValue('ro.build.version.sdk') ?? ''; $this->model = $this->getBuildPropValue('ro.lineage.device') ?? $this->getBuildPropValue('ro.cm.device') ?? ($tokens[1] == 'cm' ? $tokens[9] : $tokens[8]); $this->version = $tokens[2]; + if(substr_count($this->version, ".") > 1 && !$shouldDisplayPatch) { + $this->version = substr($this->version, 0, strrpos($this->version, '.'));//remove maintenance number when using an old updater to avoid crash + } $this->preversion = $tokens[3]; $this->displayVersion = $this->getBuildPropValue('ro.cm.display.version') ?? $this->getBuildPropValue('ro.lineage.display.version') ?? ''; $this->androidVersion = $this->getBuildPropValue('ro.build.version.release') ?? ''; diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index dc0a413..add4140 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -160,7 +160,11 @@ private function getBuilds() { $params = $this->postData['params']; - + preg_match_all('/.*(eOS) v([0-9\.]+)-?((alpha|beta|rc)(\.\d)?)?.*/', $_SERVER['HTTP_USER_AGENT'], $currentTokens); + $shouldDisplayPatch=false; + if(count($currentTokens[0])>0){ + $shouldDisplayPatch = true; + } $device = isset($params['device']) ? $params['device'] : ''; $channels = isset($params['channels']) ? $params['channels'][0] : ''; @@ -189,12 +193,12 @@ // If not found there, we have to find it with the old fashion method... if ($build === false) { - $build = new Build($file, $dir, $this->logger); + $build = new Build($file, $dir, $this->logger, $shouldDisplayPatch); // ...and then save it for 72h until it expires again apcu_store($file, $build, 72*60*60); } } else { - $build = new Build($file, $dir, $this->logger); + $build = new Build($file, $dir, $this->logger, $shouldDisplayPatch); } if ($build->includeInResults($this->postData['params'])) { -- GitLab From 67107cdbc2bc7ec8263366134764720d405a0afd Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Thu, 3 Nov 2022 12:28:33 +0000 Subject: [PATCH 4/5] Send patch version only from 1.6 --- src/Helpers/Builds.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index add4140..0c8d8e5 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -162,8 +162,11 @@ $params = $this->postData['params']; preg_match_all('/.*(eOS) v([0-9\.]+)-?((alpha|beta|rc)(\.\d)?)?.*/', $_SERVER['HTTP_USER_AGENT'], $currentTokens); $shouldDisplayPatch=false; - if(count($currentTokens[0])>0){ - $shouldDisplayPatch = true; + if(isset($currentTokens[2]) && count($currentTokens[2])>0){ + $this->currenteOSVersion = $currentTokens[2][0]; + $versionArray = explode(".", $this->currenteOSVersion); + if($versionArray[0] > 1 || $versionArray[0] == 1 && $versionArray[1] > 5) + $shouldDisplayPatch = true; } $device = isset($params['device']) ? $params['device'] : ''; $channels = isset($params['channels']) ? $params['channels'][0] : ''; -- GitLab From 63439df466b13e7aa04e5b42c9810324c3c9aa19 Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Wed, 9 Nov 2022 06:02:05 +0000 Subject: [PATCH 5/5] specify minimal eOS version in rollout config file --- src/Helpers/Build.php | 39 +++++++++++++++++++++++++++++++++++++-- src/Helpers/Builds.php | 3 ++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index 7e2df2d..87bcf4d 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -403,6 +403,15 @@ private function parseSemVer($versionString) { $versionArray = explode(".", $versionString); + if(empty($versionArray[0])) { + $versionArray[0] = 0; + } + if(empty($versionArray[1])) { + $versionArray[1] = 0; + } + if(empty($versionArray[2])) { + $versionArray[2] = 0; + } return array_map("intval", $versionArray); } @@ -532,9 +541,9 @@ * @param type $params The params dictionary inside the current POST request * @return boolean True if valid, False if not. */ - public function includeInResults($params) + public function includeInResults($params, $currenteOSVersion) { - return $this->isValid($params) && $this->checkRollout() && $this->getSize() > 0; + return $this->isValid($params) && $this->checkRollout() && $this->checkRequirements($currenteOSVersion) && $this->getSize() > 0; } /** @@ -555,10 +564,36 @@ return ($configFilePath) ? json_decode( file_get_contents($configFilePath) , true) : array(); } + /** + * Return if requirements are met or not for a build + * @return boolean + */ + public function checkRequirements($currenteOSVersion="") + { + $minimalVersion = isset($this->confProp['requirements']) ? $this->confProp['requirements']['minOSVersion'] : null; + $isCompatible = true; + if(isset($minimalVersion)){ + $currenteOSVersionSemantic = $this->parseSemVer($currenteOSVersion); + $minimalSemanticVersion = $this->parseSemVer($minimalVersion); + $isCompatible = false; + if($currenteOSVersionSemantic[0] == $minimalSemanticVersion[0]){ + if($currenteOSVersionSemantic[1] == $minimalSemanticVersion[1]){ + $isCompatible = $currenteOSVersionSemantic[2] >= $minimalSemanticVersion[2]; + } + else + $isCompatible = $currenteOSVersionSemantic[1] > $minimalSemanticVersion[1]; + } + else + $isCompatible = $currenteOSVersionSemantic[0] > $minimalSemanticVersion[0]; + } + return $isCompatible; + } + /** * Return if rollout successful or not for a build * @return boolean */ + public function checkRollout() { $rolloutpercentage = isset($this->confProp['rollout']['percentage']) ? (int) $this->confProp['rollout']['percentage'] : 100; diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index 0c8d8e5..b7e84b4 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -162,6 +162,7 @@ $params = $this->postData['params']; preg_match_all('/.*(eOS) v([0-9\.]+)-?((alpha|beta|rc)(\.\d)?)?.*/', $_SERVER['HTTP_USER_AGENT'], $currentTokens); $shouldDisplayPatch=false; + $this->currenteOSVersion = -1; if(isset($currentTokens[2]) && count($currentTokens[2])>0){ $this->currenteOSVersion = $currentTokens[2][0]; $versionArray = explode(".", $this->currenteOSVersion); @@ -204,7 +205,7 @@ $build = new Build($file, $dir, $this->logger, $shouldDisplayPatch); } - if ($build->includeInResults($this->postData['params'])) { + if ($build->includeInResults($this->postData['params'], $this->currenteOSVersion)) { array_push($this->builds, $build); } -- GitLab