Parcourir la source

Updated update function

AY il y a 3 ans
Parent
commit
1e140726ce
4 fichiers modifiés avec 72 ajouts et 62 suppressions
  1. 1 1
      mod/updates/handler.go
  2. 4 4
      mod/updates/updates.go
  3. 1 1
      system/update.json
  4. 66 56
      web/SystemAO/updates/index.html

+ 1 - 1
mod/updates/handler.go

@@ -41,7 +41,7 @@ type UpdateConfig struct {
 		} `json:"freebsd"`
 	} `json:"binary"`
 	Webpack  string `json:"webpack"`
-	Checusum string `json:"checusum"`
+	Checksum string `json:"checksum"`
 }
 
 func HandleUpdateCheckSize(w http.ResponseWriter, r *http.Request) {

+ 4 - 4
mod/updates/updates.go

@@ -116,13 +116,13 @@ func DownloadUpdatesFromURL(binaryURL string, webpackURL string, checksumURL str
 		os.Remove(checksumDownloadTarget)
 		if !binaryBool {
 			progressUpdateFunction(1, 100, "Binary checksum mismatch")
-			errorMessage = err.Error()
-			return err
+			errorMessage = "Binary checksum mismatch"
+			return errors.New("Binary checksum mismatch")
 		}
 		if !webPackBool {
 			progressUpdateFunction(1, 100, "Web pack checksum mismatch")
-			errorMessage = err.Error()
-			return err
+			errorMessage = "Web pack checksum mismatch"
+			return errors.New("Web pack checksum mismatch")
 		}
 	}
 

+ 1 - 1
system/update.json

@@ -26,5 +26,5 @@
         }
     },
     "webpack": "https://github.com/tobychui/arozos/releases/latest/download/web.tar.gz",
-    "checksum": ""
+    "checksum": "https://jenkins.alanyeung.co/job/arozos/lastSuccessfulBuild/artifact/arozos_file_checksum.sha1"
 }

+ 66 - 56
web/SystemAO/updates/index.html

@@ -1,5 +1,6 @@
 <!DOCTYPE html>
 <html ng-app="App">
+
 <head>
     <title>System Update</title>
     <meta charset="UTF-8">
@@ -9,6 +10,7 @@
     <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
     <!-- <script type="text/javascript" src="../../script/ao_module.js"></script> -->
 </head>
+
 <body>
     <div class="ui container">
         <div class="ui basic segment">
@@ -16,7 +18,7 @@
                 <i class="sync icon"></i>
                 <div class="content">
                     System Update
-                  <div class="sub header">Update the ArozOS System to the latest version</div>
+                    <div class="sub header">Update the ArozOS System to the latest version</div>
                 </div>
             </h3>
             <div class="ui divider"></div>
@@ -43,7 +45,7 @@
                 <i class="yellow exclamation icon"></i>
                 <div class="content">
                     <div class="header">
-                    Confirm Update?
+                        Confirm Update?
                     </div>
                     <p><span>This updates will take up </span><span id="spaceEst" style="font-weight: bold;"></span> <span>of space.</span></p>
                     <p><b>Please make sure you have back up all important files and config files before you proceeds.</b></p>
@@ -60,12 +62,14 @@
                         Starting Download Session
                     </div>
                     <br>
-                    <p id="fallbackmodeExp" style="display:none;">You are seeing this message is because the websocket connection to your host failed to establish. No worry, updates can still be done using AJAX fallback mode, just without the real time progress updates. <br>Please wait until the download complete before closing this page.</br></p>
+                    <p id="fallbackmodeExp" style="display:none;">You are seeing this message is because the websocket connection to your host failed to establish. No worry, updates can still be done using AJAX fallback mode, just without the real time progress updates. <br>Please wait until the
+                        download complete before closing this page.</br>
+                    </p>
                     <div class="ui blue active progress">
                         <div id="downloadProgressBar" class="bar">
                             <div class="progress">0.00%</div>
                         </div>
