From b2f377a00c57ecfc767536f0099fcf9150fc2690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Mon, 30 Mar 2020 21:05:50 +0100 Subject: [PATCH] fu-tool: add reinstall command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1914 Signed-off-by: Filipe LaĆ­ns --- src/fu-tool.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/src/fu-tool.c b/src/fu-tool.c index dce0a6368..9edb07c98 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -1133,6 +1133,74 @@ fu_util_update (FuUtilPrivate *priv, gchar **values, GError **error) return fu_util_prompt_complete (priv->completion_flags, TRUE, error); } +static gboolean +fu_util_reinstall (FuUtilPrivate *priv, gchar **values, GError **error) +{ + g_autoptr(FwupdRelease) rel = NULL; + g_autoptr(GPtrArray) rels = NULL; + g_autoptr(FuDevice) dev = NULL; + + if (g_strv_length (values) != 1) { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_INVALID_ARGS, + "Invalid arguments"); + return FALSE; + } + + if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) + return FALSE; + + dev = fu_engine_get_device (priv->engine, values[0], error); + if (dev == NULL) + return FALSE; + + /* try to lookup/match release from client */ + rels = fu_engine_get_releases_for_device (priv->engine, dev, error); + if (rels == NULL) + return FALSE; + + for (guint j = 0; j < rels->len; j++) { + FwupdRelease *rel_tmp = g_ptr_array_index (rels, j); + if (fu_common_vercmp_full (fwupd_release_get_version (rel_tmp), + fu_device_get_version (dev), + fu_device_get_version_format (dev)) == 0) { + rel = g_object_ref (rel_tmp); + break; + } + } + if (rel == NULL) { + g_set_error (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_SUPPORTED, + "Unable to locate release for %s version %s", + fu_device_get_name (dev), + fu_device_get_version (dev)); + return FALSE; + } + + /* update the console if composite devices are also updated */ + priv->current_operation = FU_UTIL_OPERATION_INSTALL; + g_signal_connect (priv->engine, "device-changed", + G_CALLBACK (fu_util_update_device_changed_cb), priv); + priv->flags |= FWUPD_INSTALL_FLAG_ALLOW_REINSTALL; + if (!fu_util_install_release (priv, rel, error)) + return FALSE; + fu_util_display_current_message (priv); + + /* we don't want to ask anything */ + if (priv->no_reboot_check) { + g_debug ("skipping reboot check"); + return TRUE; + } + + /* save the device state for other applications to see */ + if (!fu_util_save_current_state (priv, error)) + return FALSE; + + return fu_util_prompt_complete (priv->completion_flags, TRUE, error); +} + static gboolean fu_util_detach (FuUtilPrivate *priv, gchar **values, GError **error) { @@ -1982,6 +2050,12 @@ main (int argc, char *argv[]) /* TRANSLATORS: command description */ _("Install a firmware file on this hardware"), fu_util_install); + fu_util_cmd_array_add (cmd_array, + "reinstall", + "DEVICE-ID", + /* TRANSLATORS: command description */ + _("Reinstall firmware on a device"), + fu_util_reinstall); fu_util_cmd_array_add (cmd_array, "attach", "DEVICE-ID",