From 06531f3db14a3421e7d624389c542a86355d4d06 Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Fri, 10 Jan 2025 14:34:00 +0100 Subject: [PATCH] cdba: Add option to run cdba-server locally without ssh cdba is mainly intended for remote usage, but it also works well for controlling devices that you just need occasionally and then directly connect to your local laptop instead of a remote server. Another use case is if you just use cdba to power up a standard distro on a remote board and then SSH into it remotely. To avoid interruptions, it's better to start cdba locally on the server in a tmux session. That way, temporary disconnections do not power down the board. From a protocol perspective, everything is transferred through STDIN and STDOUT. It makes no difference if we have ssh piping the data to a remote server, or if the data is directly passed to the cdba-server binary started locally. The functionality works exactly the same. Add an option for this in the cdba client. If the -h option is omitted, cdba-server is started locally. --- README | 5 +++-- cdba.c | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README b/README index 1270d45..1203269 100644 --- a/README +++ b/README @@ -19,11 +19,12 @@ from sandbox/cdba/cdba-server. Available devices are read from $HOME/.cdba = Client side The client is invoked as: - cdba -b -h [-c ] [-s ] [boot.img] + cdba -b [-h ] [-c ] [-s ] [boot.img] will be connected to using ssh and will be selected for operation. As the board's fastboot interface shows up the given boot.img -will be transfered and booted on the device. If [boot.img] is omitted, +will be transfered and booted on the device. If is omitted, the +cdba-server is started locally without using ssh. If [boot.img] is omitted, "fastboot continue" is run to boot the installed operating system. The board will execute until the key sequence ^A q is invoked or the board diff --git a/cdba.c b/cdba.c index 8595fa4..e9bb43a 100644 --- a/cdba.c +++ b/cdba.c @@ -103,8 +103,13 @@ static int fork_ssh(const char *host, const char *cmd, int *pipes) close(piped_stderr[0]); close(piped_stderr[1]); - execlp("ssh", "ssh", host, cmd, NULL); - err(1, "launching ssh failed"); + if (host) { + execlp("ssh", "ssh", host, cmd, NULL); + err(1, "launching ssh failed"); + } else { + execlp(cmd, cmd, NULL); + err(1, "launching cdba-server failed"); + } default: close(piped_stdin[0]); close(piped_stdout[1]); @@ -583,12 +588,12 @@ static void usage(void) { extern const char *__progname; - fprintf(stderr, "usage: %s -b -h [-t ] " + fprintf(stderr, "usage: %s -b [-h ] [-t ] " "[-T ] [boot.img]\n", __progname); - fprintf(stderr, "usage: %s -i -b -h \n", + fprintf(stderr, "usage: %s -i -b [-h ]\n", __progname); - fprintf(stderr, "usage: %s -l -h \n", + fprintf(stderr, "usage: %s -l [-h ]\n", __progname); exit(1); } @@ -667,9 +672,6 @@ int main(int argc, char **argv) } } - if (!host) - usage(); - switch (verb) { case CDBA_BOOT: if (optind > argc || !board)