From d82ffb4f818277c0a996dafde4b44eab27687915 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 4 Jul 2020 12:12:11 +0200 Subject: [PATCH] gluon-autoupdater: make site.conf branch setting optional Default to the alphabetically smallest branch if none is set in site.conf. Also prevent enabling the autoupdater when no branches exist. --- package/gluon-autoupdater/check_site.lua | 2 +- .../luasrc/lib/gluon/upgrade/500-autoupdater | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package/gluon-autoupdater/check_site.lua b/package/gluon-autoupdater/check_site.lua index e247cc5d..eaabf285 100644 --- a/package/gluon-autoupdater/check_site.lua +++ b/package/gluon-autoupdater/check_site.lua @@ -1,4 +1,4 @@ -need_string(in_site({'autoupdater', 'branch'})) +need_string(in_site({'autoupdater', 'branch'}), false) need_table({'autoupdater', 'branches'}, function(branch) need_alphanumeric_key(branch) diff --git a/package/gluon-autoupdater/luasrc/lib/gluon/upgrade/500-autoupdater b/package/gluon-autoupdater/luasrc/lib/gluon/upgrade/500-autoupdater index 2835d088..6ccd3072 100755 --- a/package/gluon-autoupdater/luasrc/lib/gluon/upgrade/500-autoupdater +++ b/package/gluon-autoupdater/luasrc/lib/gluon/upgrade/500-autoupdater @@ -5,6 +5,8 @@ local uci = require('simple-uci').cursor() local unistd = require 'posix.unistd' +local min_branch + for name, config in pairs(site.autoupdater.branches()) do uci:delete('autoupdater', name) uci:section('autoupdater', 'branch', name, { @@ -13,18 +15,26 @@ for name, config in pairs(site.autoupdater.branches()) do good_signatures = config.good_signatures, pubkey = config.pubkeys, }) + + if not min_branch or (name < min_branch) then + min_branch = name + end end if not uci:get('autoupdater', 'settings') then local enabled = unistd.access('/lib/gluon/autoupdater/default_enabled') ~= nil - local branch = site.autoupdater.branch() + local branch = site.autoupdater.branch(min_branch) local f = io.open('/lib/gluon/autoupdater/default_branch') if f then branch = f:read('*line') f:close() end + if not branch then + enabled = false + end + uci:section('autoupdater', 'autoupdater', 'settings', { enabled = enabled, branch = branch,