From 4c84f46f4ea6ab7de0f4e93fe30f6440d445e1c6 Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Fri, 5 Jan 2024 15:49:39 +0000 Subject: [PATCH] status: Introduce tool to quickly check if we are booted as default Generally in ostree based systems you would expect to boot into deployment 0, in rollback conditions triggered by greenboot-related rollbacks this might not be the case. This is a tool to detect this. Signed-off-by: Eric Curtin --- src/ostree/ot-admin-builtin-status.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ostree/ot-admin-builtin-status.c b/src/ostree/ot-admin-builtin-status.c index bf94843f26..4f40c9d1ce 100644 --- a/src/ostree/ot-admin-builtin-status.c +++ b/src/ostree/ot-admin-builtin-status.c @@ -30,12 +30,15 @@ static gboolean opt_verify; static gboolean opt_skip_signatures; +static gboolean opt_query_booted; 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, "Print the commit verification status", NULL }, + { "query-booted", 'Q', 0, G_OPTION_ARG_NONE, &opt_query_booted, + "Print whether the default deployment is booted or not", NULL }, { NULL } }; static gboolean deployment_print_status (OstreeSysroot *sysroot, OstreeRepo *repo, OstreeDeployment *deployment, @@ -200,10 +203,16 @@ ot_admin_builtin_status (int argc, char **argv, OstreeCommandInvocation *invocat if (booted_deployment) ostree_sysroot_query_deployments_for (sysroot, NULL, &pending_deployment, &rollback_deployment); - if (deployments->len == 0) + if (opt_query_booted) { - g_print ("No deployments.\n"); + if (deployments->len == 0) + return FALSE; + + const gboolean is_default_booted = deployments->pdata[0] == booted_deployment; + g_print ("%s\n", is_default_booted ? "default" : "not-default"); } + else if (deployments->len == 0) + g_print ("No deployments.\n"); else { for (guint i = 0; i < deployments->len; i++)