-                      </div>
+                    </div>
                 </div>
             </div>
             <div id="success" class="ui icon green message" style="display:none;">
@@ -96,7 +100,7 @@
                 </div>
             </div>
             <div id="restartPanel" class="ui message" style="display:none;">
-                <div class="header" >
+                <div class="header">
                     Launcher Detected: <span id="launcherName">N/A</span>
                 </div>
                 <p>You will need to restart ArozOS in order to apply the updates.</p>
@@ -125,19 +129,18 @@
             <small>Usually with named as: webpack.tar.gz</small>
             <br><br>
             <button class="ui red button updateBtn" onclick="updateViaURL();"><i class="cloud upload icon"></i> Execute Update</button>
-            
+
             <div class="ui divider"></div>
 
 
             <div class="ui message">
                 <h4><i class="info circle icon"></i>Update Instruction</h4>
-                <p>To update your ArozOS system, you will need two files: A compiled binary of the newer version of ArozOS and the webpack compress file in .tar.gz format.
-                You can get the two files on Github, private distribution servers or from cluster nodes. Please choose one of the update method below and press "Update" to start the update process.</p>
+                <p>To update your ArozOS system, you will need two files: A compiled binary of the newer version of ArozOS and the webpack compress file in .tar.gz format. You can get the two files on Github, private distribution servers or from cluster
+                    nodes. Please choose one of the update method below and press "Update" to start the update process.</p>
                 <p>Notes that updates only work if ArozOS is started by the launcher. If not, you might need to manually update the system using system commands.</p>
                 <div class="ui accordion">
                     <div class="title">
-                      <i class="dropdown icon"></i>
-                      How to update manually?
+                        <i class="dropdown icon"></i> How to update manually?
                     </div>
                     <div class="content">
                         <p>If your system is not started by any launcher (versions before v1.120), you might want to manually update the ArozOS following the steps below.</p>
@@ -147,7 +150,8 @@
                             <div class="item">SSH into your host, cd into the ArozOS root (Usually located at ~/arozos/src/)</div>
                             <div class="item">Check if the "updates" folder exists. If yes, check if the new ArozOS binary and "system" and "web" folder exists</div>
                             <div class="item">Backup any important files or config if needed</div>
