diff mbox series

[V2,10/10] swupdate-client: supports selection to install

Message ID 20201113083108.12567-11-sbabic@denx.de
State Changes Requested
Headers show
Series Rework and extend IPC for install | expand

Commit Message

Stefano Babic Nov. 13, 2020, 8:31 a.m. UTC
This allows to set which part of sw-description should be parsed.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 tools/swupdate-client.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/swupdate-client.c b/tools/swupdate-client.c
index 0dc19a2..f6bff6b 100644
--- a/tools/swupdate-client.c
+++ b/tools/swupdate-client.c
@@ -40,6 +40,8 @@  static void usage(void) {
 		" Available OPTIONS\n"
 		" -h : print help and exit\n"
 		" -d : ask the server to only perform a dry run\n"
+		" -e, --select <software>,<mode> : Select software images set and source\n"
+		"                                  Ex.: stable,main\n"
 		" -q : go quite, resets verbosity\n"
 		" -v : go verbose, essentially print upgrade status messages from server\n"
 		" -p : ask the server to run post-update commands if upgrade succeeds\n"
@@ -52,6 +54,7 @@  int verbose = 1;
 bool dry_run = false;
 bool run_postupdate = false;
 int end_status = EXIT_SUCCESS;
+char *software_set = NULL, *running_mode = NULL;
 
 pthread_mutex_t mymutex;
 
@@ -132,6 +135,10 @@  static int send_file(const char* filename) {
 	struct swupdate_request req;
 	swupdate_prepare_req(&req);
 	req.dry_run = dry_run;
+	if (software_set && strlen(software_set)) {
+		strncpy(req.software_set, software_set, sizeof(req.software_set) - 1);
+		strncpy(req.running_mode, running_mode, sizeof(req.running_mode) - 1);
+	}
 	rc = swupdate_async_start(readimage, printstatus,
 				end, &req, sizeof(req));
 
@@ -161,11 +168,12 @@  static int send_file(const char* filename) {
  */
 int main(int argc, char *argv[]) {
 	int c;
+	char *pos;
 
 	pthread_mutex_init(&mymutex, NULL);
 
 	/* parse command line options */
-	while ((c = getopt(argc, argv, "dhqvp")) != EOF) {
+	while ((c = getopt(argc, argv, "dhqvpe:")) != EOF) {
 		switch (c) {
 		case 'd':
 			dry_run = true;
@@ -179,6 +187,16 @@  int main(int argc, char *argv[]) {
 		case 'v':
 			verbose++;
 			break;
+		case 'e':
+			pos = strchr(optarg, ',');
+			if (pos == NULL) {
+				fprintf(stderr, "Wrong selection %s\n", optarg);
+				exit (EXIT_FAILURE);
+			}
+			*pos++ = '\0';
+			software_set = optarg;
+			running_mode = pos;
+			break;
 		case 'p':
 			run_postupdate = true;
 			break;