diff --git a/.dockerignore b/.dockerignore index 331d38729f5f7d96699c2d2d722793688bd52759..4623ebb9a1e03e03cf8ed035d1461c0f7e5b02e7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,4 @@ .git Dockerfile +builds/delta/*/*/*.zip +builds/full/*/*/*.zip diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 404c7a831296afe1fb0b5850fd36331cf52e0650..cb2308fdf88a8e3b1d066bdbaf09d4a024fc2b69 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,4 @@ -image: docker:stable +image: docker:19.03.1 # When using dind, it's wise to use the overlayfs driver for # improved performance. @@ -7,9 +7,10 @@ variables: CONTAINER_IMAGE: registry.gitlab.e.foundation:5000/e/os/lineageota PUBLISH_USER: root PUBLISH_URL: ota.ecloud.global + DOCKER_TLS_CERTDIR: "/certs" services: -- docker:dind +- docker:19.03.1-dind before_script: - 'which ssh-agent || ( apk --update add openssh-client )' diff --git a/README.md b/README.md index 12494f98f8e096c08fcf121ccb17b7414ac73450..2e647c1739cdb927a48c543c94188500f8776d31 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,29 @@ Got a question? Not sure where it should be made? See [CONTRIBUTING](CONTRIBUTIN ## How to use +### Test + +``` +$ sudo docker build -t e/lineageota . \ + && sudo docker run \ + -d \ + -p 80:80 \ + --rm \ + -v "${PWD}/builds/full:/var/www/html/builds/full" \ + --name lineageota \ + e/lineageota +``` + +Access to API via http://localhost/api/v1/\/\ + +Get logs with + +``` +$ sudo docker exec -ti lineageota tail -f LineageOTA.log +``` + +You can also use this server with a device connected to the same network, specifying the correct IP (see below). + ### Composer ```shell diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index 42d186c30f4d9891f23b2ccd623ecd5b0f4bfa55..f500f909efbb6baa96db633dbfeedba270d679cf 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -29,15 +29,15 @@ class Builds { - // This will contain the build list based on the current request + // This will contain the build list based on the current request private $builds = array(); + private $postData = array(); + private $logger = null; + private $currentBuild = null; - private $postData = array(); - private $logger = null; - - /** - * Constructor of the Builds class. - */ + /** + * Constructor of the Builds class. + */ public function __construct($logger) { $this->logger = $logger; @@ -52,14 +52,22 @@ $this->getBuilds(); } - /** - * Return a valid response list of builds available based on the current request - * @return array An array preformatted with builds - */ + /** + * Return a valid response list of builds available based on the current request + * @return array An array preformatted with builds + */ public function get() { $ret = array(); foreach ( $this->builds as $build ) { + + if (!is_null($this->currentBuild) && strcmp($this->currentBuild->getAndroidVersion(), $build->getAndroidVersion()) != 0) { + $this->logger->info($build->getIncremental().' ignored as Android version is not the same'); + continue; + } + + $this->logger->info($build->getIncremental().' is a new update'); + array_push( $ret, array( // CyanogenMod 'incremental' => $build->getIncremental(), @@ -84,21 +92,21 @@ return $ret; } - /** - * Set a custom set of POST data. Useful to hack the flow in case the data doesn't come within the body of the HTTP request - * @param array An array structured as POST data - * @return void - */ - public function setPostData( $customData ){ - $this->postData = $customData; - $this->builds = array(); - $this->getBuilds(); - } - - /** - * Return a valid response of the delta build (if available) based on the current request - * @return array An array preformatted with the delta build - */ + /** + * Set a custom set of POST data. Useful to hack the flow in case the data doesn't come within the body of the HTTP request + * @param array An array structured as POST data + * @return void + */ + public function setPostData( $customData ){ + $this->postData = $customData; + $this->builds = array(); + $this->getBuilds(); + } + + /** + * Return a valid response of the delta build (if available) based on the current request + * @return array An array preformatted with the delta build + */ public function getDelta() { $ret = false; @@ -126,7 +134,7 @@ return $ret; } - /* Utility / Internal */ + /* Utility / Internal */ private function getBuilds() { // Get physical paths of where the files resides @@ -171,10 +179,18 @@ if ( $build->isValid( $this->postData['params'] ) ) { array_push( $this->builds , $build ); + + if (strcmp($this->postData['params']['source_incremental'], $build->getIncremental()) == 0) { + $this->currentBuild = $build; + $this->logger->info($build->getIncremental().' is the current build'); + } } } } } } + + if (!empty($this->postData['params']['source_incremental']) && is_null($this->currentBuild)) + $this->currentBuild = $this->builds[1]; } }