diff mbox series

swupdate-progress: allow to call a script after an update

Message ID 20200208134610.6383-1-sbabic@denx.de
State Accepted
Headers show
Series swupdate-progress: allow to call a script after an update | expand

Commit Message

Stefano Babic Feb. 8, 2020, 1:46 p.m. UTC
This tool can be used in productoion to monitor an update. It can be
useful to call an external script with the result of the update.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 doc/source/swupdate-progress.rst | 15 +++++++++++++++
 tools/swupdate-progress.c        | 19 ++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/doc/source/swupdate-progress.rst b/doc/source/swupdate-progress.rst
index e230df8..10178fa 100644
--- a/doc/source/swupdate-progress.rst
+++ b/doc/source/swupdate-progress.rst
@@ -12,8 +12,23 @@  swupdate-progress [option]
 DESCRIPTION
 -----------
 
+swupdate-progress is an example how to connect to SWUpdate via the progress interface.
+It shows on the stdout a simple bar with the procent indication of the current update
+and reports the result of the update. It can optionally drive "psplash" or execute a script
+after an update.
+
+-c
+        Use colors to show results on stdout
+-e
+        Command to be execute after an update
+-p
+        send percentage to psplash
 -r
         optionally reboot the target after a successful update
+-s
+        path to progress IPC socket in case the default is not taken
 -w
         waits for a SWUpdate connection instead of exit with error
+-h
+        print a help
         
diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c
index 579f167..9bf568f 100644
--- a/tools/swupdate-progress.c
+++ b/tools/swupdate-progress.c
@@ -64,6 +64,7 @@  static struct option long_options[] = {
 	{"wait", no_argument, NULL, 'w'},
 	{"color", no_argument, NULL, 'c'},
 	{"socket", required_argument, NULL, 's'},
+	{"exec", required_argument, NULL, 'e'},
 	{NULL, 0, NULL, 0}
 };
 
@@ -74,6 +75,7 @@  static void usage(char *programname)
 			programname);
 	fprintf(stdout,
 		" -c, --color             : Use colors to show results\n"
+		" -e, --exec <script>     : call the script with the result of update\n"
 		" -r, --reboot            : reboot after a successful update\n"
 		" -w, --wait              : wait for a connection with SWUpdate\n"
 		" -p, --psplash           : send info to the psplash process\n"
@@ -182,10 +184,11 @@  int main(int argc, char **argv)
 	int opt_r = 0;
 	int opt_p = 0;
 	int c;
+	char *script = NULL;
 	RECOVERY_STATUS	status = IDLE;		/* Update Status (Running, Failure) */
 
 	/* Process options with getopt */
-	while ((c = getopt_long(argc, argv, "cwprhs:",
+	while ((c = getopt_long(argc, argv, "cwprhs:e:",
 				long_options, NULL)) != EOF) {
 		switch (c) {
 		case 'c':
@@ -203,6 +206,9 @@  int main(int argc, char **argv)
 		case 's':
 			SOCKET_PROGRESS_PATH = strdup(optarg);
 			break;
+		case 'e':
+			script = strdup(optarg);
+			break;
 		case 'h':
 			usage(argv[0]);
 			exit(0);
@@ -299,6 +305,17 @@  int main(int argc, char **argv)
 			fprintf(stdout, "%s !\n", msg.status == SUCCESS
 							  ? "SUCCESS"
 							  : "FAILURE");
+			if (script) {
+				char *cmd;
+				if (asprintf(&cmd, "%s %s", script,
+						msg.status == SUCCESS ?
+						"SUCCESS" : "FAILURE") == -1) {
+					fprintf(stderr, "OOM calling post-exec script\n");
+				} else {
+					system(cmd);
+					free(cmd);
+				}
+			}
 			resetterm();
 			if (psplash_ok)
 				psplash_progress(psplash_pipe_path, &msg);