From c607772f8cfc500a6aac0fd8b2737e13622d13ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 29 Jan 2019 10:47:46 +0100 Subject: updater-ng: update turris.lua to be same as in upstream --- updater-ng/files/base.lua | 93 ---------------------------------------- updater-ng/files/turris.lua | 90 ++++++++++++++++++-------------------- updater-ng/files/updater-wipe.sh | 4 -- 3 files changed, 42 insertions(+), 145 deletions(-) delete mode 100644 updater-ng/files/base.lua delete mode 100755 updater-ng/files/updater-wipe.sh (limited to 'updater-ng') diff --git a/updater-ng/files/base.lua b/updater-ng/files/base.lua deleted file mode 100644 index 1b5e9f3..0000000 --- a/updater-ng/files/base.lua +++ /dev/null @@ -1,93 +0,0 @@ ---[[ -This file is part of updater-ng. Don't edit it. -]] - -local branch = "" -local lists -local datacollection_enabled = false -if uci then - local cursor = uci.cursor() - branch = cursor:get("updater", "override", "branch") - if branch then - WARN("Branch overriden to " .. branch) - branch = "-" .. branch - else - branch = "" - end - lists = cursor:get("updater", "pkglists", "lists") - -- TODO this can also be for example yes but this should work in default - datacollection_enabled = cursor:get("foris", "eula", "agreed_collect") == '1' -else - ERROR("UCI library is not available. Not processing user lists.") -end - --- Verify contract -if not datacollection_enabled then - local contract_valid = io.open('/usr/share/server-uplink/contract_valid', 'r') - if not contract_valid then -- Try to generate it - os.execute('/usr/share/server-uplink/contract_valid.sh') - contract_valid = io.open('/usr/share/server-uplink/contract_valid', 'r') - end - if contract_valid then - local contract_content = contract_valid:read() - datacollection_enabled = contract_content == 'valid' - contract_valid:close() - else - WARN("Contract wasn't verified") - -- For Turris 1.x expect in default valid contract - datacollection_enabled = model:match("^[Tt]urris$") - end -end - --- Guess what board this is. -local base_model = "" -if model then - if model:match("Turris Mox") then - base_model = "mox" - elseif model:match("[Oo]mnia") then - base_model = "omnia" - elseif model:match("[Tt]urris") then - base_model = "turris" - end -end - --- Definitions common url base -local base_url = "https://repo.turris.cz/" .. base_model .. branch .. "/lists/" --- Reused options for remotely fetched scripts -local script_options = { - security = "Remote", - ca = system_cas, - crl = no_crl, - pubkey = { - "file:///etc/updater/keys/release.pub", - "file:///etc/updater/keys/standby.pub", - "file:///etc/updater/keys/test.pub" -- It is normal for this one to not be present in production systems - } -} - --- The distribution base script. It contains the repository and bunch of basic packages -Script("base", base_url .. "base.lua", script_options) - --- Data collection list -if datacollection_enabled then - Script("base", base_url .. "i_agree_datacollect.lua", script_options) -end - --- Additional enabled distribution lists -if lists then - if type(lists) == "string" then -- if there is single list then uci returns just a string - lists = {lists} - end - -- Go through user lists and pull them in. - local exec_list = {} -- We want to run userlist only once even if it's defined multiple times - if type(lists) == "table" then - for _, l in ipairs(lists) do - if exec_list[l] then - WARN("User list " .. l .. " specified multiple times") - else - Script("userlist-" .. l, base_url .. l .. ".lua", script_options) - exec_list[l] = true - end - end - end -end diff --git a/updater-ng/files/turris.lua b/updater-ng/files/turris.lua index 5559507..e3dc02b 100644 --- a/updater-ng/files/turris.lua +++ b/updater-ng/files/turris.lua @@ -2,40 +2,47 @@ This file is part of updater-ng. Don't edit it. ]] -local branch = "hbs" -local lists -local datacollection_enabled = false +local uci_cursor = nil if uci then - local cursor = uci.cursor() - uci_branch = cursor:get("updater", "override", "branch") - if uci_branch then - WARN("Branch overriden to " .. uci_branch) - branch = uci_branch - end - lists = cursor:get("updater", "pkglists", "lists") - -- TODO this can also be for example yes but this should work in default - datacollection_enabled = cursor:get("foris", "eula", "agreed_collect") == '1' + uci_cursor = uci.cursor() else ERROR("UCI library is not available. Configuration not used.") end +local function uci_cnf(name, default) + if uci_cursor then + return uci_cursor:get("updater", "turris", name) or default + else + return default + end +end --- TODO Turris 1.x contract? Or should we drop it. +-- Configuration variables +local mode = uci_cnf("mode", "branch") -- should we follow branch or version? +local branch = uci_cnf("branch", "hbs") -- which branch to follow +local version = uci_cnf("version", nil) -- which version to follow +local lists = uci_cnf("lists", {}) -- what additional lists should we use --- Guess what board this is. -local base_model = "" -if model then - if model:match("Turris Mox") then - base_model = "mox" - elseif model:match("[Oo]mnia") then - base_model = "omnia" - elseif model:match("[Tt]urris") then - base_model = "turris" - end +-- Verify that we have sensible configuration +if type(lists) == "string" then -- if there is single list then uci returns just a string + lists = {lists} +end +if mode == "version" and not version then + WARN("Mode configured to be 'version' but no version provided. Changing mode to 'branch' instead.") + mode = "branch" +end + +-- Common URL base to Turris OS repository +local repo_base_uri +if mode == "branch" then + repo_base_uri = "https://repo.turris.cz/" .. branch +elseif mode == "version" then + repo_base_uri = "https://repo.turris.cz/archive/" .. version +else + DIE("Invalid updater.turris.mode specified: " .. mode) end +Export('repo_base_uri') --- Definitions common url base -local base_url = "https://repo.turris.cz/" .. base_model .. '-' .. branch .. "/lists/" --- Reused options for remotely fetched scripts +-- Common connection settings for Turris OS scripts local script_options = { security = "Remote", ca = system_cas, @@ -47,30 +54,17 @@ local script_options = { } } +local base_uri = repo_base_uri .. "/lists/" -- The distribution base script. It contains the repository and bunch of basic packages -Script("base", base_url .. "base.lua", script_options) - --- Data collection list -if datacollection_enabled then - Script("base", base_url .. "i_agree_datacollect.lua", script_options) -end +Script(base_url .. "base.lua", script_options) -- Additional enabled distribution lists -if lists then - if type(lists) == "string" then -- if there is single list then uci returns just a string - lists = {lists} - end - -- Go through user lists and pull them in. - local exec_list = {} -- We want to run userlist only once even if it's defined multiple times - if type(lists) == "table" then - for _, l in ipairs(lists) do - if exec_list[l] then - WARN("User list " .. l .. " specified multiple times") - else - Script("userlist-" .. l, base_url .. l .. ".lua", script_options) - exec_list[l] = true - end - end +local exec_list = {} -- We want to run userlist only once even if it's defined multiple times +for _, l in ipairs(lists) do + if exec_list[l] then + WARN("Turris package list '" .. l .. "' specified multiple times") + else + Script(base_url .. l .. ".lua", script_options) + exec_list[l] = true end end - diff --git a/updater-ng/files/updater-wipe.sh b/updater-ng/files/updater-wipe.sh deleted file mode 100755 index 7bd6ba8..0000000 --- a/updater-ng/files/updater-wipe.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# Empty... -# This file exists only for backward compatibility with Foris wizard and nuci. -# With Foris wizard removal we should drop this. -- cgit v1.2.3