]> git.ipfire.org Git - pakfire.git/commitdiff
cli: pakfire-builder: Implement shell
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 28 Sep 2023 15:16:08 +0000 (15:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 28 Sep 2023 15:16:08 +0000 (15:16 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/cli/lib/shell.c [new file with mode: 0644]
src/cli/lib/shell.h [new file with mode: 0644]
src/cli/pakfire-builder.c

index 486cacb2d90ebdf479ea348eff2064450afc2704..e94fd4fe04bcddaa991db80a57ac4e2043a2c9a4 100644 (file)
@@ -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 (file)
index 0000000..982de8e
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <errno.h>
+#include <getopt.h>
+#include <stdlib.h>
+
+#include "command.h"
+#include "shell.h"
+
+#include <pakfire/build.h>
+#include <pakfire/pakfire.h>
+
+#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 (file)
index 0000000..1bc6fe7
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PAKFIRE_CLI_SHELL_H
+#define PAKFIRE_CLI_SHELL_H
+
+#include <pakfire/pakfire.h>
+
+int cli_shell(struct pakfire* pakfire, int argc, char* argv[]);
+
+#endif /* PAKFIRE_CLI_SHELL_H */
index e48ab4ba099b7c725d1a22bdaa5096be4101aac6..d7a85901b73bf4cc9303f50a918303198846d9df 100644 (file)
@@ -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 },
        };