From 1397ee2b7a20c73853c8c80be59e20918f922d64 Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Fri, 5 Jan 2024 15:49:39 +0000 Subject: [PATCH 1/3] 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 | 32 +++++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/ostree/ot-admin-builtin-status.c b/src/ostree/ot-admin-builtin-status.c index bf94843f26..d4822793ef 100644 --- a/src/ostree/ot-admin-builtin-status.c +++ b/src/ostree/ot-admin-builtin-status.c @@ -30,13 +30,21 @@ static gboolean opt_verify; static gboolean opt_skip_signatures; - -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 }, - { NULL } }; +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, + "Output the string \"default\" if the default deployment is the booted one, \"not-default\" if " + "we are booted in a non-default deployment (e.g. the user interactively chose a different " + "entry in the bootloader menu, or the bootloader rolled back automatically, etc.). If we are " + "not in a booted OSTree system, an error is returned.", + NULL }, + { NULL } +}; static gboolean deployment_print_status (OstreeSysroot *sysroot, OstreeRepo *repo, OstreeDeployment *deployment, gboolean is_booted, gboolean is_pending, gboolean is_rollback, @@ -200,7 +208,15 @@ 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) + { + if (deployments->len == 0) + return glnx_throw (error, "Not in a booted OSTree system"); + + 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"); } From c13aef97c67864aa80d20b94a34893d1cc7d0f99 Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Fri, 5 Jan 2024 17:08:43 +0000 Subject: [PATCH 2/3] man: Add ostree admin status man page CLI options. Document the various CLI options. Signed-off-by: Eric Curtin --- man/ostree-admin-status.xml | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/man/ostree-admin-status.xml b/man/ostree-admin-status.xml index dde099b00d..cc90312c91 100644 --- a/man/ostree-admin-status.xml +++ b/man/ostree-admin-status.xml @@ -61,6 +61,65 @@ License along with this library. If not, see . + + Options + + + + ="PATH" + + + Create a new OSTree sysroot at PATH + + + + + + + + Print the commit verification status + + + + + + + + Skip signatures in output + + + + + + + + Output the string default if the default deployment + is the booted one, not-default if we are booted in + a non-default deployment (e.g. the user interactively chose a + different entry in the bootloader menu, or the bootloader rolled back + automatically, etc.). If we are not in a booted OSTree system, an + error is returned. + + + + + + + + Print debug information during command processing + + + + + --version + + + Print version information and exit + + + + + Example $ ostree admin status From 46bae54b1dfb7aef7a263391a4d00c41ac9df400 Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Fri, 5 Jan 2024 18:18:22 +0000 Subject: [PATCH 3/3] status: Fix --skip-signatures description It was a copy-paste of another description, rather than it's own. Signed-off-by: Eric Curtin --- src/ostree/ot-admin-builtin-status.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ostree/ot-admin-builtin-status.c b/src/ostree/ot-admin-builtin-status.c index d4822793ef..e867cb8667 100644 --- a/src/ostree/ot-admin-builtin-status.c +++ b/src/ostree/ot-admin-builtin-status.c @@ -35,8 +35,8 @@ 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 }, + { "skip-signatures", 'S', 0, G_OPTION_ARG_NONE, &opt_skip_signatures, "Skip signatures in output", + NULL }, { "query-booted", 'Q', 0, G_OPTION_ARG_NONE, &opt_query_booted, "Output the string \"default\" if the default deployment is the booted one, \"not-default\" if " "we are booted in a non-default deployment (e.g. the user interactively chose a different "