gluon-autoupdater: revert to default branch when configured branch is invalid

An invalid branch may be set for various reasons:

- Previous firmware had an invalid default branch
- Branch list has changed and old UCI branch config was removed by a
  site-specific upgrade script
- Manual UCI configuration
This commit is contained in:
Matthias Schiffer 2022-05-15 11:59:51 +02:00
parent 2c65f0834b
commit 53cf8796c7
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C

View File

@ -32,19 +32,23 @@ local function default_branch()
return site.autoupdater.branch(min_branch)
end
local enabled, branch
if not uci:get('autoupdater', 'settings') then
local enabled = unistd.access('/lib/gluon/autoupdater/default_enabled') ~= nil
enabled = unistd.access('/lib/gluon/autoupdater/default_enabled') ~= nil
end
local branch = default_branch()
local old_branch = uci:get('autoupdater', 'settings', 'branch')
if not old_branch or not uci:get('autoupdater', old_branch) then
branch = default_branch()
if not branch then
enabled = false
end
end
uci:section('autoupdater', 'autoupdater', 'settings', {
uci:section('autoupdater', 'autoupdater', 'settings', {
enabled = enabled,
branch = branch,
})
end
})
uci:set('autoupdater', 'settings', 'version_file', '/lib/gluon/release')