fu-tool: add reinstall command

Closes #1914

Signed-off-by: Filipe Laíns <lains@archlinux.org>
This commit is contained in:
Filipe Laíns 2020-03-30 21:05:50 +01:00 committed by Richard Hughes
parent d3a4fd3e1c
commit b2f377a00c

View File

@ -1133,6 +1133,74 @@ fu_util_update (FuUtilPrivate *priv, gchar **values, GError **error)
return fu_util_prompt_complete (priv->completion_flags, TRUE, 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 static gboolean
fu_util_detach (FuUtilPrivate *priv, gchar **values, GError **error) fu_util_detach (FuUtilPrivate *priv, gchar **values, GError **error)
{ {
@ -1982,6 +2050,12 @@ main (int argc, char *argv[])
/* TRANSLATORS: command description */ /* TRANSLATORS: command description */
_("Install a firmware file on this hardware"), _("Install a firmware file on this hardware"),
fu_util_install); 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, fu_util_cmd_array_add (cmd_array,
"attach", "attach",
"DEVICE-ID", "DEVICE-ID",