diff --git a/src/app/rpmostree-builtin-status.c b/src/app/rpmostree-builtin-status.c index 19f6d776..a3b87b4d 100644 --- a/src/app/rpmostree-builtin-status.c +++ b/src/app/rpmostree-builtin-status.c @@ -54,6 +54,7 @@ static gboolean opt_verbose_advisories; static gboolean opt_json; static gboolean opt_only_booted; static const char *opt_jsonpath; +static gboolean opt_pending_exit_77; static GOptionEntry option_entries[] = { { "pretty", 'p', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_pretty, "This option is deprecated and no longer has any effect", NULL }, @@ -62,6 +63,7 @@ static GOptionEntry option_entries[] = { { "json", 0, 0, G_OPTION_ARG_NONE, &opt_json, "Output JSON", NULL }, { "jsonpath", 'J', 0, G_OPTION_ARG_STRING, &opt_jsonpath, "Filter JSONPath expression", "EXPRESSION" }, { "booted", 'b', 0, G_OPTION_ARG_NONE, &opt_only_booted, "Only print the booted deployment", NULL }, + { "pending-exit-77", 'b', 0, G_OPTION_ARG_NONE, &opt_pending_exit_77, "If pending deployment available, exit 77", NULL }, { NULL } }; @@ -1026,5 +1028,18 @@ rpmostree_builtin_status (int argc, } } + if (opt_pending_exit_77) + { + if (g_variant_n_children (deployments) > 1) + { + g_autoptr(GVariant) pending = g_variant_get_child_value (deployments, 0); + g_auto(GVariantDict) dict; + g_variant_dict_init (&dict, pending); + gboolean is_booted; + if (g_variant_dict_lookup (&dict, "booted", "b", &is_booted) && !is_booted) + invocation->exit_code = RPM_OSTREE_EXIT_PENDING; + } + } + return TRUE; } diff --git a/src/app/rpmostree-builtin-types.h b/src/app/rpmostree-builtin-types.h index 9d346f33..cfde72ee 100644 --- a/src/app/rpmostree-builtin-types.h +++ b/src/app/rpmostree-builtin-types.h @@ -28,6 +28,9 @@ G_BEGIN_DECLS * Use alongside EXIT_SUCCESS and EXIT_FAILURE. */ #define RPM_OSTREE_EXIT_UNCHANGED (77) +/* Exit code for when a pending deployment can be rebooted into. */ +#define RPM_OSTREE_EXIT_PENDING (77) + typedef enum { RPM_OSTREE_BUILTIN_FLAG_NONE = 0, RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD = 1 << 0, diff --git a/tests/vmcheck/test-layering-basic-1.sh b/tests/vmcheck/test-layering-basic-1.sh index 32bae52e..0feb0368 100755 --- a/tests/vmcheck/test-layering-basic-1.sh +++ b/tests/vmcheck/test-layering-basic-1.sh @@ -90,13 +90,25 @@ vm_rpmostree db diff --format=diff \ assert_file_has_content_literal 'db-diff.txt' "+foo-1.0-1.x86_64" echo "ok pkg-add foo" -# Test that we don't do progress bars if on a tty (with the client) vm_rpmostree uninstall foo-1.0 + +# Test `rpm-ostree status --pending-exit-77` +rc=0 +vm_rpmostree status --pending-exit-77 || rc=$? +assert_streq $rc 77 + +# Test that we don't do progress bars if on a tty (with the client) vm_rpmostree install foo-1.0 > foo-install.txt assert_file_has_content_literal foo-install.txt 'Checking out packages (1/1) 100%' echo "ok install not on a tty" vm_reboot + +# Test `rpm-ostree status --pending-exit-77`, with no actual pending deployment +rc=0 +vm_rpmostree status --pending-exit-77 || rc=$? +assert_streq $rc 0 + vm_assert_status_jq \ '.deployments[0]["base-checksum"]' \ '.deployments[0]["pending-base-checksum"]|not' \