autoupdater: allow skipping the version check (#187)

this commit introduces a new cli flag "--force-version"
This commit is contained in:
lemoer 2018-06-03 12:13:50 +02:00 committed by Andreas Ziegler
parent 6268f870f1
commit ed7ed7dcba
2 changed files with 9 additions and 1 deletions

View File

@ -86,6 +86,7 @@ static void usage(void) {
" really flash a new firmware if one is available.\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"
" <mirror> ... Override the mirror URLs given in the configuration. If\n"
" specified, these are not shuffled.\n\n",
stderr
@ -100,6 +101,7 @@ static void parse_args(int argc, char *argv[], struct settings *settings) {
OPTION_HELP = 'h',
OPTION_NO_ACTION = 'n',
OPTION_FALLBACK = 256,
OPTION_FORCE_VERSION = 257,
};
const struct option options[] = {
@ -107,6 +109,7 @@ 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},
{"force-version", no_argument, NULL, OPTION_FORCE_VERSION},
{"help", no_argument, NULL, OPTION_HELP},
};
@ -136,6 +139,10 @@ static void parse_args(int argc, char *argv[], struct settings *settings) {
settings->no_action = true;
break;
case OPTION_FORCE_VERSION:
settings->force_version = true;
break;
default:
usage();
exit(1);
@ -321,7 +328,7 @@ static bool autoupdate(const char *mirror, struct settings *s, int lock_fd) {
}
/* Check version and update probability */
if (!newer_than(m->version, s->old_version)) {
if (!newer_than(m->version, s->old_version) && !s->force_version) {
puts("No new firmware available.");
ret = true;
goto out;

View File

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