From: Michael Tremer Date: Thu, 28 Sep 2023 15:16:08 +0000 (+0000) Subject: cli: pakfire-builder: Implement shell X-Git-Tag: 0.9.30~1611 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=beee2bda3b44506146c51c8e208cce011c7c1832;p=pakfire.git cli: pakfire-builder: Implement shell Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 486cacb2d..e94fd4fe0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -449,6 +449,8 @@ libcli_la_SOURCES = \ src/cli/lib/repolist.h \ src/cli/lib/requires.c \ src/cli/lib/requires.h \ + src/cli/lib/shell.c \ + src/cli/lib/shell.h \ src/cli/lib/search.c \ src/cli/lib/search.h \ src/cli/lib/sync.c \ diff --git a/src/cli/lib/shell.c b/src/cli/lib/shell.c new file mode 100644 index 000000000..982de8e35 --- /dev/null +++ b/src/cli/lib/shell.c @@ -0,0 +1,110 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#include +#include +#include + +#include "command.h" +#include "shell.h" + +#include +#include + +#define MAX_PACKAGES 128 + +struct config { + int flags; + const char* packages[MAX_PACKAGES]; + unsigned int num_packages; +}; + +static void help(void) { + printf( + "%s [OPTIONS...] shell [OPTIONS...]\n\n" + "Options:\n" + " --disable-snapshot Do not use the snapshot\n" + " --install PACKAGE Installs the given package\n" + " -h --help Show help\n", + program_invocation_short_name + ); + + exit(0); +} + +static int parse_argv(struct config* config, int argc, char* argv[]) { + enum { + ARG_DISABLE_SNAPSHOT, + ARG_INSTALL, + }; + + static const struct option options[] = { + { "disable-snapshot", no_argument, NULL, ARG_DISABLE_SNAPSHOT }, + { "help", no_argument, NULL, 'h' }, + { "install", required_argument, NULL, ARG_INSTALL }, + { NULL }, + }; + int c; + + for (;;) { + c = getopt_long(argc, argv, "h", options, NULL); + if (c < 0) + break; + + switch (c) { + case 'h': + help(); + + case ARG_DISABLE_SNAPSHOT: + config->flags |= PAKFIRE_BUILD_DISABLE_SNAPSHOT; + break; + + case ARG_INSTALL: + if (config->num_packages >= MAX_PACKAGES) + return -ENOBUFS; + + config->packages[config->num_packages++] = optarg; + break; + + case '?': + return -EINVAL; + + default: + break; + } + } + + return 0; +} + +int cli_shell(struct pakfire* pakfire, int argc, char* argv[]) { + struct config config = { + .packages = { NULL }, + .num_packages = 0, + }; + int r; + + // Parse commandline + r = parse_argv(&config, argc, argv); + if (r) + return r; + + return pakfire_shell(pakfire, config.packages, config.flags); +} diff --git a/src/cli/lib/shell.h b/src/cli/lib/shell.h new file mode 100644 index 000000000..1bc6fe735 --- /dev/null +++ b/src/cli/lib/shell.h @@ -0,0 +1,28 @@ +/*############################################################################# +# # +# Pakfire - The IPFire package management system # +# Copyright (C) 2023 Pakfire development team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +#############################################################################*/ + +#ifndef PAKFIRE_CLI_SHELL_H +#define PAKFIRE_CLI_SHELL_H + +#include + +int cli_shell(struct pakfire* pakfire, int argc, char* argv[]); + +#endif /* PAKFIRE_CLI_SHELL_H */ diff --git a/src/cli/pakfire-builder.c b/src/cli/pakfire-builder.c index e48ab4ba0..d7a85901b 100644 --- a/src/cli/pakfire-builder.c +++ b/src/cli/pakfire-builder.c @@ -34,6 +34,7 @@ #include "lib/provides.h" #include "lib/repolist.h" #include "lib/requires.h" +#include "lib/shell.h" #include "lib/search.h" #include "lib/terminal.h" #include "lib/version.h" @@ -59,6 +60,7 @@ static int cli_main(struct pakfire* pakfire, int argc, char* argv[]) { { "provides", 0, cli_provides }, { "repolist", 0, cli_repolist }, { "requires", 0, cli_requires }, + { "shell", 0, cli_shell }, { "search", 0, cli_search }, { NULL }, };