luci-app-attendedsysupgrade: fix branch detection
authorPaul Spooren <[email protected]>
Wed, 5 May 2021 16:09:08 +0000 (18:09 +0200)
committerPaul Spooren <[email protected]>
Wed, 5 May 2021 16:14:32 +0000 (06:14 -1000)
The running branch determines which upgrades are suggested. A jump to a
newer branch (e.g. 19.07.8 to 21.02.1) is only suggested if the advanced
mode is enable, since it may break the router.

OpenWrt versions end in either `-SNAPSHOT`, `.X-rcY` or `.x`. All these
suffixes are removed, resulting in the branch name.

Previously the `-SNAPSHOT` suffix wasn't removed resulting in wrong
branch names.

Also clean up some log spam.

Signed-off-by: Paul Spooren <[email protected]>
applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js

index c5d21c2f3a7c670c62b4b584f36104b981848fdd..f6d31a35beb7c1146b96f35d08f14d586d036d34 100644 (file)
@@ -24,6 +24,15 @@ var callUpgradeStart = rpc.declare({
        params: ["keep"]
 });
 
+function get_branch(version) {
+       // determine branch of a version
+       // SNAPSHOT -> SNAPSHOT
+       // 21.02-SNAPSHOT -> 21.02
+       // 21.02.0-rc1 -> 21.02
+       // 19.07.8 -> 19.07
+       return version.replace("-SNAPSHOT", "").split(".").slice(0, 2).join(".");
+}
+
 function install_sysupgrade(url, keep, sha256) {
        displayStatus("notice spinning", E('p', _('Downloading firmware from server to browser')));
        request.get(url, {
@@ -89,7 +98,6 @@ function request_sysupgrade(server_url, data) {
                        case 200:
                                var res = response.json()
                                var image;
-                               console.log(res)
                                for (image of res.images) {
                                        if (image.type == "sysupgrade") {
                                                break;
@@ -216,9 +224,10 @@ function request_sysupgrade(server_url, data) {
 
 function check_sysupgrade(server_url, current_version, target, board_name, packages) {
        displayStatus("notice spinning", E('p', _('Searching for an available sysupgrade')));
-       var current_branch = current_version.split(".").slice(0, 2).join(".");
+       var current_branch = get_branch(current_version);
        var advanced_mode = uci.get_first('attendedsysupgrade', 'client', 'advanced_mode') || 0;
        var candidates = [];
+
        fetch(server_url + "/api/latest")
                .then(response => response.json())
                .then(response => {
@@ -226,7 +235,7 @@ function check_sysupgrade(server_url, current_version, target, board_name, packa
                                candidates.push("SNAPSHOT");
                        } else {
                                for (let version of response["latest"]) {
-                                       var branch = version.split(".").slice(0, 2).join(".");
+                                       var branch = get_branch(version);
 
                                        // already latest version installed
                                        if (current_version == version) {
@@ -249,8 +258,6 @@ function check_sysupgrade(server_url, current_version, target, board_name, packa
                        if (candidates) {
                                var m, s, o;
 
-                               console.log(candidates);
-
                                var mapdata = {
                                        request: {
                                                board_name: board_name,