-                            <div class="item">Stop the arozos service using <code>sudo systemctl stop arozos</code></code></div>
+                            <div class="item">Stop the arozos service using <code>sudo systemctl stop arozos</code></code>
+                            </div>
                             <div class="item">Copy the updates to the arozos root using <code>cp -r ./updates/* ./</code></div>
                             <div class="item">Restore the files or config</div>
                             <div class="item">Start the arozos service using <code>sydo systemctl start arozos</code></div>
@@ -174,21 +178,22 @@
         var useVendorUpdate = false;
         var vendorUpdateBinaryURL = "";
         var vendorUpdateWebpackURL = "";
+        var vendorUpdateCheckSumURL = "";
 
         $(".accordion").accordion();
         initVendorUpdateInfo();
         checkPendingUpdates();
 
-        function checkPendingUpdates(){
-            $.get("../../system/update/checkpending", function(data){
-                if (data == true){
+        function checkPendingUpdates() {
+            $.get("../../system/update/checkpending", function(data) {
+                if (data == true) {
                     //There is a pending update.
                     hideAllStatus();
                     $("#pending").slideDown('fast');
-                    $.get("/system/update/restart", function(data){
-                        if (data.error !== undefined){
+                    $.get("/system/update/restart", function(data) {
+                        if (data.error !== undefined) {
                             //No launcher
-                        }else{
+                        } else {
                             $("#launcherName").text(data);
                             $("#restartPanel").show();
                         }
@@ -198,90 +203,94 @@
             })
         }
 
-        function initVendorUpdateInfo(){
-            $.get("../../system/update/platform", function(data){
+        function initVendorUpdateInfo() {
+            $.get("../../system/update/platform", function(data) {
                 console.log(data);
-                if (data.error !== undefined){
+                if (data.error !== undefined) {
                     //No vendor update modes
                     $(".vendorupdate").hide();
-                }else{
-                    if (data.Config.binary[data.OS] && data.Config.binary[data.OS][data.ARCH]){
+                } else {
+                    if (data.Config.binary[data.OS] && data.Config.binary[data.OS][data.ARCH]) {
                         //This update target exists
                         vendorUpdateBinaryURL = data.Config.binary[data.OS][data.ARCH];
                     }
                     vendorUpdateWebpackURL = data.Config.webpack;
+                    vendorUpdateCheckSumURL = data.Config.checksum;
                     $(".vendorName").text(data.Config.vendor);
                 }
             })
         }
 
-        function updateViaVendor(){
+        function updateViaVendor() {
             let binaryDownloadURL = vendorUpdateBinaryURL;
             let webpackDownloadURL = vendorUpdateWebpackURL;
-            if (binaryDownloadURL == "" || webpackDownloadURL == ""){
+
+            if (binaryDownloadURL == "" || webpackDownloadURL == "") {
                 return
             }
             //Check space need
             $("#checking").slideDown("fast");
             $("#warning").slideUp("fast");
             useVendorUpdate = true;
-            $.get(`/system/update/checksize?webpack=${webpackDownloadURL}&binary=${binaryDownloadURL}`, function(data){
-                if (data.error != undefined){
+            $.get(`/system/update/checksize?webpack=${webpackDownloadURL}&binary=${binaryDownloadURL}`, function(data) {
+                if (data.error != undefined) {
                     cancelUpdateStatus();
                     alert("Update failed: " + data.error)
-                }else{
+                } else {
                     let totalDownloadBytes = data[0] + data[1];
                     $("#spaceEst").text(ao_module_utils.formatBytes(totalDownloadBytes, 2));
                     $("#confirmDownload").slideDown("fast");
                     $("#checking").slideUp("fast");
                     console.log(data);
                 }
-               
+
             })
         }
 
-        function updateViaURL(){
+        function updateViaURL() {
             let binaryDownloadURL = $("#burl").val().trim();
             let webpackDownloadURL = $("#wurl").val().trim();
-            if (binaryDownloadURL == "" || webpackDownloadURL == ""){
+            if (binaryDownloadURL == "" || webpackDownloadURL == "") {
                 alert("Invalid or Empty URL given");
                 return
             }
             //Check space need
             $("#checking").slideDown("fast");
             $("#warning").slideUp("fast");
-            $.get(`/system/update/checksize?webpack=${webpackDownloadURL}&binary=${binaryDownloadURL}`, function(data){
-                if (data.error != undefined){
+            $.get(`/system/update/checksize?webpack=${webpackDownloadURL}&binary=${binaryDownloadURL}`, function(data) {
+                if (data.error != undefined) {
                     cancelUpdateStatus();
                     alert("Update failed: " + data.error)
-                }else{
+                } else {
                     let totalDownloadBytes = data[0] + data[1];
                     $("#spaceEst").text(ao_module_utils.formatBytes(totalDownloadBytes, 2));
                     $("#confirmDownload").slideDown("fast");
                     $("#checking").slideUp("fast");
                     console.log(data);
                 }
-               
+
             })
         }
 
-        function confirmURLUpdate(){
+        function confirmURLUpdate() {
             let binaryDownloadURL = $("#burl").val().trim();
             let webpackDownloadURL = $("#wurl").val().trim();
+            let checksumDownloadURL = "";
 
-            if (useVendorUpdate){
+            if (useVendorUpdate) {
                 //Use vendor link for update. Replace the download target with vendor update links
                 useVendorUpdate = false;
                 binaryDownloadURL = vendorUpdateBinaryURL;
                 webpackDownloadURL = vendorUpdateWebpackURL;
+                checksumDownloadURL = vendorUpdateCheckSumURL;
             }
-            if (binaryDownloadURL == "" || webpackDownloadURL == ""){
+            if (binaryDownloadURL == "" || webpackDownloadURL == "") {
                 alert("Invalid or Empty URL given");
                 return
             }
 
             var wsroot = ao_module_utils.getWebSocketEndpoint();
-            var requestEndpoint = wsroot + `/system/update/download?webpack=${webpackDownloadURL}&binary=${binaryDownloadURL}&ws=true`
+            var requestEndpoint = wsroot + `/system/update/download?webpack=${webpackDownloadURL}&binary=${binaryDownloadURL}&checksum=${checksumDownloadURL}&ws=true`
             console.log("Connecting to: ", requestEndpoint);
 
             hideAllStatus();
@@ -296,15 +305,15 @@
 
             socket.onmessage = function(event) {
                 let status = JSON.parse(event.data);
-                if (status.error !== undefined){
+                if (status.error !== undefined) {
                     hideAllStatus();
                     $("#failed").slideDown();
                     $("#failedErrorMessage").text(status.error);
-                }else{
+                } else {
                     //Progressing
                     let progressText = status.Progress.toFixed(2) + "%";
                     $("#downloadProgressBar").find(".progress").text(progressText);
-                    $("#downloadProgressBar").css("width",status.Progress + "%");
+                    $("#downloadProgressBar").css("width", status.Progress + "%");
                     $("#downloadStatusText").text(`[${status.Stage}] ${status.StatusText}`);
                 }
                 console.log(event.data);
@@ -322,7 +331,7 @@
             };
         }
 
-        function downloadUpdateFallbackMode(binaryDownloadURL, webpackDownloadURL){
+        function downloadUpdateFallbackMode(binaryDownloadURL, webpackDownloadURL) {
             hideAllStatus();
             $("#downloading").slideDown("fast");
             $("#downloadStatusText").text("Waiting for Download Complete (Fallback Mode)");
@@ -330,13 +339,13 @@
             $("#downloadProgressBar").find(".progress").text("Downloading");
             $("#downloadProgressBar").css("width", "50%");
             $(".updateBtn").addClass("disabled");
-            $.get(`../../system/update/download?webpack=${webpackDownloadURL}&binary=${binaryDownloadURL}`, function(data){
-                if (data.error !== undefined){
+            $.get(`../../system/update/download?webpack=${webpackDownloadURL}&binary=${binaryDownloadURL}`, function(data) {
+                if (data.error !== undefined) {
                     hideAllStatus();
                     $("#failed").slideDown();
                     $("#failedErrorMessage").text(data.error);
                     $(".updateBtn").removeClass("disabled");
-                }else{
+                } else {
                     hideAllStatus();
                     $("#success").slideDown();
                     checkLauncher();
@@ -344,38 +353,38 @@
             })
         }
 
-        function checkLauncher(){
+        function checkLauncher() {
             $(".updateBtn").removeClass("disabled");
-            $.get("/system/update/restart", function(data){
-                if (data.error !== undefined){
+            $.get("/system/update/restart", function(data) {
+                if (data.error !== undefined) {
                     //No launcher
                     $("#restartPanel").hide();
-                }else{
+                } else {
                     $("#launcherName").text(data);
                     $("#restartPanel").show();
                 }
                 console.log("Launcher check: ", data);
             })
-           
+
         }
 
-        function restartArozOS(){
-            if (confirm("CONFIRM RESTART?")){
+        function restartArozOS() {
+            if (confirm("CONFIRM RESTART?")) {
                 window.top.location.href = "../updates/updating.html";
             }
         }
 
-        function cancelUpdateStatus(){
+        function cancelUpdateStatus() {
             hideAllStatus();
             $("#warning").slideDown("fast");
         }
 
-        function restartLater(){
+        function restartLater() {
             hideAllStatus();
         }
 
 
-        function hideAllStatus(){
+        function hideAllStatus() {
             $("#warning").slideUp("fast");
             $("#confirmDownload").slideUp("fast");
             $("#checking").slideUp("fast");
@@ -386,4 +395,5 @@
         }
     </script>
 </body>
-</html>  
+
+</html>