Skip to content
Snippets Groups Projects
Unverified Commit d82ffb4f authored by Matthias Schiffer's avatar Matthias Schiffer
Browse files

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.
parent ee533575
No related branches found
No related tags found
No related merge requests found
need_string(in_site({'autoupdater', 'branch'})) need_string(in_site({'autoupdater', 'branch'}), false)
need_table({'autoupdater', 'branches'}, function(branch) need_table({'autoupdater', 'branches'}, function(branch)
need_alphanumeric_key(branch) need_alphanumeric_key(branch)
......
...@@ -5,6 +5,8 @@ local uci = require('simple-uci').cursor() ...@@ -5,6 +5,8 @@ local uci = require('simple-uci').cursor()
local unistd = require 'posix.unistd' local unistd = require 'posix.unistd'
local min_branch
for name, config in pairs(site.autoupdater.branches()) do for name, config in pairs(site.autoupdater.branches()) do
uci:delete('autoupdater', name) uci:delete('autoupdater', name)
uci:section('autoupdater', 'branch', name, { uci:section('autoupdater', 'branch', name, {
...@@ -13,18 +15,26 @@ for name, config in pairs(site.autoupdater.branches()) do ...@@ -13,18 +15,26 @@ for name, config in pairs(site.autoupdater.branches()) do
good_signatures = config.good_signatures, good_signatures = config.good_signatures,
pubkey = config.pubkeys, pubkey = config.pubkeys,
}) })
if not min_branch or (name < min_branch) then
min_branch = name
end
end end
if not uci:get('autoupdater', 'settings') then if not uci:get('autoupdater', 'settings') then
local enabled = unistd.access('/lib/gluon/autoupdater/default_enabled') ~= nil 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') local f = io.open('/lib/gluon/autoupdater/default_branch')
if f then if f then
branch = f:read('*line') branch = f:read('*line')
f:close() f:close()
end end
if not branch then
enabled = false
end
uci:section('autoupdater', 'autoupdater', 'settings', { uci:section('autoupdater', 'autoupdater', 'settings', {
enabled = enabled, enabled = enabled,
branch = branch, branch = branch,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment