From 902d945f4f91b755d6cc3f111d2f090cc75f6fe4 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 13 Dec 2016 11:35:06 +0100 Subject: [PATCH] install/update: Support -y to avoid interaction (for automation) This assumes the answer to any question is yes (or to pick the most prioritized answer). Fixes https://github.com/flatpak/flatpak/issues/436 --- app/flatpak-builtins-install.c | 16 +++++++++++----- app/flatpak-builtins-update.c | 4 +++- app/flatpak-transaction.c | 14 +++++++++++--- app/flatpak-transaction.h | 1 + 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/flatpak-builtins-install.c b/app/flatpak-builtins-install.c index 6ccf467b1..42a3fbe23 100644 --- a/app/flatpak-builtins-install.c +++ b/app/flatpak-builtins-install.c @@ -50,6 +50,7 @@ static gboolean opt_app; static gboolean opt_bundle; static gboolean opt_from; static gboolean opt_oci; +static gboolean opt_yes; static GOptionEntry options[] = { { "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, N_("Arch to install for"), N_("ARCH") }, @@ -64,6 +65,7 @@ static GOptionEntry options[] = { { "oci", 0, 0, G_OPTION_ARG_NONE, &opt_oci, N_("Assume LOCATION is an oci registry"), NULL }, { "gpg-file", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_gpg_file, N_("Check bundle signatures with GPG key from FILE (- for stdin)"), N_("FILE") }, { "subpath", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_subpaths, N_("Only install this subpath"), N_("PATH") }, + { "assumeyes", 'y', 0, G_OPTION_ARG_NONE, &opt_yes, N_("OAutomatically answer yes for all questions"), NULL }, { NULL } }; @@ -226,10 +228,14 @@ handle_runtime_repo_deps (FlatpakDir *dir, GBytes *data, GError **error) if (old_remote != NULL) return TRUE; - if (flatpak_yes_no_prompt (_("This application depends on runtimes from:\n %s\nConfigure this as new remote '%s'"), + if (opt_yes || + flatpak_yes_no_prompt (_("This application depends on runtimes from:\n %s\nConfigure this as new remote '%s'"), runtime_url, new_remote)) { - if (!flatpak_dir_modify_remote (dir, new_remote, config, gpg_key, NULL, error)) + if (opt_yes) + g_print (_("Configuring %s as new remote '%s'"), runtime_url, new_remote); + + if (!flatpak_dir_modify_remote (dir, new_remote, config, gpg_key, NULL, error)) return FALSE; if (!flatpak_dir_recreate_repo (dir, NULL, error)) return FALSE; @@ -299,7 +305,7 @@ install_from (FlatpakDir *dir, slash = strchr (ref, '/'); g_print (_("Installing: %s\n"), slash + 1); - transaction = flatpak_transaction_new (clone, opt_no_pull, opt_no_deploy, + transaction = flatpak_transaction_new (clone, opt_yes, opt_no_pull, opt_no_deploy, !opt_no_deps, !opt_no_related); if (!flatpak_transaction_add_install (transaction, remote, ref, (const char **)opt_subpaths, error)) @@ -338,7 +344,7 @@ install_oci (FlatpakDir *dir, registry_file = g_file_new_for_commandline_arg (registry_arg); registry_uri = g_file_get_uri (registry_file); - transaction = flatpak_transaction_new (dir, opt_no_pull, opt_no_deploy, + transaction = flatpak_transaction_new (dir, opt_yes, opt_no_pull, opt_no_deploy, !opt_no_deps, !opt_no_related); for (i = 0; tags[i] != NULL; i++) @@ -406,7 +412,7 @@ flatpak_builtin_install (int argc, char **argv, GCancellable *cancellable, GErro default_branch = flatpak_dir_get_remote_default_branch (dir, remote); kinds = flatpak_kinds_from_bools (opt_app, opt_runtime); - transaction = flatpak_transaction_new (dir, opt_no_pull, opt_no_deploy, + transaction = flatpak_transaction_new (dir, opt_yes, opt_no_pull, opt_no_deploy, !opt_no_deps, !opt_no_related); for (i = 0; i < n_prefs; i++) diff --git a/app/flatpak-builtins-update.c b/app/flatpak-builtins-update.c index d32c061c2..770c78062 100644 --- a/app/flatpak-builtins-update.c +++ b/app/flatpak-builtins-update.c @@ -46,6 +46,7 @@ static gboolean opt_no_deps; static gboolean opt_runtime; static gboolean opt_app; static gboolean opt_appstream; +static gboolean opt_yes; static GOptionEntry options[] = { { "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, N_("Arch to update for"), N_("ARCH") }, @@ -59,6 +60,7 @@ static GOptionEntry options[] = { { "app", 0, 0, G_OPTION_ARG_NONE, &opt_app, N_("Look for app with the specified name"), NULL }, { "appstream", 0, 0, G_OPTION_ARG_NONE, &opt_appstream, N_("Update appstream for remote"), NULL }, { "subpath", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_subpaths, N_("Only update this subpath"), N_("PATH") }, + { "assumeyes", 'y', 0, G_OPTION_ARG_NONE, &opt_yes, N_("OAutomatically answer yes for all questions"), NULL }, { NULL } }; @@ -135,7 +137,7 @@ flatpak_builtin_update (int argc, n_prefs = 1; } - transaction = flatpak_transaction_new (dir, opt_no_pull, opt_no_deploy, + transaction = flatpak_transaction_new (dir, opt_yes, opt_no_pull, opt_no_deploy, !opt_no_deps, !opt_no_related); kinds = flatpak_kinds_from_bools (opt_app, opt_runtime); diff --git a/app/flatpak-transaction.c b/app/flatpak-transaction.c index 1fcc7a7f2..c76ff87ef 100644 --- a/app/flatpak-transaction.c +++ b/app/flatpak-transaction.c @@ -45,6 +45,7 @@ struct FlatpakTransaction { GHashTable *refs; GList *ops; + gboolean no_interaction; gboolean no_pull; gboolean no_deploy; gboolean add_deps; @@ -146,6 +147,7 @@ flatpak_transaction_operation_free (FlatpakTransactionOp *self) FlatpakTransaction * flatpak_transaction_new (FlatpakDir *dir, + gboolean no_interaction, gboolean no_pull, gboolean no_deploy, gboolean add_deps, @@ -156,6 +158,7 @@ flatpak_transaction_new (FlatpakDir *dir, t->dir = g_object_ref (dir); t->refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + t->no_interaction = no_interaction; t->no_pull = no_pull; t->no_deploy = no_deploy; t->add_deps = add_deps; @@ -259,13 +262,18 @@ flatpak_transaction_add_op (FlatpakTransaction *self, } static char * -ask_for_remote (const char **remotes) +ask_for_remote (FlatpakTransaction *self, const char **remotes) { int n_remotes = g_strv_length ((char **)remotes); int chosen = 0; int i; - if (n_remotes == 1) + if (self->no_interaction) + { + chosen = 1; + g_print ("Found in remote %s\n", remotes[0]); + } + else if (n_remotes == 1) { if (flatpak_yes_no_prompt (_("Found in remote %s, do you want to install it?"), remotes[0])) chosen = 1; @@ -364,7 +372,7 @@ add_deps (FlatpakTransaction *self, } else { - runtime_remote = ask_for_remote ((const char **)remotes); + runtime_remote = ask_for_remote (self, (const char **)remotes); } if (runtime_remote == NULL) diff --git a/app/flatpak-transaction.h b/app/flatpak-transaction.h index 6f5488142..2eb811063 100644 --- a/app/flatpak-transaction.h +++ b/app/flatpak-transaction.h @@ -29,6 +29,7 @@ typedef struct FlatpakTransaction FlatpakTransaction; FlatpakTransaction *flatpak_transaction_new (FlatpakDir *dir, + gboolean no_interaction, gboolean no_pull, gboolean no_deploy, gboolean add_deps,