Verified Commit 666f6814 authored by Karel Koci's avatar Karel Koci 🤘

Split all functionality off entry.lua and do some cleanups

In next updater release will localrepo and opkg wrapper be in separate
packages and because we now have conf.d directory we can easily add any
additional configuration code trough it and package it in separate
package. This makes much more clean entry script.

Major changes with this is that auto.lua and user.lua are no longer
loaded and we have to migrate them to /etc/updater/conf.d. So following
move will be done:
/etc/updater/user.lua -> /etc/updater/conf.d/user.lua
/etc/updater/auto.lua -> /etc/updater/conf.d/opkg-auto.lua
parent 2dd0fa41
--[[
This file is part of updater-ng-localrepo. Don't edit it.
]]
-- Add local repositories (might be missing if not installed or used)
Script("localrepo", "file:///usr/share/updater/localrepo/localrepo.lua", { ignore = { "missing" } })
......@@ -25,7 +25,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
UPDATER_CONFIG=/etc/updater/auto.lua # Automatic updater configuration file
UPDATER_CONFIG=/etc/updater/conf.d/opkg-auto.lua # Automatic updater configuration file
OPKG=/bin/opkg-cl # Path to opkg
ARGS=""
......@@ -81,12 +81,12 @@ config_clean_pkg() {
# Checks if package is specified in auto.lua config
config_pkg_in() {
grep -qe "^Install\((\| \)\"$1\"" "$UPDATER_CONFIG" || return 1
grep -qe "^Install\((\| \)\"$1\"" "$UPDATER_CONFIG"
}
# Checks if given package is installed
pkg_installed() {
[ -n "$($OPKG $ARGS list-installed "$1")" ] || return 1
[ -n "$($OPKG $ARGS list-installed "$1")" ]
}
install() {
......@@ -140,7 +140,7 @@ remove() {
# Check if $UPDATER_CONFIG exists. Otherwise create.
if [ ! -f "$UPDATER_CONFIG" ]; then
echo "-- A file with auto-generated Install commands. Do not edit." > "$UPDATER_CONFIG"
echo "-- This is automatically generated file managed by opkg wrapper script. Please don't edit!" > "$UPDATER_CONFIG"
fi
echo "$PACKAGES" | sed '1d' | while read P; do
......
--[[
This file is part of updater-ng-opkg. Don't edit it.
]]
-- Repositories configured in opkg configuration.
-- We read only customfeeds.conf as that should be only file where user should add additional repositories
local custom_feed = io.open("/etc/opkg/customfeeds.conf")
if custom_feed then
local pubkeys = {}
for f in pairs(ls('/etc/opkg/keys')) do
table.insert(pubkeys, "file:///etc/opkg/keys/" .. f)
end
for line in custom_feed:lines() do
if line:match('^%s*src/gz ') then
local name, feed_uri = line:match('src/gz[%s]+([^%s]+)[%s]+([^%s]+)')
if name and feed_uri then
DBG("Adding custom opkg feed " .. name .. " (" .. feed_uri .. ")")
Repository(name, feed_uri, {pubkey = pubkeys, ignore = {"missing"}})
else
WARN("Malformed line in customfeeds.conf:\n" .. line)
end
end
end
custom_feed:close()
else
ERROR("No /etc/opkg/customfeeds.conf file. No opkg feeds are included.")
end
-- A file with auto-generated Install commands. Do not edit.
--[[
This file is part of updater-ng. Don't edit it.
]]
local branch = ""
local lists
if uci then
-- If something is really broken, we could be unable to load the uci dynamic module. Try to do some recovery in such case and hope it works well the next time.
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")
l10n = cursor:get("updater", "l10n", "langs")
if type(l10n) == "string" then
l10n = {l10n}
end
else
ERROR("UCI library is not available. Not processing user lists.")
end
-- Guess what board this is.
local base_model = ""
if model then
if 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://api.turris.cz/updater-defs/" .. turris_version .. "/" .. base_model .. branch
-- Reused options for remotely fetched scripts
local script_options = {
security = "Remote",
ca = "file:///etc/ssl/updater.pem",
crl = "file:///tmp/crl.pem",
ocsp = false,
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)
-- 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 .. "userlists/" .. l .. ".lua", script_options)
exec_list[l] = true
end
end
end
end
-- Do not edit this file. It is the entry point. Edit the user.lua file.
--[[
Do not edit this file. It is the entry point. Create new file in conf.d instead.
Also note that for migration purpose this file is compiled in to the updater
library and so changes in this file won't affect pkgupdate execution. This file
is here just for illustration.
]]
-- Prepare variables specifying localization of system.
l10n = {} -- table with selected localizations
Export('l10n')
-- This is helper function for including localization packages.
......@@ -10,109 +17,15 @@ function for_l10n(fragment)
end
Export('for_l10n')
local branch = ""
local lists
if uci then
-- If something is really broken, we could be unable to load the uci dynamic module. Try to do some recovery in such case and hope it works well the next time.
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")
l10n = cursor:get("updater", "l10n", "langs")
if type(l10n) == "string" then
l10n = {l10n}
end
else
ERROR("UCI library is not available. Not processing user lists.")
end
-- Guess what board this is.
local base_model = ""
if model then
if 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://api.turris.cz/updater-defs/" .. turris_version .. "/" .. base_model .. branch
-- Reused options for remotely fetched scripts
local script_options = {
security = "Remote",
ca = "file:///etc/ssl/updater.pem",
crl = "file:///tmp/crl.pem",
ocsp = false,
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)
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 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 .. "userlists/" .. l .. ".lua", script_options)
exec_list[l] = true
end
end
end
end
-- Some auto-generated by command line
Script("auto-src", "file:///etc/updater/auto.lua", { security = "Local" })
-- Some provided by the user
Script("user-src", "file:///etc/updater/user.lua", { security = "Local" })
-- Add local repositories (might be missing if not installed or used)
Script("localrepo", "file:///usr/share/updater/localrepo/localrepo.lua", { ignore = { "missing" } })
-- Load all lua scripts from /etc/updater/conf.d
local confd_type, _ = stat('/etc/updater/conf.d')
local conf_dir = root_dir .. '/etc/updater/conf.d'
local confd_type, _ = stat(conf_dir)
if confd_type == 'd' then
for name, tp in pairs(ls('/etc/updater/conf.d')) do
for name, tp in pairs(ls(conf_dir)) do
if tp == 'r' and name:match('.*.lua') then
Script("conf.d-" .. name:sub(1, name:find('.lua$') - 1), "file:///etc/updater/conf.d/" .. name, { security = "Local" })
end
end
end
-- Repositories configured in opkg configuration.
-- We read only customfeeds.conf as that should be only file where user should add additional repositories
local custom_feed = io.open("/etc/opkg/customfeeds.conf")
if custom_feed then
local pubkeys = {}
for f in pairs(ls('/etc/opkg/keys')) do
table.insert(pubkeys, "file:///etc/opkg/keys/" .. f)
end
for line in custom_feed:lines() do
if line:match('^%s*src/gz ') then
local name, feed_uri = line:match('src/gz[%s]+([^%s]+)[%s]+([^%s]+)')
if name and feed_uri then
DBG("Adding custom opkg feed " .. name .. " (" .. feed_uri .. ")")
Repository(name, feed_uri, {pubkey = pubkeys, ignore = {"missing"}})
else
WARN("Malformed line in customfeeds.conf:\n" .. line)
end
Script("conf.d-" .. name:sub(1, name:find('.lua$') - 1), 'file://' .. conf_dir .. '/' .. name, { security = "Local" })
end
end
custom_feed:close()
else
ERROR("No /etc/opkg/customfeeds.conf file. No opkg feeds are included.")
DIE('No ' .. conf_dir .. ' directory!')
end
--[[
This is example configuration file. You can use it as quick reference for your own
configurations.
Note that this is Lua 5.1 so you can write any Lua code to these configuration
files and it will be executed as part of updater execution.
Full reference to language it self can be found here:
https://turris.pages.labs.nic.cz/updater/docs/language.html
]]
--[[
To add repository you have to call Repository command.
First argument must be name of repository (duplicate names are not allowed).
Second argument must be URL to repository. Use `file://` for local path.
Third argument is optional table with options for this repository.
Most important options are following:
priority: This allows you to specify priority of this repository. Packages are
preferably taken from repository with higher priority no matter even if there
is potentially newer version of package. In default all repositories has
priority 50 and you can specify any value from 0 to 100.
verification: Specifies verification level. You can specify "none" to have do no
repository verification or "sig" to check only repository signature or "cert" to
not check signature but check ssl certificate if https is used. Or use "both" to
verify both signature and ssl vertificate.
pubkey: URL to public key used for signature verification.
]]
--Repository("repo-name", "https://example.com/", { pubkey = "file:///etc/repo.pubkey" })
--[[
To specify that you want to have some package installed you have to use function
Install.
It expect packages names as arguments and optional table with additional options.
You can pass multiple arguments at once to this function and additional options
will be applied on all of those.
Most important options are following:
priority: This allows you to specify how much you want this package. It has to be
number between 0 and 100 and in default if not specified is set to 50. Updater
can ignore given package if it's not possible to install it because it collides
with some other package that is required with higher priority or with Uninstall
command with higher priority.
version: Explicitly states that we want to install given packages with some
specific version. Value has to be a string starting with at least one of these
characters "=<>". So for example if you want anything newer than version 2.0
then you can specify ">=2.0" to this option.
repository: Explicitly states that we want to install given packages from one of
specified repositories.
]]
--Install("pkg1mame", "pkg2name", { repository = {"repo-name"} })
--[[
To specify that you don't want to have some package installed you have to use
function Uninstall.
It expect packages names as arguments and optional table with additional options.
Most important options are following:
priority: See Install command for more information.
]]
--Uninstall("pkg1name", "pkg2name")
--[[
A place for user definitions.
Repository "name" "URI" { ca = "file:///etc/ssl/ca.pem", pubkey = "file:///etc/repo.pubkey" }
Install "pkgname" "other"
]]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment