78 lines
1.9 KiB
Lua
Executable File
78 lines
1.9 KiB
Lua
Executable File
#!/usr/bin/lua
|
|
|
|
local fs = require 'nixio.fs'
|
|
local site = require 'gluon.site_config'
|
|
local uci = require 'luci.model.uci'
|
|
local util = require 'luci.util'
|
|
|
|
local c = uci.cursor()
|
|
|
|
local subst = {}
|
|
|
|
subst['%%v'] = util.trim(fs.readfile('/etc/openwrt_version'))
|
|
subst['%%n'], subst['%%S'] = util.exec('. /etc/openwrt_release; echo $DISTRIB_CODENAME; echo $DISTRIB_TARGET'):match('([^\n]*)\n([^\n]*)')
|
|
subst['%%GS'] = site.site_code
|
|
subst['%%GV'] = util.trim(fs.readfile('/lib/gluon/gluon-version'))
|
|
subst['%%GR'] = util.trim(fs.readfile('/lib/gluon/release'))
|
|
|
|
function replace_patterns(url)
|
|
for k, v in pairs(subst) do
|
|
url = url:gsub(k, v)
|
|
end
|
|
|
|
return url
|
|
end
|
|
|
|
for name, config in pairs(site.autoupdater.branches) do
|
|
c:delete('autoupdater', name)
|
|
mirrors = {}
|
|
for i, v in ipairs(config.mirrors) do
|
|
mirrors[i]=replace_patterns(v)
|
|
end
|
|
c:section('autoupdater', 'branch', name,
|
|
{
|
|
name = config.name,
|
|
mirror = mirrors,
|
|
good_signatures = config.good_signatures,
|
|
pubkey = config.pubkeys,
|
|
}
|
|
)
|
|
end
|
|
|
|
if not c:get('autoupdater', 'settings') then
|
|
local enabled = 0
|
|
local branch = site.autoupdater.branch
|
|
|
|
local f = io.open('/lib/gluon/autoupdater/default_branch')
|
|
if f then
|
|
enabled = 1
|
|
branch = f:read('*line')
|
|
f:close()
|
|
end
|
|
|
|
c:section('autoupdater', 'autoupdater', 'settings',
|
|
{
|
|
enabled = enabled,
|
|
branch = branch,
|
|
}
|
|
)
|
|
end
|
|
|
|
c:set('autoupdater', 'settings', 'version_file', '/lib/gluon/release')
|
|
|
|
c:save('autoupdater')
|
|
|
|
|
|
local autoupdater_util = require 'autoupdater.util'
|
|
autoupdater_util.randomseed()
|
|
|
|
|
|
-- Perform updates at a random time between 04:00 and 05:00, and once an hour
|
|
-- a fallback update (used after the regular updates haven't
|
|
local minute = math.random(0, 59)
|
|
|
|
local f = io.open('/usr/lib/micron.d/autoupdater', 'w')
|
|
f:write(string.format('%i 4 * * * /usr/sbin/autoupdater\n', minute))
|
|
f:write(string.format('%i 0-3,5-23 * * * /usr/sbin/autoupdater --fallback\n', minute))
|
|
f:close()
|