Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alias to pin current deployment #3142

Closed
p5 opened this issue Jan 21, 2024 · 4 comments
Closed

Alias to pin current deployment #3142

p5 opened this issue Jan 21, 2024 · 4 comments

Comments

@p5
Copy link
Contributor

p5 commented Jan 21, 2024

It would be good if there was a quick and easy way to pin the current deployment without needing to rely on multiple commands:

  • rpm-ostree status -v - to find out which index the current deployed system is
    • It changes from 0 to 1 when there's an update staged
  • ostree admin pin <index> - to actually pin the deployment

It would be great if there was a simple alias called current (or whatever you feel makes the most sense) which points to the deployed index.
This could also be extended to include keywords like previous or staged, but I see less reason for this to be used.

Therefore, the user could run ostree admin pin current and be done with it.

@ericcurtin
Copy link
Collaborator

ericcurtin commented Jan 21, 2024

This request is similar to recently merged pull requests:

#3134
#3136

It would not be that hard to open another PR to introduce a:

ostree admin status --booted-index

option. Then you could just do:

ostree admin pin $(ostree admin status --booted-index)

@ericcurtin
Copy link
Collaborator

Feel free to run with this and contribute it back @p5

We will need to also update man pages, help info (the help info is wrong in the below code).

We could also de-deplicate those three for loop sections into a single function that takes either booted_deployment, pending_deployment, rollback_deployment as a pointer.

Just add a:

Co-authored-by: Eric Curtin ecurtin@redhat.com

tag in the commit/PR.

diff --git a/src/ostree/ot-admin-builtin-status.c b/src/ostree/ot-admin-builtin-status.c
index d05d9928..fe4577c9 100644
--- a/src/ostree/ot-admin-builtin-status.c
+++ b/src/ostree/ot-admin-builtin-status.c
@@ -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,
@@ -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++)

@ericcurtin
Copy link
Collaborator

This can be closed with:

#3146

@ericcurtin
Copy link
Collaborator

ostree admin pin current is implemented as ostree admin pin booted to align with other namings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants