Skip to content

Commit

Permalink
Add new commands to output the current, staged and previous deploymen…
Browse files Browse the repository at this point in the history
…t for use in automation and scripting.

Right now, it's difficult to pin the current deployment without needing to look into the output of some other tooling (like rpm-ostree) to get the index of each deployment.  This index also is not consistent - the current deployment could be 0 when you first boot the system then 1 shortly after.
This change makes it easy to get the index of the current or future deployment so it can be piped into other commands (such as ostree admin pin).

Huge thanks to Eric for authoring this patch for me!

Co-authored-by: Eric Curtin [email protected]

Signed-off-by: Robert Sturla <[email protected]>
  • Loading branch information
p5 committed Jan 22, 2024
1 parent d1d8f4a commit e4917f1
Showing 1 changed file with 60 additions and 9 deletions.
69 changes: 60 additions & 9 deletions src/ostree/ot-admin-builtin-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,25 @@
static gboolean opt_verify;
static gboolean opt_skip_signatures;
static gboolean opt_is_default;
static gboolean opt_booted_index;
static gboolean opt_pending_index;
static gboolean opt_rollback_index;

static GOptionEntry options[]
= { { "verify", 'V', 0, G_OPTION_ARG_NONE, &opt_verify, "Print the commit verification status",
NULL },
{ "skip-signatures", 'S', 0, G_OPTION_ARG_NONE, &opt_skip_signatures,
"Skip signatures in output", NULL },
{ "is-default", 'D', 0, G_OPTION_ARG_NONE, &opt_is_default,
"Output \"default\" if booted into the default deployment, otherwise \"not-default\"",
NULL },
{ NULL } };
static GOptionEntry options[] = {
{ "verify", 'V', 0, G_OPTION_ARG_NONE, &opt_verify, "Print the commit verification status",
NULL },
{ "skip-signatures", 'S', 0, G_OPTION_ARG_NONE, &opt_skip_signatures, "Skip signatures in output",
NULL },
{ "is-default", 'D', 0, G_OPTION_ARG_NONE, &opt_is_default,
"Output \"default\" if booted into the default deployment, otherwise \"not-default\"", NULL },
{ "booted-index", 'b', 0, G_OPTION_ARG_NONE, &opt_booted_index,
"Output \"default\" if booted into the default deployment, otherwise \"not-default\"", NULL },
{ "pending-index", 'p', 0, G_OPTION_ARG_NONE, &opt_pending_index,
"Output \"default\" if booted into the default deployment, otherwise \"not-default\"", NULL },
{ "rollback-index", 'r', 0, G_OPTION_ARG_NONE, &opt_rollback_index,
"Output \"default\" if booted into the default deployment, otherwise \"not-default\"", NULL },
{ NULL }
};
static gboolean
deployment_print_status (OstreeSysroot *sysroot, OstreeRepo *repo, OstreeDeployment *deployment,
gboolean is_booted, gboolean is_pending, gboolean is_rollback,
Expand Down Expand Up @@ -218,6 +227,48 @@ ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocat
{
g_print ("No deployments.\n");
}
else if (opt_booted_index)
{
for (guint i = 0; i < deployments->len; ++i)
{
OstreeDeployment *deployment = deployments->pdata[i];
if (deployment == booted_deployment)
{
g_print ("%d\n", i);
return TRUE;
}
}

return FALSE;
}
else if (opt_pending_index)
{
for (guint i = 0; i < deployments->len; ++i)
{
OstreeDeployment *deployment = deployments->pdata[i];
if (deployment == pending_deployment)
{
g_print ("%d\n", i);
return TRUE;
}
}

return FALSE;
}
else if (opt_rollback_index)
{
for (guint i = 0; i < deployments->len; ++i)
{
OstreeDeployment *deployment = deployments->pdata[i];
if (deployment == rollback_deployment)
{
g_print ("%d\n", i);
return TRUE;
}
}

return FALSE;
}
else
{
for (guint i = 0; i < deployments->len; i++)
Expand Down

0 comments on commit e4917f1

Please sign in to comment.