Skip to content

Commit

Permalink
app: add temp test command, note, this is mainly for testing
Browse files Browse the repository at this point in the history
As tilte. This adds a 'temp-convert' command to rpm-ostree.
The main goal of this command is to convert the AH's
/usr/lib/passwd and /usr/lib/group for testing purposes.

This can be useful to find whether your output for conversion
is correct when testing on real-world entries
  • Loading branch information
peterbaouoft committed Jun 29, 2018
1 parent b9aefd9 commit ec396b6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile-rpm-ostree.am
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ rpm_ostree_SOURCES = src/app/main.c \
src/app/rpmostree-polkit-agent.c \
src/app/rpmostree-polkit-agent.h \
src/app/rpmostree-builtin-kargs.c \
$(NULL)
src/app/rpmostree-builtin-temp-convert.c \
$(NULL)

if BUILDOPT_COMPOSE_TOOLING
rpm_ostree_SOURCES += \
Expand Down
3 changes: 3 additions & 0 deletions src/app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ static RpmOstreeCommand commands[] = {
{ "refresh-md", 0,
"Generate rpm repo metadata",
rpmostree_builtin_refresh_md },
{ "temp-convert", RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
"temp command to convert passwd/group conversion",
rpmostree_builtin_temp_convert },
/* Legacy aliases */
{ "pkg-add", RPM_OSTREE_BUILTIN_FLAG_HIDDEN,
NULL, rpmostree_builtin_install },
Expand Down
53 changes: 53 additions & 0 deletions src/app/rpmostree-builtin-temp-convert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "config.h"
#include "libglnx.h"
#include "rpmostree-util.h"
#include "rpmostree-json-parsing.h"
#include "rpmostree-passwd-util.h"
#include "rpmostree-builtins.h"

static char *opt_conversion_location;


static GOptionEntry conversion_option_entries[] = {
{ "conversion_dir", 0, 0, G_OPTION_ARG_STRING, &opt_conversion_location, "Directory to convert", "CONVERSION_DIR"},
{ NULL }
};

// Temporarily take one argument --> mainly to convert the entries from /usr/lib/passwd into
// entries into sysusers.d
gboolean rpmostree_builtin_temp_convert (int argc,
char **argv,
RpmOstreeCommandInvocation *invocation,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GOptionContext) context = g_option_context_new ("");
if (!rpmostree_option_context_parse (context,
conversion_option_entries,
&argc, &argv,
invocation,
cancellable,
NULL, NULL, NULL, NULL, NULL, error))
return FALSE;
g_print("Hi, this is a test\n");

/* Test the output for conversion, right now we can already convert the content into one string conten. The next step would just be to write a function to write sysusers entries to a new place */
const char* passwd_content = glnx_file_get_contents_utf8_at (AT_FDCWD, "/usr/lib/passwd", NULL, cancellable, error);
const char* group_content = glnx_file_get_contents_utf8_at (AT_FDCWD, "/usr/lib/group", NULL, cancellable, error);

g_print ("%s\n", passwd_content);
g_print ("%s\n", group_content);
// g_autoptr(GPtrArray) converted_ents =
g_autoptr(GPtrArray) passwd_ents = rpmostree_passwd_data2passwdents (passwd_content);
g_autoptr(GPtrArray) group_ents = rpmostree_passwd_data2groupents (group_content);
g_autoptr(GPtrArray) sysusers_entries = NULL;
rpmostree_passwdents2sysusers (passwd_ents, &sysusers_entries, error);
rpmostree_groupents2sysusers (group_ents, &sysusers_entries, error);

g_autofree char* sysuser_converted_content = NULL;
rpmostree_passwd_sysusers2char (sysusers_entries, &sysuser_converted_content, error);

g_print("%s", sysuser_converted_content);

return TRUE;
}
1 change: 1 addition & 0 deletions src/app/rpmostree-builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ BUILTINPROTO(uninstall);
BUILTINPROTO(override);
BUILTINPROTO(start_daemon);
BUILTINPROTO(ex);
BUILTINPROTO(temp_convert);

#undef BUILTINPROTO

Expand Down

0 comments on commit ec396b6

Please sign in to comment.