Browse Source

Add auto updater changes

DSR! 3 years ago
parent
commit
43803db41c

+ 12 - 30
src/pineapple/modules/Advanced/api/module.php

@@ -5,6 +5,8 @@ class Advanced extends SystemModule
     private $dbConnection;
 
     const DATABASE = "/etc/pineapple/pineapple.db";
+    const UP_PATH = "/tmp/upgrade.bin";
+    const UP_FLAG = "/tmp/upgradeDownloaded";
 
     public function __construct($request)
     {
@@ -89,10 +91,6 @@ class Advanced extends SystemModule
             case 'revokeApiToken':
                 $this->revokeApiToken();
                 break;
-
-            case 'downloadManualUpgrade':
-                $this->downloadManualUpgrade();
-                break;
         }
     }
 
@@ -117,7 +115,6 @@ class Advanced extends SystemModule
     {
         exec('lsusb', $lsusb);
         $lsusb = implode("\n", $lsusb);
-
         $this->response = array('lsusb' => $lsusb);
     }
 
@@ -180,22 +177,19 @@ class Advanced extends SystemModule
             exec("cd / && patch < /tmp/hotpatch.patch");
         }
 
-        $version = escapeshellarg($this->request->version);
-        @unlink("/tmp/upgrade.bin");
-        @unlink("/tmp/upgradeDownloaded");
-        $this->execBackground("wget '{$version}' -O /tmp/upgrade.bin && touch /tmp/upgradeDownloaded");
+        $url = escapeshellarg($this->request->upgradeUrl);
+        @unlink(self::UP_PATH);
+        @unlink(self::UP_FLAG);
+        $this->execBackground("wget {$url} -O " . self::UP_PATH . " && touch " . self::UP_FLAG);
         $this->response = array("success" => true);
     }
 
     private function getDownloadStatus()
     {
-        $uploadPath = '/tmp/upgrade.bin';
-        //if (!\helper\checkRunningFull("/usr/sbin/wget")) {
-        //    $this->error = "Download error";
-        if (file_exists("/tmp/upgradeDownloaded")) {
-            $fileHash = hash_file('sha256', $uploadPath);
+        if (file_exists(self::UP_FLAG)) {
+            $fileHash = hash_file('sha256', self::UP_PATH);
             if ((bool)$this->request->isManuelUpdate) {
-                $bytes = filesize($uploadPath);
+                $bytes = filesize(self::UP_PATH);
                 $sz = 'BKMGTP';
                 $factor = floor((strlen($bytes) - 1) / 3);
   
@@ -212,15 +206,15 @@ class Advanced extends SystemModule
         } else {
             $this->response = array(
                 "completed" => false,
-                "downloaded" => filesize($uploadPath)
+                "downloaded" => filesize(self::UP_PATH)
             );
         }
     }
 
     private function performUpgrade()
     {
-        if (file_exists('/tmp/upgrade.bin')) {
-            $this->execBackground("sysupgrade -n /tmp/upgrade.bin");
+        if (file_exists(self::UP_PATH)) {
+            $this->execBackground("sysupgrade -n " . self::UP_PATH);
             $this->response = array("success" => true);
         } else {
             $this->error = "Upgrade failed.";
@@ -294,16 +288,4 @@ class Advanced extends SystemModule
             $this->error = "The revokeApiToken API call requires either a 'id', 'token', or 'name' parameter";
         }
     }
-
-    private function downloadManualUpgrade()
-    {
-        $uploadPath = '/tmp/upgrade.bin';
-        @unlink($uploadPath);
-        @unlink("/tmp/upgradeDownloaded");
-
-        $url = escapeshellarg($this->request->manualUpgradeUrl);
-        $this->execBackground("wget {$url} -O {$uploadPath} && touch /tmp/upgradeDownloaded");
-
-        $this->response = array('success' => true);
-    }
 }

+ 3 - 3
src/pineapple/modules/Advanced/js/module.js

@@ -198,7 +198,7 @@ registerController("AdvancedUpgradeController", ['$api', '$scope', '$interval',
         $api.request({
             module: 'Advanced',
             action: 'downloadUpgrade',
-            version: $scope.upgradeData['version']
+            upgradeUrl: $scope.upgradeData['upgradeUrl']
         }, function(response) {
             if (response.success === true) {
                 $scope.downloading = true;
@@ -227,8 +227,8 @@ registerController("AdvancedUpgradeController", ['$api', '$scope', '$interval',
 
         $api.request({
             module: 'Advanced',
-            action: 'downloadManualUpgrade',
-            manualUpgradeUrl: $scope.manualUpgradeUrl
+            action: 'downloadUpgrade',
+            upgradeUrl: $scope.manualUpgradeUrl
         }, function(response) {
             if (response.success === true) {
                 $scope.downloading = true;