From 56c323505b3a705eab638c68db6f0780f2724790 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Wed, 5 May 2021 18:09:08 +0200 Subject: [PATCH] luci-app-attendedsysupgrade: fix branch detection 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 (cherry picked from commit 85e9ee31239c4e912613005f4c222f13c34e9a36) --- .../view/attendedsysupgrade/overview.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js b/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js index c5d21c2f3a..f6d31a35be 100644 --- a/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js +++ b/applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js @@ -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, -- 2.30.2