]> git.ipfire.org Git - pakfire.git/commitdiff
cli: pakfire-builder: Implement repo compose
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 11:13:04 +0000 (11:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 11:13:04 +0000 (11:13 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/cli/lib/repo.c [new file with mode: 0644]
src/cli/lib/repo.h [new file with mode: 0644]
src/cli/lib/repo_compose.c [new file with mode: 0644]
src/cli/lib/repo_compose.h [new file with mode: 0644]
src/cli/pakfire-builder.c

index baa60a7946c76dde7f0125b4532ff0d5bacd92ee..9dbfab4375f003369c5b9852183e88152bee3bf4 100644 (file)
@@ -449,6 +449,10 @@ libcli_la_SOURCES = \
        src/cli/lib/provides.c \
        src/cli/lib/remove.c \
        src/cli/lib/remove.h \
+       src/cli/lib/repo.c \
+       src/cli/lib/repo.h \
+       src/cli/lib/repo_compose.c \
+       src/cli/lib/repo_compose.h \
        src/cli/lib/repolist.c \
        src/cli/lib/repolist.h \
        src/cli/lib/requires.c \
diff --git a/src/cli/lib/repo.c b/src/cli/lib/repo.c
new file mode 100644 (file)
index 0000000..b594fa0
--- /dev/null
@@ -0,0 +1,34 @@
+/*#############################################################################
+#                                                                             #
+# 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 <pakfire/pakfire.h>
+
+#include "command.h"
+#include "repo.h"
+#include "repo_compose.h"
+
+int cli_repo(struct pakfire* pakfire, int argc, char* argv[]) {
+       static const struct command commands[] = {
+               { "compose",  0, cli_repo_compose },
+               { NULL },
+       };
+
+       return command_dispatch(pakfire, commands, argc, argv);
+}
diff --git a/src/cli/lib/repo.h b/src/cli/lib/repo.h
new file mode 100644 (file)
index 0000000..8a1ef94
--- /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_REPO_H
+#define PAKFIRE_CLI_REPO_H
+
+#include <pakfire/pakfire.h>
+
+int cli_repo(struct pakfire* pakfire, int argc, char* argv[]);
+
+#endif /* PAKFIRE_CLI_REPO_H */
diff --git a/src/cli/lib/repo_compose.c b/src/cli/lib/repo_compose.c
new file mode 100644 (file)
index 0000000..464920f
--- /dev/null
@@ -0,0 +1,137 @@
+/*#############################################################################
+#                                                                             #
+# 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 <pakfire/pakfire.h>
+
+#include "repo_compose.h"
+
+struct config {
+       const char* path;
+       char** files;
+       struct pakfire_key* key;
+};
+
+static void help(void) {
+       printf(
+               "%s [OPTIONS...] repo compose [OPTIONS...] PACKAGE...\n\n"
+               "Options:\n"
+               "     --key PATH             The key to sign the repository with\n"
+               "  -h --help                 Show help\n",
+               program_invocation_short_name
+       );
+
+       exit(0);
+}
+
+static int cli_import_key(struct pakfire_key** key,
+               struct pakfire* pakfire, const char* path) {
+       FILE* f = NULL;
+       int r;
+
+       // Open the key file
+       f = fopen(path, "r");
+       if (!f) {
+               fprintf(stderr, "Could not open key from %s: %m\n", path);
+               return -errno;
+       }
+
+       // Import the key
+       r = pakfire_key_import(key, pakfire, f);
+       if (r) {
+               fprintf(stderr, "Could not import key from %s\n", path);
+               return r;
+       }
+
+       if (f)
+               fclose(f);
+
+       return r;
+}
+
+static int parse_argv(struct pakfire* pakfire, struct config* config,
+               int argc, char* argv[]) {
+       enum {
+               ARG_KEY,
+       };
+       int r;
+
+       static const struct option options[] = {
+               { "key",  required_argument, NULL, ARG_KEY },
+               { "help", no_argument,       NULL, 'h' },
+               { NULL },
+       };
+       int c;
+
+       for (;;) {
+               c = getopt_long(argc, argv, "h", options, NULL);
+               if (c < 0)
+                       break;
+
+               switch (c) {
+                       case 'h':
+                               help();
+
+                       case ARG_KEY:
+                               r = cli_import_key(&config->key, pakfire, optarg);
+                               if (r)
+                                       return r;
+                               break;
+
+                       case '?':
+                               return -EINVAL;
+
+                       default:
+                               break;
+               }
+       }
+
+       return 0;
+}
+
+
+int cli_repo_compose(struct pakfire* pakfire, int argc, char* argv[]) {
+       struct config config = {
+               .path = NULL,
+               .key  = NULL,
+       };
+       int r;
+
+       // Parse commandline
+       r = parse_argv(pakfire, &config, argc, argv);
+       if (r)
+               return r;
+
+       // XXX check if we have enough arguments
+
+       if (optind >= argc) {
+               fprintf(stderr, "Not enough arguments\n");
+               return 1;
+       }
+
+       // Set path
+       config.path = argv[optind++]; argc--;
+       config.files = argv + optind;
+
+       return pakfire_repo_compose(pakfire, config.path, config.key, (const char**)config.files);
+}
diff --git a/src/cli/lib/repo_compose.h b/src/cli/lib/repo_compose.h
new file mode 100644 (file)
index 0000000..ff6b61c
--- /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_REPO_COMPOSE_H
+#define PAKFIRE_CLI_REPO_COMPOSE_H
+
+#include <pakfire/pakfire.h>
+
+int cli_repo_compose(struct pakfire* pakfire, int argc, char* argv[]);
+
+#endif /* PAKFIRE_CLI_REPO_COMPOSE_H */
index 9d45afa27c420ad116b851992027d27a1f641f89..d3d7342ae7be742e6d44b9e02a07ceeb4b67dc84 100644 (file)
@@ -34,6 +34,7 @@
 #include "lib/dist.h"
 #include "lib/info.h"
 #include "lib/provides.h"
+#include "lib/repo.h"
 #include "lib/repolist.h"
 #include "lib/requires.h"
 #include "lib/shell.h"
@@ -62,6 +63,7 @@ static int cli_main(struct pakfire* pakfire, int argc, char* argv[]) {
                { "dist",     0, cli_dist },
                { "info",     0, cli_info },
                { "provides", 0, cli_provides },
+               { "repo",     0, cli_repo },
                { "repolist", 0, cli_repolist },
                { "requires", 0, cli_requires },
                { "shell",    0, cli_shell },