Verified Commit 6b2906aa authored by Karel Koci's avatar Karel Koci 🤘 Committed by Karel Koci

Add updater version and few additional variables to configuration

Version of updater is now managed in this repository and should be
updated and tagged always we are going to release new version.
Added variables to configuration. They are for better identification
what we can request from updater in configuration.
parent b124682d
UPDATER_VERSION := $(shell (git describe --match 'v*' --dirty || echo 'unknown') | sed -e 's/^v//')
LUA_NAME := $(shell for lua in lua5.1 lua-5.1 lua51 lua ; do if pkg-config $$lua ; then echo $$lua ; break ; fi ; done)
VALGRIND:=IN_VALGRIND=1 valgrind --leak-check=full --show-leak-kinds=all --track-fds=yes --trace-children=no --child-silent-after-fork=yes --error-exitcode=1
# For picosat, it otherwise needs some headers not available on musl for a feature we don't need. And we need trace enabled.
EXTRA_DEFINES := NGETRUSAGE TRACE
EXTRA_DEFINES := NGETRUSAGE TRACE UPDATER_VERSION='"$(UPDATER_VERSION)"'
include $(S)/build/Makefile.top
......
......@@ -612,6 +612,30 @@ turris_version
Content of `/etc/turris-version`. Might be nil on non-Turris systems.
self_version
~~~~~~~~~~~~
String containing version of updater.
language_version
~~~~~~~~~~~~~~~~
Number signaling version of updater configuration language used. This
is always `1` for language described in this document.
features
~~~~~~~~
Set of features current updater supports. You can check for feature
this way: `features['feature']`. These are currently available features:
priorities::
Updater handles priorities between multiple requests for same package.
provides::
Updater supports `Provides` control field.
abi_change::
Updater can handle and propagate ABI change.
installed
~~~~~~~~~
......
......@@ -35,8 +35,6 @@ libupdater_MODULES_3RDPARTY := \
libupdater_PKG_CONFIGS := $(LUA_NAME) libevent
# Workaround, lua.pc doesn't containd -ldl, even when it uses dlopen
libupdater_SO_LIBS += dl
# Enable tracing for picosat
libupdater_CFLAGS := -DTRACE
LIB_DOCS := \
journal \
......
......@@ -42,6 +42,8 @@ static void result_extend(size_t *count, struct cmd_op **result, enum cmd_op_typ
static const char *opt_help[COT_LAST] = {
[COT_HELP] =
"--help, -h Prints this text.\n",
[COT_VERSION] =
"--version, -V Prints version of updater.\n",
[COT_JOURNAL_ABORT] =
"--abort, -b Abort interrupted work in the journal and clean.\n",
[COT_JOURNAL_RESUME] =
......@@ -91,6 +93,7 @@ enum option_val {
static const struct option opt_long[] = {
{ .name = "help", .has_arg = no_argument, .val = 'h' },
{ .name = "version", .has_arg = no_argument, .val = 'V' },
{ .name = "journal", .has_arg = no_argument, .val = 'j' },
{ .name = "abort", .has_arg = no_argument, .val = 'b' },
{ .name = "add", .has_arg = required_argument, .val = 'a' },
......@@ -153,8 +156,8 @@ static void cmd_op_accepts_map(bool *map, const enum cmd_op_type accepts[]) {
for (size_t i = 0; accepts[i] != COT_LAST; i++) {
map[accepts[i]] = true;
}
// Always allow exits and help
map[COT_EXIT] = map[COT_CRASH] = map[COT_HELP] = true;
// Always allow exits, help and version
map[COT_EXIT] = map[COT_CRASH] = map[COT_HELP] = map[COT_VERSION] = true;
}
struct cmd_op *cmd_args_parse(int argc, char *argv[], const enum cmd_op_type accepts[]) {
......@@ -167,7 +170,7 @@ struct cmd_op *cmd_args_parse(int argc, char *argv[], const enum cmd_op_type acc
int c, ilongopt;
bool accepts_map[COT_LAST];
cmd_op_accepts_map(accepts_map, accepts);
while ((c = getopt_long(argc, argv, ":hbja:r:R:s:e:S:", opt_long, &ilongopt)) != -1) {
while ((c = getopt_long(argc, argv, ":hVbja:r:R:s:e:S:", opt_long, &ilongopt)) != -1) {
const struct simple_opt *opt = &simple_args[c];
if (opt->active) {
if (opt->has_arg)
......@@ -178,6 +181,10 @@ struct cmd_op *cmd_args_parse(int argc, char *argv[], const enum cmd_op_type acc
exclusive_cmd = true;
result_extend(&res_count, &result, COT_HELP, NULL);
break;
case 'V':
exclusive_cmd = true;
result_extend(&res_count, &result, COT_VERSION, NULL);
break;
case ':':
return cmd_arg_crash(result, 3, "Missing additional argument for ", argv[optind - 1], "\n");
case '?':
......@@ -258,6 +265,10 @@ void cmd_args_help(const enum cmd_op_type accepts[]) {
}
}
void cmd_args_version(void) {
fputs(UPDATER_VERSION "\n", stderr);
}
static int back_argc;
static char **back_argv;
static char *orig_wd;
......
......@@ -28,6 +28,8 @@ enum cmd_op_type {
COT_EXIT,
// Print help.
COT_HELP,
// Print updater version.
COT_VERSION,
// Print error message stored in argument variable.
COT_ERR_MSG,
// Clean up any unfinished journal work and roll back whatever can be.
......@@ -101,6 +103,11 @@ struct cmd_op *cmd_args_parse(int argc, char *argv[], const enum cmd_op_type acc
*/
void cmd_args_help(const enum cmd_op_type accepts[]);
/*
* Prints message containing updater version
*/
void cmd_args_version(void);
/*
* Deep-copy the arguments. They can be used in the reexec() function.
*/
......
......@@ -38,6 +38,7 @@ local DBG = DBG
local WARN = WARN
local run_command = run_command
local events_wait = events_wait
local get_updater_version = get_updater_version
local utils = require "utils"
local backend = require "backend"
local requests = require "requests"
......@@ -51,6 +52,13 @@ module "sandbox"
-- luacheck: globals morpher state_vars level new run_sandboxed load_state_vars
-- This can be changed often (always when we add some new feature). So it is defined here at top and not buried in code.
local updater_features = utils.arr2set({
'priorities',
'provides',
'abi_change'
})
-- WARNING: BEGIN_MAGIC (read the design morphers documentation)
--[[
......@@ -214,6 +222,9 @@ function load_state_vars()
model = utils.strip(utils.slurp('/tmp/sysinfo/model')),
board_name = utils.strip(utils.slurp('/tmp/sysinfo/board_name')),
turris_version = utils.strip(utils.slurp('/etc/turris-version')),
self_version = get_updater_version(),
language_version = 1,
features = updater_features,
--[[
In case we fail to read that file (it is not there), we match against
an empty string, which produces nil ‒ the element won't be in there.
......
......@@ -700,6 +700,11 @@ static int lua_system_reboot(lua_State *L) {
return 0;
}
static int lua_get_updater_version(lua_State *L) {
lua_pushstring(L, UPDATER_VERSION);
return 1;
}
extern bool state_log_enabled; // defined in util.c
static int lua_state_log_enabled(lua_State *L) {
......@@ -738,7 +743,8 @@ static const struct injected_func injected_funcs[] = {
{ lua_sha256, "sha256" },
{ lua_reexec, "reexec" },
{ lua_uri_internal_get, "uri_internal_get" },
{ lua_system_reboot, "system_reboot" }
{ lua_system_reboot, "system_reboot" },
{ lua_get_updater_version, "get_updater_version" }
};
#ifdef COVERAGE
......
......@@ -261,3 +261,6 @@ uri_internal_get(name)::
system_reboot(stick)::
Reboots system. Argument `stick` if set to true results in that this
newer returns.
get_updater_version()::
Returns string containing updater's version.
......@@ -37,6 +37,11 @@ void print_help() {
cmd_args_help(cmd_op_allowed);
}
void print_version() {
fputs("pkgmigrate ", stderr);
cmd_args_version();
}
int main(int argc, char *argv[]) {
// Set up logging machinery
log_stderr_level(LL_INFO);
......@@ -52,15 +57,17 @@ int main(int argc, char *argv[]) {
bool batch = false, early_exit = false;
for (; op->type != COT_EXIT && op->type != COT_CRASH; op ++)
switch (op->type) {
case COT_HELP: {
case COT_HELP:
print_help();
early_exit = true;
break;
}
case COT_ERR_MSG: {
case COT_VERSION:
print_version();
early_exit = true;
break;
case COT_ERR_MSG:
fputs(op->parameter, stderr);
break;
}
case COT_NO_OP:
top_level_config = op->parameter;
break;
......
......@@ -46,6 +46,11 @@ static void print_help() {
cmd_args_help(cmd_op_allows);
}
static void print_version() {
fputs("opkg-trans ", stderr);
cmd_args_version();
}
int main(int argc, char *argv[]) {
// Some setup of the machinery
log_stderr_level(LL_INFO);
......@@ -68,15 +73,17 @@ int main(int argc, char *argv[]) {
bool early_exit = false;
for (; op->type != COT_EXIT && op->type != COT_CRASH; op ++)
switch (op->type) {
case COT_HELP: {
case COT_HELP:
print_help();
early_exit = true;
break;
}
case COT_ERR_MSG: {
case COT_VERSION:
print_version();
early_exit = true;
break;
case COT_ERR_MSG:
fputs(op->parameter, stderr);
break;
}
case COT_INSTALL: {
const char *err = interpreter_call(interpreter, "transaction.queue_install", NULL, "s", op->parameter);
ASSERT_MSG(!err, "%s", err);
......
......@@ -54,6 +54,11 @@ static void print_help() {
cmd_args_help(cmd_op_allows);
}
static void print_version() {
fputs("pkgupdate ", stderr);
cmd_args_version();
}
const char *hook_preupdate = "/etc/updater/hook_preupdate";
const char *hook_postupdate = "/etc/updater/hook_postupdate";
const char *hook_reboot_delayed = "/etc/updater/hook_reboot_required";
......@@ -118,15 +123,17 @@ int main(int argc, char *argv[]) {
const char *task_log = NULL;
for (; op->type != COT_EXIT && op->type != COT_CRASH; op ++)
switch (op->type) {
case COT_HELP: {
case COT_HELP:
print_help();
early_exit = true;
break;
}
case COT_ERR_MSG: {
case COT_VERSION:
print_version();
early_exit = true;
break;
case COT_ERR_MSG:
fputs(op->parameter, stderr);
break;
}
case COT_NO_OP:
top_level_config = op->parameter;
break;
......
......@@ -8,7 +8,7 @@ globals = {
-- lua51 doesn't contains?
"_M",
-- From interpreter.c
"log", "state_log_enabled", "state_dump", "run_command", "download", "events_wait", "mkdtemp", "chdir", "getcwd", "mkdir", "move", "ls", "stat", "lstat", "sync", "setenv", "md5", "sha256", "reexec", "uri_internal_get", "system_reboot",
"log", "state_log_enabled", "state_dump", "run_command", "download", "events_wait", "mkdtemp", "chdir", "getcwd", "mkdir", "move", "ls", "stat", "lstat", "sync", "setenv", "md5", "sha256", "reexec", "uri_internal_get", "system_reboot", "get_updater_version",
-- From logging
"ERROR", "WARN", "INFO", "DBG", "DIE", "log_event", "c_pcall_error_handler",
-- From dumper
......
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