Skip to content

Commit

Permalink
Merge pull request #3134 from ericcurtin/query-boot-real
Browse files Browse the repository at this point in the history
status: Introduce tool to quickly check if we are booted as default
  • Loading branch information
cgwalters authored Jan 8, 2024
2 parents 87a0aba + 46bae54 commit b79a2e1
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 8 deletions.
59 changes: 59 additions & 0 deletions man/ostree-admin-status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,65 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
</para>
</refsect1>

<refsect1>
<title>Options</title>

<variablelist>
<varlistentry>
<term><option>--sysroot</option>="PATH"</term>

<listitem><para>
Create a new OSTree sysroot at PATH
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>-V, --verify</option></term>

<listitem><para>
Print the commit verification status
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>-S, --skip-signatures</option></term>

<listitem><para>
Skip signatures in output
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>-Q, --query-booted</option></term>

<listitem><para>
Output the string <literal>default</literal> if the default deployment
is the booted one, <literal>not-default</literal> 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.
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>-v, --verbose</option></term>

<listitem><para>
Print debug information during command processing
</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--version</option>--version</term>

<listitem><para>
Print version information and exit
</para></listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1>
<title>Example</title>
<para><command>$ ostree admin status</command></para>
Expand Down
32 changes: 24 additions & 8 deletions src/ostree/ot-admin-builtin-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "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 "
"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,
Expand Down Expand Up @@ -202,7 +210,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");
}
Expand Down

0 comments on commit b79a2e1

Please sign in to comment.