Skip to content

Commit

Permalink
Add: --sysroot and --os arguments
Browse files Browse the repository at this point in the history
These match OSTree.  There are a variety of use cases here.  One is
for test suites; we can stand up a temporary sysroot directory, and
operate on content inside there.

Another is doing virtual machine upgrades offline from a host system,
or upgrading a different OS.

The duplication here is a bit unfortunate; if we add a lot more
commands we should revisit this and perhaps have a common option
group.
  • Loading branch information
cgwalters committed Jul 17, 2014
1 parent f642512 commit 711745b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/rpmostree-builtin-rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@

#include "libgsystem.h"

static char *opt_sysroot = "/";
static char *opt_osname;

static GOptionEntry option_entries[] = {
{ "sysroot", 0, 0, G_OPTION_ARG_STRING, &opt_sysroot, "Use system root SYSROOT (default: /)", "SYSROOT" },
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
{ NULL }
};

Expand All @@ -51,6 +56,7 @@ rpmostree_builtin_rebase (int argc,
gs_free char *new_ref = NULL;
gs_free char *new_refspec = NULL;
gs_free char *new_revision = NULL;
gs_unref_object GFile *sysroot_path = NULL;
gs_unref_object GFile *deployment_path = NULL;
gs_unref_object GFile *deployment_origin_path = NULL;
gs_unref_object OstreeDeployment *merge_deployment = NULL;
Expand All @@ -77,11 +83,12 @@ rpmostree_builtin_rebase (int argc,

new_provided_refspec = argv[1];

sysroot = ostree_sysroot_new_default ();
sysroot_path = g_file_new_for_path (opt_sysroot);
sysroot = ostree_sysroot_new (sysroot_path);
if (!ostree_sysroot_load (sysroot, cancellable, error))
goto out;

upgrader = ostree_sysroot_upgrader_new_for_os (sysroot, NULL,
upgrader = ostree_sysroot_upgrader_new_for_os (sysroot, opt_osname,
cancellable, error);
if (!upgrader)
goto out;
Expand Down
6 changes: 5 additions & 1 deletion src/rpmostree-builtin-rollback.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@

#include "libgsystem.h"

static char *opt_sysroot = "/";
static gboolean opt_reboot;

static GOptionEntry option_entries[] = {
{ "sysroot", 0, 0, G_OPTION_ARG_STRING, &opt_sysroot, "Use system root SYSROOT (default: /)", "SYSROOT" },
{ "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Initiate a reboot after rollback is prepared", NULL },
{ NULL }
};
Expand All @@ -43,6 +45,7 @@ rpmostree_builtin_rollback (int argc,
{
gboolean ret = FALSE;
GOptionContext *context = g_option_context_new ("- Revert to the previously booted tree");
gs_unref_object GFile *sysroot_path = NULL;
gs_unref_object OstreeSysroot *sysroot = NULL;
gs_free char *origin_description = NULL;
gs_unref_ptrarray GPtrArray *deployments = NULL;
Expand All @@ -58,7 +61,8 @@ rpmostree_builtin_rollback (int argc,
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;

sysroot = ostree_sysroot_new_default ();
sysroot_path = g_file_new_for_path (opt_sysroot);
sysroot = ostree_sysroot_new (sysroot_path);
if (!ostree_sysroot_load (sysroot, cancellable, error))
goto out;

Expand Down
6 changes: 5 additions & 1 deletion src/rpmostree-builtin-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@

#include "libgsystem.h"

static char *opt_sysroot = "/";
static gboolean opt_pretty;

static GOptionEntry option_entries[] = {
{ "sysroot", 0, 0, G_OPTION_ARG_STRING, &opt_sysroot, "Use system root SYSROOT (default: /)", "SYSROOT" },
{ "pretty", 'p', 0, G_OPTION_ARG_NONE, &opt_pretty, "Display status in formatted rows", NULL },
{ NULL }
};
Expand All @@ -51,6 +53,7 @@ rpmostree_builtin_status (int argc,
GError **error)
{
gboolean ret = FALSE;
gs_unref_object GFile *sysroot_path = NULL;
gs_unref_object OstreeSysroot *sysroot = NULL;
gs_unref_ptrarray GPtrArray *deployments = NULL; // list of all depoyments
OstreeDeployment *booted_deployment = NULL; // current booted deployment
Expand All @@ -68,7 +71,8 @@ rpmostree_builtin_status (int argc,
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;

sysroot = ostree_sysroot_new_default ();
sysroot_path = g_file_new_for_path (opt_sysroot);
sysroot = ostree_sysroot_new (sysroot_path);
if (!ostree_sysroot_load (sysroot, cancellable, error))
goto out;

Expand Down
11 changes: 9 additions & 2 deletions src/rpmostree-builtin-upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@

#include "libgsystem.h"

static char *opt_sysroot = "/";
static char *opt_osname;
static gboolean opt_reboot;
static gboolean opt_allow_downgrade;

static GOptionEntry option_entries[] = {
{ "sysroot", 0, 0, G_OPTION_ARG_STRING, &opt_sysroot, "Use system root SYSROOT (default: /)", "SYSROOT" },
{ "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Operate on provided OSNAME", "OSNAME" },
{ "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Initiate a reboot after an upgrade is prepared", NULL },
{ "allow-downgrade", 0, 0, G_OPTION_ARG_NONE, &opt_allow_downgrade, "Permit deployment of chronologically older trees", NULL },
{ NULL }
Expand All @@ -46,6 +50,7 @@ rpmostree_builtin_upgrade (int argc,
{
gboolean ret = FALSE;
GOptionContext *context = g_option_context_new ("- Perform a system upgrade");
gs_unref_object GFile *sysroot_path = NULL;
gs_unref_object OstreeSysroot *sysroot = NULL;
gs_unref_object OstreeSysrootUpgrader *upgrader = NULL;
gs_unref_object OstreeAsyncProgress *progress = NULL;
Expand All @@ -59,11 +64,13 @@ rpmostree_builtin_upgrade (int argc,
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;

sysroot = ostree_sysroot_new_default ();
sysroot_path = g_file_new_for_path (opt_sysroot);
sysroot = ostree_sysroot_new (sysroot_path);
if (!ostree_sysroot_load (sysroot, cancellable, error))
goto out;

upgrader = ostree_sysroot_upgrader_new (sysroot, cancellable, error);
upgrader = ostree_sysroot_upgrader_new_for_os (sysroot, opt_osname,
cancellable, error);
if (!upgrader)
goto out;

Expand Down

0 comments on commit 711745b

Please sign in to comment.