autoupdater: add check for manifest info

With the option -c (--check) we only download the manifest and verify
them. If manifest is valid and a new firmware is available then result
is printed to stdout.

VERSION=<image_version>
SIZE=<image_size>

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert 2018-12-06 16:07:38 +01:00
parent 1dc8416ac1
commit 66f36382f0
2 changed files with 23 additions and 2 deletions

View File

@ -84,6 +84,8 @@ static void usage(void) {
" -h, --help Show this help.\n\n"
" -n, --no-action Download and validate the manifest as usual, but do not\n"
" really flash a new firmware if one is available.\n\n"
" -c, --check Validate the manifest as usual, but do not\n"
" download a new firmware.\n\n"
" --fallback Upgrade if and only if the upgrade timespan of the new\n"
" version has passed for at least 24 hours.\n\n"
" --force-version Skip version check to allow downgrades.\n\n"
@ -100,6 +102,7 @@ static void parse_args(int argc, char *argv[], struct settings *settings) {
OPTION_FORCE = 'f',
OPTION_HELP = 'h',
OPTION_NO_ACTION = 'n',
OPTION_CHECK = 'c',
OPTION_FALLBACK = 256,
OPTION_FORCE_VERSION = 257,
};
@ -109,12 +112,13 @@ static void parse_args(int argc, char *argv[], struct settings *settings) {
{"force", no_argument, NULL, OPTION_FORCE},
{"fallback", no_argument, NULL, OPTION_FALLBACK},
{"no-action", no_argument, NULL, OPTION_NO_ACTION},
{"check", no_argument, NULL, OPTION_CHECK},
{"force-version", no_argument, NULL, OPTION_FORCE_VERSION},
{"help", no_argument, NULL, OPTION_HELP},
};
while (true) {
int c = getopt_long(argc, argv, "b:fhn", options, NULL);
int c = getopt_long(argc, argv, "b:fhnc", options, NULL);
if (c < 0)
break;
@ -139,6 +143,10 @@ static void parse_args(int argc, char *argv[], struct settings *settings) {
settings->no_action = true;
break;
case OPTION_CHECK:
settings->check = true;
break;
case OPTION_FORCE_VERSION:
settings->force_version = true;
break;
@ -286,7 +294,8 @@ static bool autoupdate(const char *mirror, struct settings *s, int lock_fd) {
sprintf(manifest_url, "%s/%s.manifest", mirror, s->branch);
printf("Retrieving manifest from %s ...\n", manifest_url);
if (!s->check)
printf("Retrieving manifest from %s ...\n", manifest_url);
/* Download manifest */
ecdsa_sha256_init(&m->hash_ctx);
@ -334,6 +343,17 @@ static bool autoupdate(const char *mirror, struct settings *s, int lock_fd) {
goto out;
}
if (s->check) {
printf(
"VERSION=%s\n"
"SIZE=%u\n",
m->version,
m->imagesize
);
ret = true;
goto out;
}
if (!s->force && random() >= RAND_MAX * get_probability(m->date, m->priority, s->fallback)) {
fputs("autoupdater: info: no autoupdate this time. Use -f to override.\n", stderr);
ret = true;

View File

@ -33,6 +33,7 @@ struct settings {
bool force;
bool fallback;
bool no_action;
bool check;
bool force_version;
const char *branch;
unsigned long good_signatures;