]> git.ipfire.org Git - pakfire.git/commitdiff
cli: pakfire-builder: Implement "image create"
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 11:33:32 +0000 (11:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Sep 2023 11:52:23 +0000 (11:52 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/cli/lib/image.c [new file with mode: 0644]
src/cli/lib/image.h [new file with mode: 0644]
src/cli/lib/image_create.c [new file with mode: 0644]
src/cli/lib/image_create.h [new file with mode: 0644]
src/cli/pakfire-builder.c

index 9dbfab4375f003369c5b9852183e88152bee3bf4..431a5183d76192305ef2bc070d096abab62e879f 100644 (file)
@@ -441,6 +441,10 @@ libcli_la_SOURCES = \
        src/cli/lib/dist.h \
        src/cli/lib/dump.c \
        src/cli/lib/dump.h \
+       src/cli/lib/image.c \
+       src/cli/lib/image.h \
+       src/cli/lib/image_create.c \
+       src/cli/lib/image_create.h \
        src/cli/lib/info.c \
        src/cli/lib/info.h \
        src/cli/lib/install.h \
diff --git a/src/cli/lib/image.c b/src/cli/lib/image.c
new file mode 100644 (file)
index 0000000..cdc44bd
--- /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 "image.h"
+#include "image_create.h"
+
+int cli_image(struct pakfire* pakfire, int argc, char* argv[]) {
+       static const struct command commands[] = {
+               { "create",  0, cli_image_create },
+               { NULL },
+       };
+
+       return command_dispatch(pakfire, commands, argc, argv);
+}
diff --git a/src/cli/lib/image.h b/src/cli/lib/image.h
new file mode 100644 (file)
index 0000000..7bd5fb5
--- /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_IMAGE_H
+#define PAKFIRE_CLI_IMAGE_H
+
+#include <pakfire/pakfire.h>
+
+int cli_image(struct pakfire* pakfire, int argc, char* argv[]);
+
+#endif /* PAKFIRE_CLI_IMAGE_H */
diff --git a/src/cli/lib/image_create.c b/src/cli/lib/image_create.c
new file mode 100644 (file)
index 0000000..58cc975
--- /dev/null
@@ -0,0 +1,109 @@
+/*#############################################################################
+#                                                                             #
+# 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/build.h>
+#include <pakfire/pakfire.h>
+
+#include "image_create.h"
+
+static void help(void) {
+       printf(
+               "%s [OPTIONS...] image create TYPE PATH...\n\n"
+               "Options:\n"
+               "  -h --help                 Show help\n",
+               program_invocation_short_name
+       );
+
+       exit(0);
+}
+
+static int parse_argv(struct pakfire* pakfire, int argc, char* argv[]) {
+       static const struct option options[] = {
+               { "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 '?':
+                               return -EINVAL;
+
+                       default:
+                               break;
+               }
+       }
+
+       return 0;
+}
+
+int cli_image_create(struct pakfire* pakfire, int argc, char* argv[]) {
+       struct pakfire_build* build = NULL;
+       FILE* f = NULL;
+       int r;
+
+       // Parse commandline
+       r = parse_argv(pakfire, argc, argv);
+       if (r)
+               return r;
+
+       // XXX check arguments
+
+       if (optind >= argc) {
+               fprintf(stderr, "Not enough arguments\n");
+               return 1;
+       }
+
+       f = fopen(argv[2], "w");
+       if (!f) {
+               fprintf(stderr, "Could not open %s: %m\n", argv[2]);
+               r = -errno;
+               goto ERROR;
+       }
+
+       // Setup the build environment
+       r = pakfire_build_create(&build, pakfire, NULL, 0);
+       if (r)
+               goto ERROR;
+
+       // Create the image
+       r = pakfire_build_mkimage(build, argv[1], f);
+       if (r)
+               goto ERROR;
+
+ERROR:
+       if (build)
+               pakfire_build_unref(build);
+       if (f)
+               fclose(f);
+
+       return r;
+}
diff --git a/src/cli/lib/image_create.h b/src/cli/lib/image_create.h
new file mode 100644 (file)
index 0000000..ec139f4
--- /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_IMAGE_CREATE_H
+#define PAKFIRE_CLI_IMAGE_CREATE_H
+
+#include <pakfire/pakfire.h>
+
+int cli_image_create(struct pakfire* pakfire, int argc, char* argv[]);
+
+#endif /* PAKFIRE_CLI_IMAGE_CREATE_H */
index d3d7342ae7be742e6d44b9e02a07ceeb4b67dc84..c84bcfaca047e9909915d5858df656697fc370ef 100644 (file)
@@ -32,6 +32,7 @@
 #include "lib/clean.h"
 #include "lib/command.h"
 #include "lib/dist.h"
+#include "lib/image.h"
 #include "lib/info.h"
 #include "lib/provides.h"
 #include "lib/repo.h"
@@ -61,6 +62,7 @@ static int cli_main(struct pakfire* pakfire, int argc, char* argv[]) {
                { "build",    0, cli_build },
                { "clean",    0, cli_clean },
                { "dist",     0, cli_dist },
+               { "image",    0, cli_image },
                { "info",     0, cli_info },
                { "provides", 0, cli_provides },
                { "repo",     0, cli_repo },