Richard Hughes | 02c90d8 | 2018-08-09 12:13:03 +0100 | [diff] [blame] | 1 | /* |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2 | * Copyright (C) 2015-2018 Richard Hughes <richard@hughsie.com> |
| 3 | * |
Mario Limonciello | 51308e6 | 2018-05-28 20:05:46 -0500 | [diff] [blame] | 4 | * SPDX-License-Identifier: LGPL-2.1+ |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Richard Hughes | b08e7bc | 2018-09-11 10:51:13 +0100 | [diff] [blame] | 7 | #define G_LOG_DOMAIN "FuMain" |
| 8 | |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 9 | #include "config.h" |
| 10 | |
| 11 | #include <fwupd.h> |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 12 | #include <glib/gstdio.h> |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 13 | #include <glib/gi18n.h> |
Richard Hughes | 9e5675e | 2019-11-22 09:35:03 +0000 | [diff] [blame] | 14 | #ifdef HAVE_GIO_UNIX |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 15 | #include <glib-unix.h> |
Richard Hughes | 9e5675e | 2019-11-22 09:35:03 +0000 | [diff] [blame] | 16 | #endif |
Richard Hughes | 7d82a09 | 2019-11-22 09:42:31 +0000 | [diff] [blame] | 17 | #include <fcntl.h> |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 18 | #include <locale.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <unistd.h> |
Richard Hughes | 3d178be | 2018-08-30 11:14:24 +0100 | [diff] [blame] | 21 | #include <libsoup/soup.h> |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 22 | #include <jcat.h> |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 23 | |
Mario Limonciello | 7a3df4b | 2019-01-31 10:27:22 -0600 | [diff] [blame] | 24 | #include "fu-device-private.h" |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 25 | #include "fu-engine.h" |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 26 | #include "fu-history.h" |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 27 | #include "fu-plugin-private.h" |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 28 | #include "fu-progressbar.h" |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame^] | 29 | #include "fu-security-attrs-private.h" |
Mario Limonciello | 6b0e663 | 2019-11-22 13:04:32 -0600 | [diff] [blame] | 30 | #include "fu-smbios-private.h" |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 31 | #include "fu-util-common.h" |
Mario Limonciello | fde4773 | 2018-09-11 12:20:58 -0500 | [diff] [blame] | 32 | #include "fu-debug.h" |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 33 | #include "fwupd-common-private.h" |
Mario Limonciello | 3143bad | 2019-02-27 07:31:00 -0600 | [diff] [blame] | 34 | #include "fwupd-device-private.h" |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 35 | |
Richard Hughes | 3d00522 | 2019-05-17 14:02:41 +0100 | [diff] [blame] | 36 | #ifdef HAVE_SYSTEMD |
| 37 | #include "fu-systemd.h" |
| 38 | #endif |
| 39 | |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 40 | /* custom return code */ |
| 41 | #define EXIT_NOTHING_TO_DO 2 |
| 42 | |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 43 | typedef enum { |
| 44 | FU_UTIL_OPERATION_UNKNOWN, |
| 45 | FU_UTIL_OPERATION_UPDATE, |
| 46 | FU_UTIL_OPERATION_INSTALL, |
Richard Hughes | a58510b | 2019-10-30 10:03:12 +0000 | [diff] [blame] | 47 | FU_UTIL_OPERATION_READ, |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 48 | FU_UTIL_OPERATION_LAST |
| 49 | } FuUtilOperation; |
| 50 | |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 51 | struct FuUtilPrivate { |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 52 | GCancellable *cancellable; |
| 53 | GMainLoop *loop; |
| 54 | GOptionContext *context; |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 55 | FuEngine *engine; |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 56 | FuProgressbar *progressbar; |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 57 | gboolean no_reboot_check; |
Mario Limonciello | 98b9516 | 2019-10-30 09:20:43 -0500 | [diff] [blame] | 58 | gboolean no_safety_check; |
Mario Limonciello | 53ce25d | 2019-02-01 16:09:03 +0000 | [diff] [blame] | 59 | gboolean prepare_blob; |
| 60 | gboolean cleanup_blob; |
Mario Limonciello | 3143bad | 2019-02-27 07:31:00 -0600 | [diff] [blame] | 61 | gboolean enable_json_state; |
Richard Hughes | 460226a | 2018-05-21 20:56:21 +0100 | [diff] [blame] | 62 | FwupdInstallFlags flags; |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 63 | gboolean show_all_devices; |
Richard Hughes | 0e46b22 | 2019-09-05 12:13:35 +0100 | [diff] [blame] | 64 | gboolean disable_ssl_strict; |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 65 | /* only valid in update and downgrade */ |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 66 | FuUtilOperation current_operation; |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 67 | FwupdDevice *current_device; |
Mario Limonciello | 32241f4 | 2019-01-24 10:12:41 -0600 | [diff] [blame] | 68 | gchar *current_message; |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 69 | FwupdDeviceFlags completion_flags; |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 70 | FwupdDeviceFlags filter_include; |
| 71 | FwupdDeviceFlags filter_exclude; |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 72 | }; |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 73 | |
Mario Limonciello | e61c94d | 2018-10-11 10:49:55 -0500 | [diff] [blame] | 74 | static gboolean |
Mario Limonciello | 3143bad | 2019-02-27 07:31:00 -0600 | [diff] [blame] | 75 | fu_util_save_current_state (FuUtilPrivate *priv, GError **error) |
| 76 | { |
| 77 | g_autoptr(JsonBuilder) builder = NULL; |
| 78 | g_autoptr(JsonGenerator) json_generator = NULL; |
| 79 | g_autoptr(JsonNode) json_root = NULL; |
| 80 | g_autoptr(GPtrArray) devices = NULL; |
| 81 | g_autofree gchar *state = NULL; |
| 82 | g_autofree gchar *dirname = NULL; |
| 83 | g_autofree gchar *filename = NULL; |
| 84 | |
| 85 | if (!priv->enable_json_state) |
| 86 | return TRUE; |
| 87 | |
| 88 | devices = fu_engine_get_devices (priv->engine, error); |
| 89 | if (devices == NULL) |
| 90 | return FALSE; |
Richard Hughes | 0ef4720 | 2020-01-06 13:59:09 +0000 | [diff] [blame] | 91 | fwupd_device_array_ensure_parents (devices); |
Mario Limonciello | 3143bad | 2019-02-27 07:31:00 -0600 | [diff] [blame] | 92 | |
| 93 | /* create header */ |
| 94 | builder = json_builder_new (); |
| 95 | json_builder_begin_object (builder); |
| 96 | |
| 97 | /* add each device */ |
| 98 | json_builder_set_member_name (builder, "Devices"); |
| 99 | json_builder_begin_array (builder); |
| 100 | for (guint i = 0; i < devices->len; i++) { |
| 101 | FwupdDevice *dev = g_ptr_array_index (devices, i); |
| 102 | json_builder_begin_object (builder); |
| 103 | fwupd_device_to_json (dev, builder); |
| 104 | json_builder_end_object (builder); |
| 105 | } |
| 106 | json_builder_end_array (builder); |
| 107 | json_builder_end_object (builder); |
| 108 | |
| 109 | /* export as a string */ |
| 110 | json_root = json_builder_get_root (builder); |
| 111 | json_generator = json_generator_new (); |
| 112 | json_generator_set_pretty (json_generator, TRUE); |
| 113 | json_generator_set_root (json_generator, json_root); |
| 114 | state = json_generator_to_data (json_generator, NULL); |
| 115 | if (state == NULL) |
| 116 | return FALSE; |
| 117 | dirname = fu_common_get_path (FU_PATH_KIND_LOCALSTATEDIR_PKG); |
| 118 | filename = g_build_filename (dirname, "state.json", NULL); |
| 119 | return g_file_set_contents (filename, state, -1, error); |
| 120 | } |
| 121 | |
| 122 | static gboolean |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 123 | fu_util_start_engine (FuUtilPrivate *priv, FuEngineLoadFlags flags, GError **error) |
Mario Limonciello | e8dd4d7 | 2019-02-26 15:28:04 -0600 | [diff] [blame] | 124 | { |
| 125 | g_autoptr(GError) error_local = NULL; |
| 126 | |
Richard Hughes | d92ccca | 2019-05-20 11:28:31 +0100 | [diff] [blame] | 127 | #ifdef HAVE_SYSTEMD |
Richard Hughes | 3d00522 | 2019-05-17 14:02:41 +0100 | [diff] [blame] | 128 | if (!fu_systemd_unit_stop (fu_util_get_systemd_unit (), &error_local)) |
Mario Limonciello | 8692d01 | 2019-10-12 18:01:55 -0500 | [diff] [blame] | 129 | g_debug ("Failed to stop daemon: %s", error_local->message); |
Richard Hughes | d92ccca | 2019-05-20 11:28:31 +0100 | [diff] [blame] | 130 | #endif |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 131 | if (!fu_engine_load (priv->engine, flags, error)) |
Richard Hughes | f425d29 | 2019-01-18 17:57:39 +0000 | [diff] [blame] | 132 | return FALSE; |
| 133 | if (fu_engine_get_tainted (priv->engine)) { |
| 134 | g_printerr ("WARNING: This tool has loaded 3rd party code and " |
| 135 | "is no longer supported by the upstream developers!\n"); |
| 136 | } |
| 137 | return TRUE; |
Mario Limonciello | e61c94d | 2018-10-11 10:49:55 -0500 | [diff] [blame] | 138 | } |
| 139 | |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 140 | static void |
Mario Limonciello | b72aa8c | 2018-06-08 09:24:36 -0500 | [diff] [blame] | 141 | fu_util_maybe_prefix_sandbox_error (const gchar *value, GError **error) |
| 142 | { |
| 143 | g_autofree gchar *path = g_path_get_dirname (value); |
| 144 | if (!g_file_test (path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { |
| 145 | g_prefix_error (error, |
| 146 | "Unable to access %s. You may need to copy %s to %s: ", |
| 147 | path, value, g_getenv ("HOME")); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | static void |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 152 | fu_util_cancelled_cb (GCancellable *cancellable, gpointer user_data) |
| 153 | { |
| 154 | FuUtilPrivate *priv = (FuUtilPrivate *) user_data; |
| 155 | /* TRANSLATORS: this is when a device ctrl+c's a watch */ |
| 156 | g_print ("%s\n", _("Cancelled")); |
| 157 | g_main_loop_quit (priv->loop); |
| 158 | } |
| 159 | |
| 160 | static gboolean |
| 161 | fu_util_smbios_dump (FuUtilPrivate *priv, gchar **values, GError **error) |
| 162 | { |
| 163 | g_autofree gchar *tmp = NULL; |
| 164 | g_autoptr(FuSmbios) smbios = NULL; |
| 165 | if (g_strv_length (values) < 1) { |
| 166 | g_set_error_literal (error, |
| 167 | FWUPD_ERROR, |
| 168 | FWUPD_ERROR_INVALID_ARGS, |
| 169 | "Invalid arguments"); |
| 170 | return FALSE; |
| 171 | } |
| 172 | smbios = fu_smbios_new (); |
| 173 | if (!fu_smbios_setup_from_file (smbios, values[0], error)) |
| 174 | return FALSE; |
| 175 | tmp = fu_smbios_to_string (smbios); |
| 176 | g_print ("%s\n", tmp); |
| 177 | return TRUE; |
| 178 | } |
| 179 | |
Richard Hughes | 9e5675e | 2019-11-22 09:35:03 +0000 | [diff] [blame] | 180 | #ifdef HAVE_GIO_UNIX |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 181 | static gboolean |
| 182 | fu_util_sigint_cb (gpointer user_data) |
| 183 | { |
| 184 | FuUtilPrivate *priv = (FuUtilPrivate *) user_data; |
| 185 | g_debug ("Handling SIGINT"); |
| 186 | g_cancellable_cancel (priv->cancellable); |
| 187 | return FALSE; |
| 188 | } |
Richard Hughes | 9e5675e | 2019-11-22 09:35:03 +0000 | [diff] [blame] | 189 | #endif |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 190 | |
| 191 | static void |
| 192 | fu_util_private_free (FuUtilPrivate *priv) |
| 193 | { |
Mario Limonciello | cc50e1a | 2018-08-14 17:45:24 -0500 | [diff] [blame] | 194 | if (priv->current_device != NULL) |
| 195 | g_object_unref (priv->current_device); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 196 | if (priv->engine != NULL) |
| 197 | g_object_unref (priv->engine); |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 198 | if (priv->loop != NULL) |
| 199 | g_main_loop_unref (priv->loop); |
| 200 | if (priv->cancellable != NULL) |
| 201 | g_object_unref (priv->cancellable); |
| 202 | if (priv->progressbar != NULL) |
| 203 | g_object_unref (priv->progressbar); |
| 204 | if (priv->context != NULL) |
| 205 | g_option_context_free (priv->context); |
Mario Limonciello | 32241f4 | 2019-01-24 10:12:41 -0600 | [diff] [blame] | 206 | g_free (priv->current_message); |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 207 | g_free (priv); |
| 208 | } |
| 209 | |
| 210 | #pragma clang diagnostic push |
| 211 | #pragma clang diagnostic ignored "-Wunused-function" |
| 212 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(FuUtilPrivate, fu_util_private_free) |
| 213 | #pragma clang diagnostic pop |
| 214 | |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 215 | |
| 216 | static void |
| 217 | fu_main_engine_device_added_cb (FuEngine *engine, |
| 218 | FuDevice *device, |
| 219 | FuUtilPrivate *priv) |
| 220 | { |
| 221 | g_autofree gchar *tmp = fu_device_to_string (device); |
| 222 | g_debug ("ADDED:\n%s", tmp); |
| 223 | } |
| 224 | |
| 225 | static void |
| 226 | fu_main_engine_device_removed_cb (FuEngine *engine, |
| 227 | FuDevice *device, |
| 228 | FuUtilPrivate *priv) |
| 229 | { |
| 230 | g_autofree gchar *tmp = fu_device_to_string (device); |
| 231 | g_debug ("REMOVED:\n%s", tmp); |
| 232 | } |
| 233 | |
| 234 | static void |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 235 | fu_main_engine_status_changed_cb (FuEngine *engine, |
| 236 | FwupdStatus status, |
| 237 | FuUtilPrivate *priv) |
| 238 | { |
| 239 | fu_progressbar_update (priv->progressbar, status, 0); |
| 240 | } |
| 241 | |
| 242 | static void |
| 243 | fu_main_engine_percentage_changed_cb (FuEngine *engine, |
| 244 | guint percentage, |
| 245 | FuUtilPrivate *priv) |
| 246 | { |
| 247 | fu_progressbar_update (priv->progressbar, FWUPD_STATUS_UNKNOWN, percentage); |
| 248 | } |
| 249 | |
| 250 | static gboolean |
| 251 | fu_util_watch (FuUtilPrivate *priv, gchar **values, GError **error) |
| 252 | { |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 253 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 254 | return FALSE; |
| 255 | g_main_loop_run (priv->loop); |
| 256 | return TRUE; |
| 257 | } |
| 258 | |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 259 | static gint |
| 260 | fu_util_plugin_name_sort_cb (FuPlugin **item1, FuPlugin **item2) |
| 261 | { |
| 262 | return fu_plugin_name_compare (*item1, *item2); |
| 263 | } |
| 264 | |
| 265 | static gboolean |
| 266 | fu_util_get_plugins (FuUtilPrivate *priv, gchar **values, GError **error) |
| 267 | { |
| 268 | GPtrArray *plugins; |
| 269 | guint cnt = 0; |
| 270 | |
| 271 | /* load engine */ |
| 272 | if (!fu_engine_load_plugins (priv->engine, error)) |
| 273 | return FALSE; |
| 274 | |
| 275 | /* print */ |
| 276 | plugins = fu_engine_get_plugins (priv->engine); |
| 277 | g_ptr_array_sort (plugins, (GCompareFunc) fu_util_plugin_name_sort_cb); |
| 278 | for (guint i = 0; i < plugins->len; i++) { |
| 279 | FuPlugin *plugin = g_ptr_array_index (plugins, i); |
| 280 | if (!fu_plugin_get_enabled (plugin)) |
| 281 | continue; |
| 282 | g_print ("%s\n", fu_plugin_get_name (plugin)); |
| 283 | cnt++; |
| 284 | } |
| 285 | if (cnt == 0) { |
| 286 | /* TRANSLATORS: nothing found */ |
| 287 | g_print ("%s\n", _("No plugins found")); |
| 288 | return TRUE; |
| 289 | } |
| 290 | |
| 291 | return TRUE; |
| 292 | } |
| 293 | |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 294 | static gboolean |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 295 | fu_util_filter_device (FuUtilPrivate *priv, FwupdDevice *dev) |
| 296 | { |
| 297 | if (priv->filter_include != FWUPD_DEVICE_FLAG_NONE) { |
| 298 | if (!fwupd_device_has_flag (dev, priv->filter_include)) |
| 299 | return FALSE; |
| 300 | } |
| 301 | if (priv->filter_exclude != FWUPD_DEVICE_FLAG_NONE) { |
| 302 | if (fwupd_device_has_flag (dev, priv->filter_exclude)) |
| 303 | return FALSE; |
| 304 | } |
| 305 | return TRUE; |
| 306 | } |
| 307 | |
Mario Limonciello | 20cc9ee | 2019-09-05 07:27:26 -0500 | [diff] [blame] | 308 | static gchar * |
| 309 | fu_util_get_tree_title (FuUtilPrivate *priv) |
| 310 | { |
| 311 | return g_strdup (fu_engine_get_host_product (priv->engine)); |
| 312 | } |
| 313 | |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 314 | static gboolean |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 315 | fu_util_get_updates (FuUtilPrivate *priv, gchar **values, GError **error) |
| 316 | { |
| 317 | g_autoptr(GPtrArray) devices = NULL; |
Mario Limonciello | 4250d9d | 2019-08-29 09:53:44 -0500 | [diff] [blame] | 318 | g_autoptr(GNode) root = g_node_new (NULL); |
Mario Limonciello | dc9a1a8 | 2020-02-20 14:20:20 -0600 | [diff] [blame] | 319 | g_autofree gchar *title = NULL; |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 320 | |
| 321 | /* load engine */ |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 322 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 323 | return FALSE; |
Mario Limonciello | dc9a1a8 | 2020-02-20 14:20:20 -0600 | [diff] [blame] | 324 | title = fu_util_get_tree_title (priv); |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 325 | |
| 326 | /* get devices from daemon */ |
| 327 | devices = fu_engine_get_devices (priv->engine, error); |
| 328 | if (devices == NULL) |
| 329 | return FALSE; |
Richard Hughes | 0ef4720 | 2020-01-06 13:59:09 +0000 | [diff] [blame] | 330 | fwupd_device_array_ensure_parents (devices); |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 331 | for (guint i = 0; i < devices->len; i++) { |
| 332 | FwupdDevice *dev = g_ptr_array_index (devices, i); |
| 333 | g_autoptr(GPtrArray) rels = NULL; |
| 334 | g_autoptr(GError) error_local = NULL; |
Mario Limonciello | 4250d9d | 2019-08-29 09:53:44 -0500 | [diff] [blame] | 335 | GNode *child; |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 336 | |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 337 | /* not going to have results, so save a engine round-trip */ |
Mario Limonciello | 27164b7 | 2020-02-17 23:19:36 -0600 | [diff] [blame] | 338 | if (!fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE)) |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 339 | continue; |
Mario Limonciello | 27164b7 | 2020-02-17 23:19:36 -0600 | [diff] [blame] | 340 | if (!fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_SUPPORTED)) { |
| 341 | /* TRANSLATORS: message letting the user know no device upgrade available due to missing on LVFS |
| 342 | * %1 is the device name */ |
| 343 | g_autofree gchar *tmp = g_strdup_printf (_("• %s has no available firmware updates"), |
| 344 | fwupd_device_get_name (dev)); |
| 345 | g_printerr ("%s\n", tmp); |
| 346 | continue; |
| 347 | } |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 348 | if (!fu_util_filter_device (priv, dev)) |
| 349 | continue; |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 350 | |
| 351 | /* get the releases for this device and filter for validity */ |
| 352 | rels = fu_engine_get_upgrades (priv->engine, |
| 353 | fwupd_device_get_id (dev), |
| 354 | &error_local); |
| 355 | if (rels == NULL) { |
Mario Limonciello | 7e4949c | 2019-12-09 10:21:20 -0600 | [diff] [blame] | 356 | /* TRANSLATORS: message letting the user know no device upgrade available |
| 357 | * %1 is the device name */ |
Mario Limonciello | 27164b7 | 2020-02-17 23:19:36 -0600 | [diff] [blame] | 358 | g_autofree gchar *tmp = g_strdup_printf (_("• %s has the latest available firmware version"), |
| 359 | fwupd_device_get_name (dev)); |
| 360 | g_printerr ("%s\n", tmp); |
| 361 | /* discard the actual reason from user, but leave for debugging */ |
| 362 | g_debug ("%s", error_local->message); |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 363 | continue; |
| 364 | } |
Mario Limonciello | 4250d9d | 2019-08-29 09:53:44 -0500 | [diff] [blame] | 365 | child = g_node_append_data (root, dev); |
| 366 | |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 367 | for (guint j = 0; j < rels->len; j++) { |
| 368 | FwupdRelease *rel = g_ptr_array_index (rels, j); |
Mario Limonciello | 4250d9d | 2019-08-29 09:53:44 -0500 | [diff] [blame] | 369 | g_node_append_data (child, g_object_ref (rel)); |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 370 | } |
| 371 | } |
Mario Limonciello | 4250d9d | 2019-08-29 09:53:44 -0500 | [diff] [blame] | 372 | if (g_node_n_nodes (root, G_TRAVERSE_ALL) > 1) |
Mario Limonciello | 20cc9ee | 2019-09-05 07:27:26 -0500 | [diff] [blame] | 373 | fu_util_print_tree (root, title); |
Mario Limonciello | 3143bad | 2019-02-27 07:31:00 -0600 | [diff] [blame] | 374 | /* save the device state for other applications to see */ |
| 375 | if (!fu_util_save_current_state (priv, error)) |
| 376 | return FALSE; |
| 377 | |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 378 | /* success */ |
| 379 | return TRUE; |
| 380 | } |
| 381 | |
| 382 | static gboolean |
Mario Limonciello | 716ab27 | 2018-05-29 12:34:37 -0500 | [diff] [blame] | 383 | fu_util_get_details (FuUtilPrivate *priv, gchar **values, GError **error) |
| 384 | { |
| 385 | g_autoptr(GPtrArray) array = NULL; |
Mario Limonciello | 4250d9d | 2019-08-29 09:53:44 -0500 | [diff] [blame] | 386 | g_autoptr(GNode) root = g_node_new (NULL); |
Mario Limonciello | dc9a1a8 | 2020-02-20 14:20:20 -0600 | [diff] [blame] | 387 | g_autofree gchar *title = NULL; |
Mario Limonciello | 716ab27 | 2018-05-29 12:34:37 -0500 | [diff] [blame] | 388 | gint fd; |
| 389 | |
| 390 | /* load engine */ |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 391 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
Mario Limonciello | 716ab27 | 2018-05-29 12:34:37 -0500 | [diff] [blame] | 392 | return FALSE; |
Mario Limonciello | dc9a1a8 | 2020-02-20 14:20:20 -0600 | [diff] [blame] | 393 | title = fu_util_get_tree_title (priv); |
Mario Limonciello | 716ab27 | 2018-05-29 12:34:37 -0500 | [diff] [blame] | 394 | |
| 395 | /* check args */ |
| 396 | if (g_strv_length (values) != 1) { |
| 397 | g_set_error_literal (error, |
| 398 | FWUPD_ERROR, |
| 399 | FWUPD_ERROR_INVALID_ARGS, |
| 400 | "Invalid arguments"); |
| 401 | return FALSE; |
| 402 | } |
| 403 | |
Mario Limonciello | dc0608d | 2020-02-25 11:25:44 -0600 | [diff] [blame] | 404 | /* implied, important for get-details on a device not in your system */ |
| 405 | priv->show_all_devices = TRUE; |
| 406 | |
Mario Limonciello | 716ab27 | 2018-05-29 12:34:37 -0500 | [diff] [blame] | 407 | /* open file */ |
| 408 | fd = open (values[0], O_RDONLY); |
| 409 | if (fd < 0) { |
Mario Limonciello | b72aa8c | 2018-06-08 09:24:36 -0500 | [diff] [blame] | 410 | fu_util_maybe_prefix_sandbox_error (values[0], error); |
Mario Limonciello | 716ab27 | 2018-05-29 12:34:37 -0500 | [diff] [blame] | 411 | g_set_error (error, |
| 412 | FWUPD_ERROR, |
| 413 | FWUPD_ERROR_INVALID_FILE, |
| 414 | "failed to open %s", |
| 415 | values[0]); |
| 416 | return FALSE; |
| 417 | } |
| 418 | array = fu_engine_get_details (priv->engine, fd, error); |
| 419 | close (fd); |
| 420 | |
| 421 | if (array == NULL) |
| 422 | return FALSE; |
| 423 | for (guint i = 0; i < array->len; i++) { |
| 424 | FwupdDevice *dev = g_ptr_array_index (array, i); |
Mario Limonciello | 984e29c | 2020-02-25 11:30:28 -0600 | [diff] [blame] | 425 | FwupdRelease *rel; |
| 426 | GNode *child; |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 427 | if (!fu_util_filter_device (priv, dev)) |
| 428 | continue; |
Mario Limonciello | 984e29c | 2020-02-25 11:30:28 -0600 | [diff] [blame] | 429 | child = g_node_append_data (root, dev); |
| 430 | rel = fwupd_device_get_release_default (dev); |
| 431 | if (rel != NULL) |
| 432 | g_node_append_data (child, rel); |
| 433 | |
Mario Limonciello | 716ab27 | 2018-05-29 12:34:37 -0500 | [diff] [blame] | 434 | } |
Mario Limonciello | 20cc9ee | 2019-09-05 07:27:26 -0500 | [diff] [blame] | 435 | fu_util_print_tree (root, title); |
Mario Limonciello | 4250d9d | 2019-08-29 09:53:44 -0500 | [diff] [blame] | 436 | |
Mario Limonciello | 716ab27 | 2018-05-29 12:34:37 -0500 | [diff] [blame] | 437 | return TRUE; |
| 438 | } |
| 439 | |
| 440 | static gboolean |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 441 | fu_util_get_device_flags (FuUtilPrivate *priv, gchar **values, GError **error) |
| 442 | { |
| 443 | g_autoptr(GString) str = g_string_new (NULL); |
| 444 | |
| 445 | for (FwupdDeviceFlags i = FWUPD_DEVICE_FLAG_INTERNAL; i < FWUPD_DEVICE_FLAG_UNKNOWN; i<<=1) { |
| 446 | const gchar *tmp = fwupd_device_flag_to_string (i); |
| 447 | if (tmp == NULL) |
| 448 | break; |
| 449 | if (i != FWUPD_DEVICE_FLAG_INTERNAL) |
| 450 | g_string_append (str, " "); |
| 451 | g_string_append (str, tmp); |
| 452 | g_string_append (str, " ~"); |
| 453 | g_string_append (str, tmp); |
| 454 | } |
| 455 | g_print ("%s\n", str->str); |
| 456 | |
| 457 | return TRUE; |
| 458 | } |
| 459 | |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 460 | static void |
Richard Hughes | 0d1577e | 2018-05-29 13:59:06 +0100 | [diff] [blame] | 461 | fu_util_build_device_tree (FuUtilPrivate *priv, GNode *root, GPtrArray *devs, FuDevice *dev) |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 462 | { |
| 463 | for (guint i = 0; i < devs->len; i++) { |
Richard Hughes | 0d1577e | 2018-05-29 13:59:06 +0100 | [diff] [blame] | 464 | FuDevice *dev_tmp = g_ptr_array_index (devs, i); |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 465 | if (!fu_util_filter_device (priv, FWUPD_DEVICE (dev_tmp))) |
| 466 | continue; |
Mario Limonciello | d1775bc | 2018-07-17 00:28:52 -0500 | [diff] [blame] | 467 | if (!priv->show_all_devices && |
| 468 | !fu_util_is_interesting_device (FWUPD_DEVICE (dev_tmp))) |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 469 | continue; |
Richard Hughes | 0d1577e | 2018-05-29 13:59:06 +0100 | [diff] [blame] | 470 | if (fu_device_get_parent (dev_tmp) == dev) { |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 471 | GNode *child = g_node_append_data (root, dev_tmp); |
| 472 | fu_util_build_device_tree (priv, child, devs, dev_tmp); |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | static gboolean |
Mario Limonciello | 1a9127d | 2019-08-27 11:32:51 +0100 | [diff] [blame] | 478 | fu_util_get_devices (FuUtilPrivate *priv, gchar **values, GError **error) |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 479 | { |
| 480 | g_autoptr(GNode) root = g_node_new (NULL); |
Mario Limonciello | dc9a1a8 | 2020-02-20 14:20:20 -0600 | [diff] [blame] | 481 | g_autofree gchar *title = NULL; |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 482 | g_autoptr(GPtrArray) devs = NULL; |
| 483 | |
| 484 | /* load engine */ |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 485 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 486 | return FALSE; |
Mario Limonciello | dc9a1a8 | 2020-02-20 14:20:20 -0600 | [diff] [blame] | 487 | title = fu_util_get_tree_title (priv); |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 488 | |
| 489 | /* print */ |
| 490 | devs = fu_engine_get_devices (priv->engine, error); |
| 491 | if (devs == NULL) |
| 492 | return FALSE; |
| 493 | |
| 494 | /* print */ |
| 495 | if (devs->len == 0) { |
| 496 | /* TRANSLATORS: nothing attached that can be upgraded */ |
| 497 | g_print ("%s\n", _("No hardware detected with firmware update capability")); |
| 498 | return TRUE; |
| 499 | } |
Richard Hughes | 0ef4720 | 2020-01-06 13:59:09 +0000 | [diff] [blame] | 500 | fwupd_device_array_ensure_parents (devs); |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 501 | fu_util_build_device_tree (priv, root, devs, NULL); |
Mario Limonciello | 20cc9ee | 2019-09-05 07:27:26 -0500 | [diff] [blame] | 502 | fu_util_print_tree (root, title); |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 503 | |
Mario Limonciello | 1a9127d | 2019-08-27 11:32:51 +0100 | [diff] [blame] | 504 | /* save the device state for other applications to see */ |
| 505 | return fu_util_save_current_state (priv, error); |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 506 | } |
| 507 | |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 508 | static FuDevice * |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 509 | fu_util_prompt_for_device (FuUtilPrivate *priv, GPtrArray *devices_opt, GError **error) |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 510 | { |
| 511 | FuDevice *dev; |
| 512 | guint idx; |
| 513 | g_autoptr(GPtrArray) devices = NULL; |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 514 | g_autoptr(GPtrArray) devices_filtered = NULL; |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 515 | |
| 516 | /* get devices from daemon */ |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 517 | if (devices_opt != NULL) { |
| 518 | devices = g_ptr_array_ref (devices_opt); |
| 519 | } else { |
| 520 | devices = fu_engine_get_devices (priv->engine, error); |
| 521 | if (devices == NULL) |
| 522 | return NULL; |
| 523 | } |
Richard Hughes | 0ef4720 | 2020-01-06 13:59:09 +0000 | [diff] [blame] | 524 | fwupd_device_array_ensure_parents (devices); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 525 | |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 526 | /* filter results */ |
| 527 | devices_filtered = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 528 | for (guint i = 0; i < devices->len; i++) { |
| 529 | dev = g_ptr_array_index (devices, i); |
| 530 | if (!fu_util_filter_device (priv, FWUPD_DEVICE (dev))) |
| 531 | continue; |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 532 | g_ptr_array_add (devices_filtered, g_object_ref (dev)); |
| 533 | } |
| 534 | |
| 535 | /* nothing */ |
| 536 | if (devices_filtered->len == 0) { |
| 537 | g_set_error_literal (error, |
| 538 | FWUPD_ERROR, |
| 539 | FWUPD_ERROR_NOTHING_TO_DO, |
| 540 | "No supported devices"); |
| 541 | return NULL; |
| 542 | } |
| 543 | |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 544 | /* exactly one */ |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 545 | if (devices_filtered->len == 1) { |
| 546 | dev = g_ptr_array_index (devices_filtered, 0); |
Mario Limonciello | a61b4d8 | 2019-10-22 08:37:45 -0500 | [diff] [blame] | 547 | /* TRANSLATORS: Device has been chosen by the daemon for the user */ |
| 548 | g_print ("%s: %s\n", _("Selected device"), fu_device_get_name (dev)); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 549 | return g_object_ref (dev); |
| 550 | } |
| 551 | |
| 552 | /* TRANSLATORS: get interactive prompt */ |
| 553 | g_print ("%s\n", _("Choose a device:")); |
| 554 | /* TRANSLATORS: this is to abort the interactive prompt */ |
| 555 | g_print ("0.\t%s\n", _("Cancel")); |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 556 | for (guint i = 0; i < devices_filtered->len; i++) { |
| 557 | dev = g_ptr_array_index (devices_filtered, i); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 558 | g_print ("%u.\t%s (%s)\n", |
| 559 | i + 1, |
| 560 | fu_device_get_id (dev), |
| 561 | fu_device_get_name (dev)); |
| 562 | } |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 563 | idx = fu_util_prompt_for_number (devices_filtered->len); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 564 | if (idx == 0) { |
| 565 | g_set_error_literal (error, |
| 566 | FWUPD_ERROR, |
| 567 | FWUPD_ERROR_NOTHING_TO_DO, |
| 568 | "Request canceled"); |
| 569 | return NULL; |
| 570 | } |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 571 | dev = g_ptr_array_index (devices_filtered, idx - 1); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 572 | return g_object_ref (dev); |
| 573 | } |
| 574 | |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 575 | static void |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 576 | fu_util_update_device_changed_cb (FwupdClient *client, |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 577 | FwupdDevice *device, |
| 578 | FuUtilPrivate *priv) |
| 579 | { |
| 580 | g_autofree gchar *str = NULL; |
| 581 | |
Richard Hughes | 809abea | 2019-03-23 11:06:18 +0000 | [diff] [blame] | 582 | /* allowed to set whenever the device has changed */ |
| 583 | if (fwupd_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_SHUTDOWN)) |
| 584 | priv->completion_flags |= FWUPD_DEVICE_FLAG_NEEDS_SHUTDOWN; |
| 585 | if (fwupd_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_REBOOT)) |
| 586 | priv->completion_flags |= FWUPD_DEVICE_FLAG_NEEDS_REBOOT; |
| 587 | |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 588 | /* same as last time, so ignore */ |
| 589 | if (priv->current_device != NULL && |
| 590 | fwupd_device_compare (priv->current_device, device) == 0) |
| 591 | return; |
| 592 | |
Richard Hughes | ee562b5 | 2020-04-07 14:32:52 +0100 | [diff] [blame] | 593 | /* ignore indirect devices that might have changed */ |
| 594 | if (fwupd_device_get_status (device) == FWUPD_STATUS_IDLE || |
| 595 | fwupd_device_get_status (device) == FWUPD_STATUS_UNKNOWN) { |
| 596 | g_debug ("ignoring %s with status %s", |
| 597 | fwupd_device_get_name (device), |
| 598 | fwupd_status_to_string (fwupd_device_get_status (device))); |
| 599 | return; |
| 600 | } |
| 601 | |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 602 | /* show message in progressbar */ |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 603 | if (priv->current_operation == FU_UTIL_OPERATION_UPDATE) { |
| 604 | /* TRANSLATORS: %1 is a device name */ |
| 605 | str = g_strdup_printf (_("Updating %s…"), |
| 606 | fwupd_device_get_name (device)); |
| 607 | fu_progressbar_set_title (priv->progressbar, str); |
| 608 | } else if (priv->current_operation == FU_UTIL_OPERATION_INSTALL) { |
| 609 | /* TRANSLATORS: %1 is a device name */ |
| 610 | str = g_strdup_printf (_("Installing on %s…"), |
| 611 | fwupd_device_get_name (device)); |
| 612 | fu_progressbar_set_title (priv->progressbar, str); |
Richard Hughes | a58510b | 2019-10-30 10:03:12 +0000 | [diff] [blame] | 613 | } else if (priv->current_operation == FU_UTIL_OPERATION_READ) { |
| 614 | /* TRANSLATORS: %1 is a device name */ |
| 615 | str = g_strdup_printf (_("Reading from %s…"), |
| 616 | fwupd_device_get_name (device)); |
| 617 | fu_progressbar_set_title (priv->progressbar, str); |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 618 | } else { |
| 619 | g_warning ("no FuUtilOperation set"); |
| 620 | } |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 621 | g_set_object (&priv->current_device, device); |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 622 | |
Mario Limonciello | 32241f4 | 2019-01-24 10:12:41 -0600 | [diff] [blame] | 623 | if (priv->current_message == NULL) { |
| 624 | const gchar *tmp = fwupd_device_get_update_message (priv->current_device); |
| 625 | if (tmp != NULL) |
| 626 | priv->current_message = g_strdup (tmp); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | static void |
| 631 | fu_util_display_current_message (FuUtilPrivate *priv) |
| 632 | { |
| 633 | if (priv->current_message == NULL) |
| 634 | return; |
| 635 | g_print ("%s\n", priv->current_message); |
| 636 | g_clear_pointer (&priv->current_message, g_free); |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 637 | } |
| 638 | |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 639 | static FuDevice * |
| 640 | fu_util_get_device (FuUtilPrivate *priv, const gchar *id, GError **error) |
| 641 | { |
| 642 | if (fwupd_guid_is_valid (id)) { |
| 643 | g_autoptr(GPtrArray) devices = NULL; |
| 644 | devices = fu_engine_get_devices_by_guid (priv->engine, id, error); |
| 645 | if (devices == NULL) |
| 646 | return NULL; |
| 647 | return fu_util_prompt_for_device (priv, devices, error); |
| 648 | } |
Mario Limonciello | c6009f5 | 2020-04-20 15:40:11 -0500 | [diff] [blame] | 649 | |
| 650 | /* did this look like a GUID? */ |
| 651 | for (guint i = 0; id[i] != '\0'; i++) { |
| 652 | if (id[i] == '-') { |
| 653 | g_set_error_literal (error, |
| 654 | FWUPD_ERROR, |
| 655 | FWUPD_ERROR_INVALID_ARGS, |
| 656 | "Invalid arguments"); |
Richard Hughes | 9c09e2c | 2020-04-22 10:52:42 +0100 | [diff] [blame] | 657 | return NULL; |
Mario Limonciello | c6009f5 | 2020-04-20 15:40:11 -0500 | [diff] [blame] | 658 | } |
| 659 | } |
Mario Limonciello | aac9c74 | 2020-04-20 13:38:44 -0500 | [diff] [blame] | 660 | return fu_engine_get_device (priv->engine, id, error); |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 661 | } |
| 662 | |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 663 | static gboolean |
| 664 | fu_util_install_blob (FuUtilPrivate *priv, gchar **values, GError **error) |
| 665 | { |
| 666 | g_autoptr(FuDevice) device = NULL; |
| 667 | g_autoptr(GBytes) blob_fw = NULL; |
| 668 | |
| 669 | /* invalid args */ |
| 670 | if (g_strv_length (values) == 0) { |
| 671 | g_set_error_literal (error, |
| 672 | FWUPD_ERROR, |
| 673 | FWUPD_ERROR_INVALID_ARGS, |
| 674 | "Invalid arguments"); |
| 675 | return FALSE; |
| 676 | } |
| 677 | |
| 678 | /* parse blob */ |
| 679 | blob_fw = fu_common_get_contents_bytes (values[0], error); |
Mario Limonciello | b72aa8c | 2018-06-08 09:24:36 -0500 | [diff] [blame] | 680 | if (blob_fw == NULL) { |
| 681 | fu_util_maybe_prefix_sandbox_error (values[0], error); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 682 | return FALSE; |
Mario Limonciello | b72aa8c | 2018-06-08 09:24:36 -0500 | [diff] [blame] | 683 | } |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 684 | |
| 685 | /* load engine */ |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 686 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 687 | return FALSE; |
| 688 | |
| 689 | /* get device */ |
| 690 | if (g_strv_length (values) >= 2) { |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 691 | device = fu_util_get_device (priv, values[1], error); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 692 | if (device == NULL) |
| 693 | return FALSE; |
| 694 | } else { |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 695 | device = fu_util_prompt_for_device (priv, NULL, error); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 696 | if (device == NULL) |
| 697 | return FALSE; |
| 698 | } |
| 699 | |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 700 | priv->current_operation = FU_UTIL_OPERATION_INSTALL; |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 701 | g_signal_connect (priv->engine, "device-changed", |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 702 | G_CALLBACK (fu_util_update_device_changed_cb), priv); |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 703 | |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 704 | /* write bare firmware */ |
Mario Limonciello | 53ce25d | 2019-02-01 16:09:03 +0000 | [diff] [blame] | 705 | if (priv->prepare_blob) { |
| 706 | g_autoptr(GPtrArray) devices = NULL; |
| 707 | devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 708 | g_ptr_array_add (devices, g_object_ref (device)); |
| 709 | if (!fu_engine_composite_prepare (priv->engine, devices, error)) { |
| 710 | g_prefix_error (error, "failed to prepare composite action: "); |
| 711 | return FALSE; |
| 712 | } |
| 713 | } |
Richard Hughes | f1fa73e | 2020-04-06 16:19:04 +0100 | [diff] [blame] | 714 | priv->flags |= FWUPD_INSTALL_FLAG_NO_HISTORY; |
Richard Hughes | 84af6e7 | 2019-02-01 18:19:41 +0000 | [diff] [blame] | 715 | if (!fu_engine_install_blob (priv->engine, device, blob_fw, priv->flags, error)) |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 716 | return FALSE; |
Mario Limonciello | 53ce25d | 2019-02-01 16:09:03 +0000 | [diff] [blame] | 717 | if (priv->cleanup_blob) { |
| 718 | g_autoptr(FuDevice) device_new = NULL; |
| 719 | g_autoptr(GError) error_local = NULL; |
| 720 | |
| 721 | /* get the possibly new device from the old ID */ |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 722 | device_new = fu_util_get_device (priv, |
| 723 | fu_device_get_id (device), |
| 724 | &error_local); |
Mario Limonciello | 53ce25d | 2019-02-01 16:09:03 +0000 | [diff] [blame] | 725 | if (device_new == NULL) { |
| 726 | g_debug ("failed to find new device: %s", |
| 727 | error_local->message); |
| 728 | } else { |
Mario Limonciello | bb3fa5e | 2019-02-07 21:13:02 -0600 | [diff] [blame] | 729 | g_autoptr(GPtrArray) devices_new = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
Mario Limonciello | 53ce25d | 2019-02-01 16:09:03 +0000 | [diff] [blame] | 730 | g_ptr_array_add (devices_new, g_steal_pointer (&device_new)); |
| 731 | if (!fu_engine_composite_cleanup (priv->engine, devices_new, error)) { |
| 732 | g_prefix_error (error, "failed to cleanup composite action: "); |
| 733 | return FALSE; |
| 734 | } |
| 735 | } |
| 736 | } |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 737 | |
Mario Limonciello | 32241f4 | 2019-01-24 10:12:41 -0600 | [diff] [blame] | 738 | fu_util_display_current_message (priv); |
| 739 | |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 740 | /* success */ |
| 741 | return fu_util_prompt_complete (priv->completion_flags, TRUE, error); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 742 | } |
| 743 | |
Richard Hughes | a58510b | 2019-10-30 10:03:12 +0000 | [diff] [blame] | 744 | static gboolean |
| 745 | fu_util_firmware_read (FuUtilPrivate *priv, gchar **values, GError **error) |
| 746 | { |
| 747 | g_autoptr(FuDevice) device = NULL; |
| 748 | g_autoptr(GBytes) blob_empty = g_bytes_new (NULL, 0); |
| 749 | g_autoptr(GBytes) blob_fw = NULL; |
| 750 | |
| 751 | /* invalid args */ |
| 752 | if (g_strv_length (values) == 0) { |
| 753 | g_set_error_literal (error, |
| 754 | FWUPD_ERROR, |
| 755 | FWUPD_ERROR_INVALID_ARGS, |
| 756 | "Invalid arguments"); |
| 757 | return FALSE; |
| 758 | } |
| 759 | |
| 760 | /* file already exists */ |
| 761 | if ((priv->flags & FWUPD_INSTALL_FLAG_FORCE) == 0 && |
| 762 | g_file_test (values[0], G_FILE_TEST_EXISTS)) { |
| 763 | g_set_error_literal (error, |
| 764 | FWUPD_ERROR, |
| 765 | FWUPD_ERROR_INVALID_ARGS, |
| 766 | "Filename already exists"); |
| 767 | return FALSE; |
| 768 | } |
| 769 | |
Richard Hughes | 02792c0 | 2019-11-01 14:21:20 +0000 | [diff] [blame] | 770 | /* write a zero length file to ensure the destination is writable to |
Richard Hughes | a58510b | 2019-10-30 10:03:12 +0000 | [diff] [blame] | 771 | * avoid failing at the end of a potentially lengthy operation */ |
| 772 | if (!fu_common_set_contents_bytes (values[0], blob_empty, error)) |
| 773 | return FALSE; |
| 774 | |
| 775 | /* load engine */ |
| 776 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
| 777 | return FALSE; |
| 778 | |
| 779 | /* get device */ |
| 780 | if (g_strv_length (values) >= 2) { |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 781 | device = fu_util_get_device (priv, values[1], error); |
Richard Hughes | a58510b | 2019-10-30 10:03:12 +0000 | [diff] [blame] | 782 | if (device == NULL) |
| 783 | return FALSE; |
| 784 | } else { |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 785 | device = fu_util_prompt_for_device (priv, NULL, error); |
Richard Hughes | a58510b | 2019-10-30 10:03:12 +0000 | [diff] [blame] | 786 | if (device == NULL) |
| 787 | return FALSE; |
| 788 | } |
| 789 | priv->current_operation = FU_UTIL_OPERATION_READ; |
| 790 | g_signal_connect (priv->engine, "device-changed", |
| 791 | G_CALLBACK (fu_util_update_device_changed_cb), priv); |
| 792 | |
| 793 | /* dump firmware */ |
| 794 | blob_fw = fu_engine_firmware_read (priv->engine, device, priv->flags, error); |
| 795 | if (blob_fw == NULL) |
| 796 | return FALSE; |
| 797 | return fu_common_set_contents_bytes (values[0], blob_fw, error); |
| 798 | } |
| 799 | |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 800 | static gint |
| 801 | fu_util_install_task_sort_cb (gconstpointer a, gconstpointer b) |
| 802 | { |
| 803 | FuInstallTask *task1 = *((FuInstallTask **) a); |
| 804 | FuInstallTask *task2 = *((FuInstallTask **) b); |
| 805 | return fu_install_task_compare (task1, task2); |
| 806 | } |
| 807 | |
| 808 | static gboolean |
Richard Hughes | 3d178be | 2018-08-30 11:14:24 +0100 | [diff] [blame] | 809 | fu_util_download_out_of_process (const gchar *uri, const gchar *fn, GError **error) |
| 810 | { |
Filipe LaÃns | e091427 | 2019-09-20 10:04:43 +0100 | [diff] [blame] | 811 | const gchar *argv[][5] = { { "wget", uri, "-O", fn, NULL }, |
Richard Hughes | 3d178be | 2018-08-30 11:14:24 +0100 | [diff] [blame] | 812 | { "curl", uri, "--output", fn, NULL }, |
| 813 | { NULL } }; |
| 814 | for (guint i = 0; argv[i][0] != NULL; i++) { |
| 815 | g_autoptr(GError) error_local = NULL; |
| 816 | if (!fu_common_find_program_in_path (argv[i][0], &error_local)) { |
| 817 | g_debug ("%s", error_local->message); |
| 818 | continue; |
| 819 | } |
Richard Hughes | b768e4d | 2019-02-26 13:55:18 +0000 | [diff] [blame] | 820 | return fu_common_spawn_sync (argv[i], NULL, NULL, 0, NULL, error); |
Richard Hughes | 3d178be | 2018-08-30 11:14:24 +0100 | [diff] [blame] | 821 | } |
| 822 | g_set_error_literal (error, |
| 823 | FWUPD_ERROR, |
| 824 | FWUPD_ERROR_NOT_FOUND, |
| 825 | "no supported out-of-process downloaders found"); |
| 826 | return FALSE; |
| 827 | } |
| 828 | |
| 829 | static gchar * |
| 830 | fu_util_download_if_required (FuUtilPrivate *priv, const gchar *perhapsfn, GError **error) |
| 831 | { |
| 832 | g_autofree gchar *filename = NULL; |
| 833 | g_autoptr(SoupURI) uri = NULL; |
| 834 | |
| 835 | /* a local file */ |
| 836 | uri = soup_uri_new (perhapsfn); |
Richard Hughes | 45a0073 | 2019-11-22 16:57:14 +0000 | [diff] [blame] | 837 | if (g_file_test (perhapsfn, G_FILE_TEST_EXISTS)) |
| 838 | return g_strdup (perhapsfn); |
Richard Hughes | 3d178be | 2018-08-30 11:14:24 +0100 | [diff] [blame] | 839 | if (uri == NULL) |
| 840 | return g_strdup (perhapsfn); |
| 841 | |
| 842 | /* download the firmware to a cachedir */ |
| 843 | filename = fu_util_get_user_cache_path (perhapsfn); |
| 844 | if (!fu_common_mkdir_parent (filename, error)) |
| 845 | return NULL; |
| 846 | if (!fu_util_download_out_of_process (perhapsfn, filename, error)) |
| 847 | return NULL; |
| 848 | return g_steal_pointer (&filename); |
| 849 | } |
| 850 | |
| 851 | static gboolean |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 852 | fu_util_install (FuUtilPrivate *priv, gchar **values, GError **error) |
| 853 | { |
Richard Hughes | 3d178be | 2018-08-30 11:14:24 +0100 | [diff] [blame] | 854 | g_autofree gchar *filename = NULL; |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 855 | g_autoptr(GBytes) blob_cab = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 856 | g_autoptr(GPtrArray) components = NULL; |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 857 | g_autoptr(GPtrArray) devices_possible = NULL; |
| 858 | g_autoptr(GPtrArray) errors = NULL; |
| 859 | g_autoptr(GPtrArray) install_tasks = NULL; |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 860 | g_autoptr(XbSilo) silo = NULL; |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 861 | |
Mario Limonciello | 8949e89 | 2018-05-25 08:03:06 -0500 | [diff] [blame] | 862 | /* load engine */ |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 863 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
Mario Limonciello | 8949e89 | 2018-05-25 08:03:06 -0500 | [diff] [blame] | 864 | return FALSE; |
| 865 | |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 866 | /* handle both forms */ |
| 867 | if (g_strv_length (values) == 1) { |
| 868 | devices_possible = fu_engine_get_devices (priv->engine, error); |
| 869 | if (devices_possible == NULL) |
| 870 | return FALSE; |
Richard Hughes | 0ef4720 | 2020-01-06 13:59:09 +0000 | [diff] [blame] | 871 | fwupd_device_array_ensure_parents (devices_possible); |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 872 | } else if (g_strv_length (values) == 2) { |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 873 | FuDevice *device = fu_util_get_device (priv, values[1], error); |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 874 | if (device == NULL) |
| 875 | return FALSE; |
| 876 | devices_possible = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 877 | g_ptr_array_add (devices_possible, device); |
| 878 | } else { |
| 879 | g_set_error_literal (error, |
| 880 | FWUPD_ERROR, |
| 881 | FWUPD_ERROR_INVALID_ARGS, |
| 882 | "Invalid arguments"); |
| 883 | return FALSE; |
| 884 | } |
| 885 | |
Richard Hughes | 3d178be | 2018-08-30 11:14:24 +0100 | [diff] [blame] | 886 | /* download if required */ |
| 887 | filename = fu_util_download_if_required (priv, values[0], error); |
| 888 | if (filename == NULL) |
| 889 | return FALSE; |
| 890 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 891 | /* parse silo */ |
Richard Hughes | 3d178be | 2018-08-30 11:14:24 +0100 | [diff] [blame] | 892 | blob_cab = fu_common_get_contents_bytes (filename, error); |
Mario Limonciello | b72aa8c | 2018-06-08 09:24:36 -0500 | [diff] [blame] | 893 | if (blob_cab == NULL) { |
Richard Hughes | 3d178be | 2018-08-30 11:14:24 +0100 | [diff] [blame] | 894 | fu_util_maybe_prefix_sandbox_error (filename, error); |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 895 | return FALSE; |
Mario Limonciello | b72aa8c | 2018-06-08 09:24:36 -0500 | [diff] [blame] | 896 | } |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 897 | silo = fu_engine_get_silo_from_blob (priv->engine, blob_cab, error); |
| 898 | if (silo == NULL) |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 899 | return FALSE; |
Mario Limonciello | 51ddf18 | 2019-01-26 00:31:58 -0600 | [diff] [blame] | 900 | components = xb_silo_query (silo, "components/component", 0, error); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 901 | if (components == NULL) |
| 902 | return FALSE; |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 903 | |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 904 | /* for each component in the silo */ |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 905 | errors = g_ptr_array_new_with_free_func ((GDestroyNotify) g_error_free); |
| 906 | install_tasks = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 907 | for (guint i = 0; i < components->len; i++) { |
| 908 | XbNode *component = g_ptr_array_index (components, i); |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 909 | |
| 910 | /* do any devices pass the requirements */ |
| 911 | for (guint j = 0; j < devices_possible->len; j++) { |
| 912 | FuDevice *device = g_ptr_array_index (devices_possible, j); |
| 913 | g_autoptr(FuInstallTask) task = NULL; |
| 914 | g_autoptr(GError) error_local = NULL; |
| 915 | |
| 916 | /* is this component valid for the device */ |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 917 | task = fu_install_task_new (device, component); |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 918 | if (!fu_engine_check_requirements (priv->engine, |
Mario Limonciello | 537da0e | 2020-03-09 15:38:17 -0500 | [diff] [blame] | 919 | task, priv->flags | FWUPD_INSTALL_FLAG_FORCE, |
| 920 | &error_local)) { |
| 921 | g_debug ("first pass requirement on %s:%s failed: %s", |
| 922 | fu_device_get_id (device), |
| 923 | xb_node_query_text (component, "id", NULL), |
| 924 | error_local->message); |
| 925 | g_ptr_array_add (errors, g_steal_pointer (&error_local)); |
| 926 | continue; |
| 927 | } |
| 928 | |
| 929 | /* make a second pass using possibly updated version format now */ |
| 930 | fu_engine_md_refresh_device_from_component (priv->engine, device, component); |
| 931 | if (!fu_engine_check_requirements (priv->engine, |
Richard Hughes | 460226a | 2018-05-21 20:56:21 +0100 | [diff] [blame] | 932 | task, priv->flags, |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 933 | &error_local)) { |
Mario Limonciello | 537da0e | 2020-03-09 15:38:17 -0500 | [diff] [blame] | 934 | g_debug ("second pass requirement on %s:%s failed: %s", |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 935 | fu_device_get_id (device), |
Richard Hughes | 481aa2a | 2018-09-18 20:51:46 +0100 | [diff] [blame] | 936 | xb_node_query_text (component, "id", NULL), |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 937 | error_local->message); |
| 938 | g_ptr_array_add (errors, g_steal_pointer (&error_local)); |
| 939 | continue; |
| 940 | } |
| 941 | |
Mario Limonciello | 7a3df4b | 2019-01-31 10:27:22 -0600 | [diff] [blame] | 942 | /* if component should have an update message from CAB */ |
| 943 | fu_device_incorporate_from_component (device, component); |
| 944 | |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 945 | /* success */ |
| 946 | g_ptr_array_add (install_tasks, g_steal_pointer (&task)); |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | /* order the install tasks by the device priority */ |
| 951 | g_ptr_array_sort (install_tasks, fu_util_install_task_sort_cb); |
| 952 | |
| 953 | /* nothing suitable */ |
| 954 | if (install_tasks->len == 0) { |
| 955 | GError *error_tmp = fu_common_error_array_get_best (errors); |
| 956 | g_propagate_error (error, error_tmp); |
| 957 | return FALSE; |
| 958 | } |
| 959 | |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 960 | priv->current_operation = FU_UTIL_OPERATION_INSTALL; |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 961 | g_signal_connect (priv->engine, "device-changed", |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 962 | G_CALLBACK (fu_util_update_device_changed_cb), priv); |
Mario Limonciello | 9eb66fe | 2018-08-10 11:32:44 -0500 | [diff] [blame] | 963 | |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 964 | /* install all the tasks */ |
Richard Hughes | dbd8c76 | 2018-06-15 20:31:40 +0100 | [diff] [blame] | 965 | if (!fu_engine_install_tasks (priv->engine, install_tasks, blob_cab, priv->flags, error)) |
| 966 | return FALSE; |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 967 | |
Mario Limonciello | 32241f4 | 2019-01-24 10:12:41 -0600 | [diff] [blame] | 968 | fu_util_display_current_message (priv); |
| 969 | |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 970 | /* we don't want to ask anything */ |
| 971 | if (priv->no_reboot_check) { |
| 972 | g_debug ("skipping reboot check"); |
| 973 | return TRUE; |
| 974 | } |
| 975 | |
Mario Limonciello | 3143bad | 2019-02-27 07:31:00 -0600 | [diff] [blame] | 976 | /* save the device state for other applications to see */ |
| 977 | if (!fu_util_save_current_state (priv, error)) |
| 978 | return FALSE; |
| 979 | |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 980 | /* success */ |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 981 | return fu_util_prompt_complete (priv->completion_flags, TRUE, error); |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 982 | } |
| 983 | |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 984 | static gboolean |
Mario Limonciello | fd73485 | 2019-08-01 16:41:42 -0500 | [diff] [blame] | 985 | fu_util_install_release (FuUtilPrivate *priv, FwupdRelease *rel, GError **error) |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 986 | { |
Mario Limonciello | fd73485 | 2019-08-01 16:41:42 -0500 | [diff] [blame] | 987 | FwupdRemote *remote; |
| 988 | const gchar *remote_id; |
| 989 | const gchar *uri_tmp; |
| 990 | g_auto(GStrv) argv = NULL; |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 991 | |
Mario Limonciello | fd73485 | 2019-08-01 16:41:42 -0500 | [diff] [blame] | 992 | uri_tmp = fwupd_release_get_uri (rel); |
| 993 | if (uri_tmp == NULL) { |
| 994 | g_set_error_literal (error, |
| 995 | FWUPD_ERROR, |
| 996 | FWUPD_ERROR_INVALID_FILE, |
| 997 | "release missing URI"); |
| 998 | return FALSE; |
| 999 | } |
| 1000 | remote_id = fwupd_release_get_remote_id (rel); |
| 1001 | if (remote_id == NULL) { |
| 1002 | g_set_error (error, |
| 1003 | FWUPD_ERROR, |
| 1004 | FWUPD_ERROR_INVALID_FILE, |
| 1005 | "failed to find remote for %s", |
| 1006 | uri_tmp); |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 1007 | return FALSE; |
Mario Limonciello | fd73485 | 2019-08-01 16:41:42 -0500 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | remote = fu_engine_get_remote_by_id (priv->engine, |
| 1011 | remote_id, |
| 1012 | error); |
| 1013 | if (remote == NULL) |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1014 | return FALSE; |
| 1015 | |
Mario Limonciello | fd73485 | 2019-08-01 16:41:42 -0500 | [diff] [blame] | 1016 | argv = g_new0 (gchar *, 2); |
| 1017 | /* local remotes have the firmware already */ |
| 1018 | if (fwupd_remote_get_kind (remote) == FWUPD_REMOTE_KIND_LOCAL) { |
| 1019 | const gchar *fn_cache = fwupd_remote_get_filename_cache (remote); |
| 1020 | g_autofree gchar *path = g_path_get_dirname (fn_cache); |
| 1021 | argv[0] = g_build_filename (path, uri_tmp, NULL); |
| 1022 | } else if (fwupd_remote_get_kind (remote) == FWUPD_REMOTE_KIND_DIRECTORY) { |
| 1023 | argv[0] = g_strdup (uri_tmp + 7); |
| 1024 | /* web remote, fu_util_install will download file */ |
| 1025 | } else { |
| 1026 | argv[0] = fwupd_remote_build_firmware_uri (remote, uri_tmp, error); |
| 1027 | } |
| 1028 | return fu_util_install (priv, argv, error); |
| 1029 | } |
| 1030 | |
| 1031 | static gboolean |
| 1032 | fu_util_update_all (FuUtilPrivate *priv, GError **error) |
| 1033 | { |
| 1034 | g_autoptr(GPtrArray) devices = NULL; |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 1035 | |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1036 | devices = fu_engine_get_devices (priv->engine, error); |
Mario Limonciello | 387bda4 | 2019-02-07 14:20:22 +0000 | [diff] [blame] | 1037 | if (devices == NULL) |
| 1038 | return FALSE; |
Richard Hughes | 0ef4720 | 2020-01-06 13:59:09 +0000 | [diff] [blame] | 1039 | fwupd_device_array_ensure_parents (devices); |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1040 | for (guint i = 0; i < devices->len; i++) { |
| 1041 | FwupdDevice *dev = g_ptr_array_index (devices, i); |
| 1042 | FwupdRelease *rel; |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1043 | const gchar *device_id; |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1044 | g_autoptr(GPtrArray) rels = NULL; |
| 1045 | g_autoptr(GError) error_local = NULL; |
| 1046 | |
| 1047 | if (!fu_util_is_interesting_device (dev)) |
| 1048 | continue; |
| 1049 | /* only show stuff that has metadata available */ |
Mario Limonciello | 27164b7 | 2020-02-17 23:19:36 -0600 | [diff] [blame] | 1050 | if (!fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_UPDATABLE)) |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1051 | continue; |
Mario Limonciello | 27164b7 | 2020-02-17 23:19:36 -0600 | [diff] [blame] | 1052 | if (!fwupd_device_has_flag (dev, FWUPD_DEVICE_FLAG_SUPPORTED)) { |
| 1053 | /* TRANSLATORS: message letting the user know no device upgrade available due to missing on LVFS |
| 1054 | * %1 is the device name */ |
| 1055 | g_autofree gchar *tmp = g_strdup_printf (_("• %s has no available firmware updates"), |
| 1056 | fwupd_device_get_name (dev)); |
| 1057 | g_printerr ("%s\n", tmp); |
| 1058 | continue; |
| 1059 | } |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 1060 | if (!fu_util_filter_device (priv, dev)) |
| 1061 | continue; |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1062 | |
| 1063 | device_id = fu_device_get_id (dev); |
| 1064 | rels = fu_engine_get_upgrades (priv->engine, device_id, &error_local); |
| 1065 | if (rels == NULL) { |
Mario Limonciello | 27164b7 | 2020-02-17 23:19:36 -0600 | [diff] [blame] | 1066 | /* TRANSLATORS: message letting the user know no device upgrade available |
| 1067 | * %1 is the device name */ |
| 1068 | g_autofree gchar *tmp = g_strdup_printf (_("• %s has the latest available firmware version"), |
| 1069 | fwupd_device_get_name (dev)); |
| 1070 | g_printerr ("%s\n", tmp); |
| 1071 | /* discard the actual reason from user, but leave for debugging */ |
| 1072 | g_debug ("%s", error_local->message); |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1073 | continue; |
| 1074 | } |
| 1075 | |
Mario Limonciello | 98b9516 | 2019-10-30 09:20:43 -0500 | [diff] [blame] | 1076 | if (!priv->no_safety_check) { |
| 1077 | if (!fu_util_prompt_warning (dev, |
| 1078 | fu_util_get_tree_title (priv), |
| 1079 | error)) |
| 1080 | return FALSE; |
| 1081 | } |
| 1082 | |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1083 | rel = g_ptr_array_index (rels, 0); |
Mario Limonciello | fd73485 | 2019-08-01 16:41:42 -0500 | [diff] [blame] | 1084 | if (!fu_util_install_release (priv, rel, &error_local)) { |
| 1085 | g_printerr ("%s\n", error_local->message); |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 1086 | continue; |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1087 | } |
Mario Limonciello | fd73485 | 2019-08-01 16:41:42 -0500 | [diff] [blame] | 1088 | fu_util_display_current_message (priv); |
| 1089 | } |
| 1090 | return TRUE; |
| 1091 | } |
| 1092 | |
| 1093 | static gboolean |
Mario Limonciello | 9917bb4 | 2020-04-20 13:41:27 -0500 | [diff] [blame] | 1094 | fu_util_update_by_id (FuUtilPrivate *priv, const gchar *id, GError **error) |
Mario Limonciello | fd73485 | 2019-08-01 16:41:42 -0500 | [diff] [blame] | 1095 | { |
| 1096 | FwupdRelease *rel; |
| 1097 | g_autoptr(FuDevice) dev = NULL; |
| 1098 | g_autoptr(GPtrArray) rels = NULL; |
| 1099 | |
Mario Limonciello | 9917bb4 | 2020-04-20 13:41:27 -0500 | [diff] [blame] | 1100 | /* do not allow a partial device-id, lookup GUIDs */ |
| 1101 | dev = fu_util_get_device (priv, id, error); |
Mario Limonciello | fd73485 | 2019-08-01 16:41:42 -0500 | [diff] [blame] | 1102 | if (dev == NULL) |
| 1103 | return FALSE; |
| 1104 | |
| 1105 | /* get the releases for this device and filter for validity */ |
Mario Limonciello | 9917bb4 | 2020-04-20 13:41:27 -0500 | [diff] [blame] | 1106 | rels = fu_engine_get_upgrades (priv->engine, fu_device_get_id (dev), error); |
Mario Limonciello | fd73485 | 2019-08-01 16:41:42 -0500 | [diff] [blame] | 1107 | if (rels == NULL) |
| 1108 | return FALSE; |
| 1109 | rel = g_ptr_array_index (rels, 0); |
| 1110 | if (!fu_util_install_release (priv, rel, error)) |
| 1111 | return FALSE; |
| 1112 | fu_util_display_current_message (priv); |
| 1113 | |
| 1114 | return TRUE; |
| 1115 | } |
| 1116 | |
| 1117 | static gboolean |
| 1118 | fu_util_update (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1119 | { |
Mario Limonciello | 0f109b0 | 2019-11-14 10:26:44 -0600 | [diff] [blame] | 1120 | if (priv->flags & FWUPD_INSTALL_FLAG_ALLOW_OLDER) { |
| 1121 | g_set_error_literal (error, |
| 1122 | FWUPD_ERROR, |
| 1123 | FWUPD_ERROR_INVALID_ARGS, |
| 1124 | "--allow-older is not supported for this command"); |
| 1125 | return FALSE; |
| 1126 | } |
| 1127 | |
| 1128 | if (priv->flags & FWUPD_INSTALL_FLAG_ALLOW_REINSTALL) { |
| 1129 | g_set_error_literal (error, |
| 1130 | FWUPD_ERROR, |
| 1131 | FWUPD_ERROR_INVALID_ARGS, |
| 1132 | "--allow-reinstall is not supported for this command"); |
| 1133 | return FALSE; |
| 1134 | } |
| 1135 | |
Mario Limonciello | fd73485 | 2019-08-01 16:41:42 -0500 | [diff] [blame] | 1136 | if (g_strv_length (values) > 1) { |
| 1137 | g_set_error_literal (error, |
| 1138 | FWUPD_ERROR, |
| 1139 | FWUPD_ERROR_INVALID_ARGS, |
| 1140 | "Invalid arguments"); |
| 1141 | return FALSE; |
| 1142 | } |
| 1143 | |
| 1144 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
| 1145 | return FALSE; |
| 1146 | |
| 1147 | priv->current_operation = FU_UTIL_OPERATION_UPDATE; |
| 1148 | g_signal_connect (priv->engine, "device-changed", |
| 1149 | G_CALLBACK (fu_util_update_device_changed_cb), priv); |
| 1150 | |
| 1151 | if (g_strv_length (values) == 1) { |
| 1152 | if (!fu_util_update_by_id (priv, values[0], error)) |
| 1153 | return FALSE; |
| 1154 | } else { |
| 1155 | if (!fu_util_update_all (priv, error)) |
| 1156 | return FALSE; |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1157 | } |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 1158 | |
| 1159 | /* we don't want to ask anything */ |
| 1160 | if (priv->no_reboot_check) { |
| 1161 | g_debug ("skipping reboot check"); |
| 1162 | return TRUE; |
| 1163 | } |
| 1164 | |
Mario Limonciello | 3143bad | 2019-02-27 07:31:00 -0600 | [diff] [blame] | 1165 | /* save the device state for other applications to see */ |
| 1166 | if (!fu_util_save_current_state (priv, error)) |
| 1167 | return FALSE; |
| 1168 | |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 1169 | return fu_util_prompt_complete (priv->completion_flags, TRUE, error); |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | static gboolean |
Filipe LaÃns | b2f377a | 2020-03-30 21:05:50 +0100 | [diff] [blame] | 1173 | fu_util_reinstall (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1174 | { |
| 1175 | g_autoptr(FwupdRelease) rel = NULL; |
| 1176 | g_autoptr(GPtrArray) rels = NULL; |
| 1177 | g_autoptr(FuDevice) dev = NULL; |
| 1178 | |
| 1179 | if (g_strv_length (values) != 1) { |
| 1180 | g_set_error_literal (error, |
| 1181 | FWUPD_ERROR, |
| 1182 | FWUPD_ERROR_INVALID_ARGS, |
| 1183 | "Invalid arguments"); |
| 1184 | return FALSE; |
| 1185 | } |
| 1186 | |
| 1187 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
| 1188 | return FALSE; |
| 1189 | |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 1190 | dev = fu_util_get_device (priv, values[0], error); |
Filipe LaÃns | b2f377a | 2020-03-30 21:05:50 +0100 | [diff] [blame] | 1191 | if (dev == NULL) |
| 1192 | return FALSE; |
| 1193 | |
| 1194 | /* try to lookup/match release from client */ |
| 1195 | rels = fu_engine_get_releases_for_device (priv->engine, dev, error); |
| 1196 | if (rels == NULL) |
| 1197 | return FALSE; |
| 1198 | |
| 1199 | for (guint j = 0; j < rels->len; j++) { |
| 1200 | FwupdRelease *rel_tmp = g_ptr_array_index (rels, j); |
| 1201 | if (fu_common_vercmp_full (fwupd_release_get_version (rel_tmp), |
| 1202 | fu_device_get_version (dev), |
| 1203 | fu_device_get_version_format (dev)) == 0) { |
| 1204 | rel = g_object_ref (rel_tmp); |
| 1205 | break; |
| 1206 | } |
| 1207 | } |
| 1208 | if (rel == NULL) { |
| 1209 | g_set_error (error, |
| 1210 | FWUPD_ERROR, |
| 1211 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1212 | "Unable to locate release for %s version %s", |
| 1213 | fu_device_get_name (dev), |
| 1214 | fu_device_get_version (dev)); |
| 1215 | return FALSE; |
| 1216 | } |
| 1217 | |
| 1218 | /* update the console if composite devices are also updated */ |
| 1219 | priv->current_operation = FU_UTIL_OPERATION_INSTALL; |
| 1220 | g_signal_connect (priv->engine, "device-changed", |
| 1221 | G_CALLBACK (fu_util_update_device_changed_cb), priv); |
| 1222 | priv->flags |= FWUPD_INSTALL_FLAG_ALLOW_REINSTALL; |
| 1223 | if (!fu_util_install_release (priv, rel, error)) |
| 1224 | return FALSE; |
| 1225 | fu_util_display_current_message (priv); |
| 1226 | |
| 1227 | /* we don't want to ask anything */ |
| 1228 | if (priv->no_reboot_check) { |
| 1229 | g_debug ("skipping reboot check"); |
| 1230 | return TRUE; |
| 1231 | } |
| 1232 | |
| 1233 | /* save the device state for other applications to see */ |
| 1234 | if (!fu_util_save_current_state (priv, error)) |
| 1235 | return FALSE; |
| 1236 | |
| 1237 | return fu_util_prompt_complete (priv->completion_flags, TRUE, error); |
| 1238 | } |
| 1239 | |
| 1240 | static gboolean |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1241 | fu_util_detach (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1242 | { |
| 1243 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | 2a679cd | 2018-09-04 21:13:23 +0100 | [diff] [blame] | 1244 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1245 | |
| 1246 | /* load engine */ |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 1247 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1248 | return FALSE; |
| 1249 | |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1250 | /* get device */ |
| 1251 | if (g_strv_length (values) >= 1) { |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 1252 | device = fu_util_get_device (priv, values[0], error); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1253 | if (device == NULL) |
| 1254 | return FALSE; |
| 1255 | } else { |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 1256 | device = fu_util_prompt_for_device (priv, NULL, error); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1257 | if (device == NULL) |
| 1258 | return FALSE; |
| 1259 | } |
| 1260 | |
| 1261 | /* run vfunc */ |
Richard Hughes | 2a679cd | 2018-09-04 21:13:23 +0100 | [diff] [blame] | 1262 | locker = fu_device_locker_new (device, error); |
| 1263 | if (locker == NULL) |
| 1264 | return FALSE; |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1265 | return fu_device_detach (device, error); |
| 1266 | } |
| 1267 | |
| 1268 | static gboolean |
| 1269 | fu_util_attach (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1270 | { |
| 1271 | g_autoptr(FuDevice) device = NULL; |
Richard Hughes | 2a679cd | 2018-09-04 21:13:23 +0100 | [diff] [blame] | 1272 | g_autoptr(FuDeviceLocker) locker = NULL; |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1273 | |
| 1274 | /* load engine */ |
Richard Hughes | c8cc77c | 2019-03-07 11:57:24 +0000 | [diff] [blame] | 1275 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1276 | return FALSE; |
| 1277 | |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1278 | /* get device */ |
| 1279 | if (g_strv_length (values) >= 1) { |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 1280 | device = fu_util_get_device (priv, values[0], error); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1281 | if (device == NULL) |
| 1282 | return FALSE; |
| 1283 | } else { |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 1284 | device = fu_util_prompt_for_device (priv, NULL, error); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1285 | if (device == NULL) |
| 1286 | return FALSE; |
| 1287 | } |
| 1288 | |
| 1289 | /* run vfunc */ |
Richard Hughes | 2a679cd | 2018-09-04 21:13:23 +0100 | [diff] [blame] | 1290 | locker = fu_device_locker_new (device, error); |
| 1291 | if (locker == NULL) |
| 1292 | return FALSE; |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 1293 | return fu_device_attach (device, error); |
| 1294 | } |
| 1295 | |
Richard Hughes | 1d894f1 | 2018-08-31 13:05:51 +0100 | [diff] [blame] | 1296 | static gboolean |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 1297 | fu_util_activate (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1298 | { |
| 1299 | gboolean has_pending = FALSE; |
| 1300 | g_autoptr(FuHistory) history = fu_history_new (); |
| 1301 | g_autoptr(GPtrArray) devices = NULL; |
| 1302 | |
| 1303 | /* check the history database before starting the daemon */ |
| 1304 | if (g_strv_length (values) == 0) { |
| 1305 | devices = fu_history_get_devices (history, error); |
| 1306 | if (devices == NULL) |
| 1307 | return FALSE; |
| 1308 | } else if (g_strv_length (values) == 1) { |
| 1309 | FuDevice *device; |
| 1310 | device = fu_history_get_device_by_id (history, values[0], error); |
| 1311 | if (device == NULL) |
| 1312 | return FALSE; |
| 1313 | devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); |
| 1314 | g_ptr_array_add (devices, device); |
| 1315 | } else { |
| 1316 | g_set_error_literal (error, |
| 1317 | FWUPD_ERROR, |
| 1318 | FWUPD_ERROR_INVALID_ARGS, |
| 1319 | "Invalid arguments"); |
| 1320 | return FALSE; |
| 1321 | } |
| 1322 | |
| 1323 | /* nothing to do */ |
| 1324 | for (guint i = 0; i < devices->len; i++) { |
| 1325 | FuDevice *dev = g_ptr_array_index (devices, i); |
| 1326 | if (fu_device_has_flag (dev, FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION)) { |
| 1327 | fu_engine_add_plugin_filter (priv->engine, |
| 1328 | fu_device_get_plugin (dev)); |
| 1329 | has_pending = TRUE; |
| 1330 | } |
| 1331 | } |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 1332 | |
dkadioglu | 1db7e98 | 2019-12-04 21:13:21 +0100 | [diff] [blame] | 1333 | if (!has_pending) { |
| 1334 | g_printerr ("No firmware to activate\n"); |
| 1335 | return TRUE; |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | /* load engine */ |
Richard Hughes | 88dc0f4 | 2019-03-07 11:58:11 +0000 | [diff] [blame] | 1339 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_READONLY_FS, error)) |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 1340 | return FALSE; |
| 1341 | |
| 1342 | /* activate anything with _NEEDS_ACTIVATION */ |
| 1343 | for (guint i = 0; i < devices->len; i++) { |
| 1344 | FuDevice *device = g_ptr_array_index (devices, i); |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 1345 | if (!fu_util_filter_device (priv, FWUPD_DEVICE (device))) |
| 1346 | continue; |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 1347 | if (!fu_device_has_flag (device, FWUPD_DEVICE_FLAG_NEEDS_ACTIVATION)) |
| 1348 | continue; |
| 1349 | /* TRANSLATORS: shown when shutting down to switch to the new version */ |
| 1350 | g_print ("%s %s…\n", _("Activating firmware update"), fu_device_get_name (device)); |
| 1351 | if (!fu_engine_activate (priv->engine, fu_device_get_id (device), error)) |
| 1352 | return FALSE; |
| 1353 | } |
| 1354 | |
| 1355 | return TRUE; |
| 1356 | } |
| 1357 | |
| 1358 | static gboolean |
Richard Hughes | 1d894f1 | 2018-08-31 13:05:51 +0100 | [diff] [blame] | 1359 | fu_util_hwids (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1360 | { |
| 1361 | g_autoptr(FuSmbios) smbios = fu_smbios_new (); |
| 1362 | g_autoptr(FuHwids) hwids = fu_hwids_new (); |
| 1363 | const gchar *hwid_keys[] = { |
| 1364 | FU_HWIDS_KEY_BIOS_VENDOR, |
| 1365 | FU_HWIDS_KEY_BIOS_VERSION, |
| 1366 | FU_HWIDS_KEY_BIOS_MAJOR_RELEASE, |
| 1367 | FU_HWIDS_KEY_BIOS_MINOR_RELEASE, |
| 1368 | FU_HWIDS_KEY_MANUFACTURER, |
| 1369 | FU_HWIDS_KEY_FAMILY, |
| 1370 | FU_HWIDS_KEY_PRODUCT_NAME, |
| 1371 | FU_HWIDS_KEY_PRODUCT_SKU, |
| 1372 | FU_HWIDS_KEY_ENCLOSURE_KIND, |
| 1373 | FU_HWIDS_KEY_BASEBOARD_MANUFACTURER, |
| 1374 | FU_HWIDS_KEY_BASEBOARD_PRODUCT, |
| 1375 | NULL }; |
| 1376 | |
| 1377 | /* read DMI data */ |
| 1378 | if (g_strv_length (values) == 0) { |
| 1379 | if (!fu_smbios_setup (smbios, error)) |
| 1380 | return FALSE; |
| 1381 | } else if (g_strv_length (values) == 1) { |
| 1382 | if (!fu_smbios_setup_from_file (smbios, values[0], error)) |
| 1383 | return FALSE; |
| 1384 | } else { |
| 1385 | g_set_error_literal (error, |
| 1386 | FWUPD_ERROR, |
| 1387 | FWUPD_ERROR_INVALID_ARGS, |
| 1388 | "Invalid arguments"); |
| 1389 | return FALSE; |
| 1390 | } |
| 1391 | if (!fu_hwids_setup (hwids, smbios, error)) |
| 1392 | return FALSE; |
| 1393 | |
| 1394 | /* show debug output */ |
| 1395 | g_print ("Computer Information\n"); |
| 1396 | g_print ("--------------------\n"); |
| 1397 | for (guint i = 0; hwid_keys[i] != NULL; i++) { |
| 1398 | const gchar *tmp = fu_hwids_get_value (hwids, hwid_keys[i]); |
| 1399 | if (tmp == NULL) |
| 1400 | continue; |
| 1401 | if (g_strcmp0 (hwid_keys[i], FU_HWIDS_KEY_BIOS_MAJOR_RELEASE) == 0 || |
| 1402 | g_strcmp0 (hwid_keys[i], FU_HWIDS_KEY_BIOS_MINOR_RELEASE) == 0) { |
| 1403 | guint64 val = g_ascii_strtoull (tmp, NULL, 16); |
| 1404 | g_print ("%s: %" G_GUINT64_FORMAT "\n", hwid_keys[i], val); |
| 1405 | } else { |
| 1406 | g_print ("%s: %s\n", hwid_keys[i], tmp); |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | /* show GUIDs */ |
| 1411 | g_print ("\nHardware IDs\n"); |
| 1412 | g_print ("------------\n"); |
| 1413 | for (guint i = 0; i < 15; i++) { |
| 1414 | const gchar *keys = NULL; |
| 1415 | g_autofree gchar *guid = NULL; |
| 1416 | g_autofree gchar *key = NULL; |
| 1417 | g_autofree gchar *keys_str = NULL; |
| 1418 | g_auto(GStrv) keysv = NULL; |
| 1419 | g_autoptr(GError) error_local = NULL; |
| 1420 | |
| 1421 | /* get the GUID */ |
| 1422 | key = g_strdup_printf ("HardwareID-%u", i); |
| 1423 | keys = fu_hwids_get_replace_keys (hwids, key); |
| 1424 | guid = fu_hwids_get_guid (hwids, key, &error_local); |
| 1425 | if (guid == NULL) { |
| 1426 | g_print ("%s\n", error_local->message); |
| 1427 | continue; |
| 1428 | } |
| 1429 | |
| 1430 | /* show what makes up the GUID */ |
| 1431 | keysv = g_strsplit (keys, "&", -1); |
| 1432 | keys_str = g_strjoinv (" + ", keysv); |
| 1433 | g_print ("{%s} <- %s\n", guid, keys_str); |
| 1434 | } |
| 1435 | |
| 1436 | return TRUE; |
| 1437 | } |
| 1438 | |
Mario Limonciello | f6d01b1 | 2018-10-18 12:57:10 -0500 | [diff] [blame] | 1439 | static gboolean |
| 1440 | fu_util_firmware_builder (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1441 | { |
| 1442 | const gchar *script_fn = "startup.sh"; |
| 1443 | const gchar *output_fn = "firmware.bin"; |
| 1444 | g_autoptr(GBytes) archive_blob = NULL; |
| 1445 | g_autoptr(GBytes) firmware_blob = NULL; |
| 1446 | if (g_strv_length (values) < 2) { |
| 1447 | g_set_error_literal (error, |
| 1448 | FWUPD_ERROR, |
| 1449 | FWUPD_ERROR_INVALID_ARGS, |
| 1450 | "Invalid arguments"); |
| 1451 | return FALSE; |
| 1452 | } |
| 1453 | archive_blob = fu_common_get_contents_bytes (values[0], error); |
| 1454 | if (archive_blob == NULL) |
| 1455 | return FALSE; |
| 1456 | if (g_strv_length (values) > 2) |
| 1457 | script_fn = values[2]; |
| 1458 | if (g_strv_length (values) > 3) |
| 1459 | output_fn = values[3]; |
| 1460 | firmware_blob = fu_common_firmware_builder (archive_blob, script_fn, output_fn, error); |
| 1461 | if (firmware_blob == NULL) |
| 1462 | return FALSE; |
| 1463 | return fu_common_set_contents_bytes (values[1], firmware_blob, error); |
| 1464 | } |
| 1465 | |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 1466 | static gboolean |
| 1467 | fu_util_self_sign (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1468 | { |
| 1469 | g_autofree gchar *sig = NULL; |
| 1470 | |
| 1471 | /* check args */ |
| 1472 | if (g_strv_length (values) != 1) { |
| 1473 | g_set_error_literal (error, |
| 1474 | FWUPD_ERROR, |
| 1475 | FWUPD_ERROR_INVALID_ARGS, |
| 1476 | "Invalid arguments: value expected"); |
| 1477 | return FALSE; |
| 1478 | } |
| 1479 | |
| 1480 | /* start engine */ |
| 1481 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
| 1482 | return FALSE; |
| 1483 | sig = fu_engine_self_sign (priv->engine, values[0], |
Richard Hughes | d5aab65 | 2020-02-25 12:47:50 +0000 | [diff] [blame] | 1484 | JCAT_SIGN_FLAG_ADD_TIMESTAMP | |
| 1485 | JCAT_SIGN_FLAG_ADD_CERT, error); |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 1486 | if (sig == NULL) |
| 1487 | return FALSE; |
| 1488 | g_print ("%s\n", sig); |
| 1489 | return TRUE; |
| 1490 | } |
| 1491 | |
Mario Limonciello | 62f8486 | 2018-10-18 13:15:23 -0500 | [diff] [blame] | 1492 | static void |
| 1493 | fu_util_device_added_cb (FwupdClient *client, |
| 1494 | FwupdDevice *device, |
| 1495 | gpointer user_data) |
| 1496 | { |
Mario Limonciello | fee8f49 | 2019-08-18 12:16:07 -0500 | [diff] [blame] | 1497 | g_autofree gchar *tmp = fu_util_device_to_string (device, 0); |
Mario Limonciello | 62f8486 | 2018-10-18 13:15:23 -0500 | [diff] [blame] | 1498 | /* TRANSLATORS: this is when a device is hotplugged */ |
| 1499 | g_print ("%s\n%s", _("Device added:"), tmp); |
| 1500 | } |
| 1501 | |
| 1502 | static void |
| 1503 | fu_util_device_removed_cb (FwupdClient *client, |
| 1504 | FwupdDevice *device, |
| 1505 | gpointer user_data) |
| 1506 | { |
Mario Limonciello | fee8f49 | 2019-08-18 12:16:07 -0500 | [diff] [blame] | 1507 | g_autofree gchar *tmp = fu_util_device_to_string (device, 0); |
Mario Limonciello | 62f8486 | 2018-10-18 13:15:23 -0500 | [diff] [blame] | 1508 | /* TRANSLATORS: this is when a device is hotplugged */ |
| 1509 | g_print ("%s\n%s", _("Device removed:"), tmp); |
| 1510 | } |
| 1511 | |
| 1512 | static void |
| 1513 | fu_util_device_changed_cb (FwupdClient *client, |
| 1514 | FwupdDevice *device, |
| 1515 | gpointer user_data) |
| 1516 | { |
Mario Limonciello | fee8f49 | 2019-08-18 12:16:07 -0500 | [diff] [blame] | 1517 | g_autofree gchar *tmp = fu_util_device_to_string (device, 0); |
Mario Limonciello | 62f8486 | 2018-10-18 13:15:23 -0500 | [diff] [blame] | 1518 | /* TRANSLATORS: this is when a device has been updated */ |
| 1519 | g_print ("%s\n%s", _("Device changed:"), tmp); |
| 1520 | } |
| 1521 | |
| 1522 | static void |
| 1523 | fu_util_changed_cb (FwupdClient *client, gpointer user_data) |
| 1524 | { |
| 1525 | /* TRANSLATORS: this is when the daemon state changes */ |
| 1526 | g_print ("%s\n", _("Changed")); |
| 1527 | } |
| 1528 | |
| 1529 | static gboolean |
| 1530 | fu_util_monitor (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1531 | { |
| 1532 | g_autoptr(FwupdClient) client = fwupd_client_new (); |
| 1533 | |
| 1534 | /* get all the devices */ |
| 1535 | if (!fwupd_client_connect (client, priv->cancellable, error)) |
| 1536 | return FALSE; |
| 1537 | |
| 1538 | /* watch for any hotplugged device */ |
| 1539 | g_signal_connect (client, "changed", |
| 1540 | G_CALLBACK (fu_util_changed_cb), priv); |
| 1541 | g_signal_connect (client, "device-added", |
| 1542 | G_CALLBACK (fu_util_device_added_cb), priv); |
| 1543 | g_signal_connect (client, "device-removed", |
| 1544 | G_CALLBACK (fu_util_device_removed_cb), priv); |
| 1545 | g_signal_connect (client, "device-changed", |
| 1546 | G_CALLBACK (fu_util_device_changed_cb), priv); |
| 1547 | g_signal_connect (priv->cancellable, "cancelled", |
| 1548 | G_CALLBACK (fu_util_cancelled_cb), priv); |
| 1549 | g_main_loop_run (priv->loop); |
| 1550 | return TRUE; |
| 1551 | } |
| 1552 | |
Richard Hughes | 1568449 | 2019-03-15 16:27:50 +0000 | [diff] [blame] | 1553 | static gboolean |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 1554 | fu_util_get_firmware_types (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1555 | { |
| 1556 | g_autoptr(GPtrArray) firmware_types = NULL; |
| 1557 | |
| 1558 | /* load engine */ |
| 1559 | if (!fu_engine_load (priv->engine, FU_ENGINE_LOAD_FLAG_NO_ENUMERATE, error)) |
| 1560 | return FALSE; |
| 1561 | |
| 1562 | firmware_types = fu_engine_get_firmware_gtype_ids (priv->engine); |
| 1563 | for (guint i = 0; i < firmware_types->len; i++) { |
| 1564 | const gchar *id = g_ptr_array_index (firmware_types, i); |
| 1565 | g_print ("%s\n", id); |
| 1566 | } |
| 1567 | if (firmware_types->len == 0) { |
| 1568 | /* TRANSLATORS: nothing found */ |
| 1569 | g_print ("%s\n", _("No firmware IDs found")); |
| 1570 | return TRUE; |
| 1571 | } |
| 1572 | |
| 1573 | return TRUE; |
| 1574 | } |
| 1575 | |
| 1576 | static gchar * |
| 1577 | fu_util_prompt_for_firmware_type (FuUtilPrivate *priv, GError **error) |
| 1578 | { |
| 1579 | g_autoptr(GPtrArray) firmware_types = NULL; |
| 1580 | guint idx; |
| 1581 | firmware_types = fu_engine_get_firmware_gtype_ids (priv->engine); |
| 1582 | |
| 1583 | /* TRANSLATORS: get interactive prompt */ |
| 1584 | g_print ("%s\n", _("Choose a firmware type:")); |
| 1585 | /* TRANSLATORS: this is to abort the interactive prompt */ |
| 1586 | g_print ("0.\t%s\n", _("Cancel")); |
| 1587 | for (guint i = 0; i < firmware_types->len; i++) { |
| 1588 | const gchar *id = g_ptr_array_index (firmware_types, i); |
| 1589 | g_print ("%u.\t%s\n", i + 1, id); |
| 1590 | } |
| 1591 | idx = fu_util_prompt_for_number (firmware_types->len); |
| 1592 | if (idx == 0) { |
| 1593 | g_set_error_literal (error, |
| 1594 | FWUPD_ERROR, |
| 1595 | FWUPD_ERROR_NOTHING_TO_DO, |
| 1596 | "Request canceled"); |
| 1597 | return NULL; |
| 1598 | } |
| 1599 | |
| 1600 | return g_strdup (g_ptr_array_index (firmware_types, idx - 1)); |
| 1601 | } |
| 1602 | |
| 1603 | static gboolean |
| 1604 | fu_util_firmware_parse (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1605 | { |
| 1606 | GType gtype; |
| 1607 | g_autoptr(GBytes) blob = NULL; |
| 1608 | g_autoptr(FuFirmware) firmware = NULL; |
| 1609 | g_autofree gchar *firmware_type = NULL; |
| 1610 | g_autofree gchar *str = NULL; |
| 1611 | |
| 1612 | /* check args */ |
| 1613 | if (g_strv_length (values) == 0 || g_strv_length (values) > 2) { |
| 1614 | g_set_error_literal (error, |
| 1615 | FWUPD_ERROR, |
| 1616 | FWUPD_ERROR_INVALID_ARGS, |
| 1617 | "Invalid arguments: filename required"); |
| 1618 | return FALSE; |
| 1619 | } |
| 1620 | |
| 1621 | if (g_strv_length (values) == 2) |
| 1622 | firmware_type = g_strdup (values[1]); |
| 1623 | |
| 1624 | /* load file */ |
| 1625 | blob = fu_common_get_contents_bytes (values[0], error); |
| 1626 | if (blob == NULL) |
| 1627 | return FALSE; |
| 1628 | |
| 1629 | /* load engine */ |
| 1630 | if (!fu_engine_load (priv->engine, FU_ENGINE_LOAD_FLAG_NO_ENUMERATE, error)) |
| 1631 | return FALSE; |
| 1632 | |
| 1633 | /* find the GType to use */ |
| 1634 | if (firmware_type == NULL) |
| 1635 | firmware_type = fu_util_prompt_for_firmware_type (priv, error); |
| 1636 | if (firmware_type == NULL) |
| 1637 | return FALSE; |
| 1638 | gtype = fu_engine_get_firmware_gtype_by_id (priv->engine, firmware_type); |
| 1639 | if (gtype == G_TYPE_INVALID) { |
| 1640 | g_set_error (error, |
| 1641 | G_IO_ERROR, |
| 1642 | G_IO_ERROR_NOT_FOUND, |
| 1643 | "GType %s not supported", firmware_type); |
| 1644 | return FALSE; |
| 1645 | } |
| 1646 | firmware = g_object_new (gtype, NULL); |
| 1647 | if (!fu_firmware_parse (firmware, blob, priv->flags, error)) |
| 1648 | return FALSE; |
| 1649 | str = fu_firmware_to_string (firmware); |
| 1650 | g_print ("%s", str); |
| 1651 | return TRUE; |
| 1652 | } |
| 1653 | |
| 1654 | static gboolean |
Richard Hughes | bca63ed | 2020-03-09 20:20:03 +0000 | [diff] [blame] | 1655 | fu_util_firmware_convert (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1656 | { |
| 1657 | GType gtype_dst; |
| 1658 | GType gtype_src; |
| 1659 | g_autofree gchar *firmware_type_dst = NULL; |
| 1660 | g_autofree gchar *firmware_type_src = NULL; |
| 1661 | g_autofree gchar *str_dst = NULL; |
| 1662 | g_autofree gchar *str_src = NULL; |
| 1663 | g_autoptr(FuFirmware) firmware_dst = NULL; |
| 1664 | g_autoptr(FuFirmware) firmware_src = NULL; |
| 1665 | g_autoptr(GBytes) blob_dst = NULL; |
| 1666 | g_autoptr(GBytes) blob_src = NULL; |
| 1667 | g_autoptr(GPtrArray) images = NULL; |
| 1668 | |
| 1669 | /* check args */ |
| 1670 | if (g_strv_length (values) < 2 || g_strv_length (values) > 4) { |
| 1671 | g_set_error_literal (error, |
| 1672 | FWUPD_ERROR, |
| 1673 | FWUPD_ERROR_INVALID_ARGS, |
| 1674 | "Invalid arguments: filename required"); |
| 1675 | return FALSE; |
| 1676 | } |
| 1677 | |
| 1678 | if (g_strv_length (values) > 2) |
| 1679 | firmware_type_src = g_strdup (values[2]); |
| 1680 | if (g_strv_length (values) > 3) |
| 1681 | firmware_type_dst = g_strdup (values[3]); |
| 1682 | |
| 1683 | /* load file */ |
| 1684 | blob_src = fu_common_get_contents_bytes (values[0], error); |
| 1685 | if (blob_src == NULL) |
| 1686 | return FALSE; |
| 1687 | |
| 1688 | /* load engine */ |
| 1689 | if (!fu_engine_load (priv->engine, FU_ENGINE_LOAD_FLAG_NO_ENUMERATE, error)) |
| 1690 | return FALSE; |
| 1691 | |
| 1692 | /* find the GType to use */ |
| 1693 | if (firmware_type_src == NULL) |
| 1694 | firmware_type_src = fu_util_prompt_for_firmware_type (priv, error); |
| 1695 | if (firmware_type_src == NULL) |
| 1696 | return FALSE; |
| 1697 | if (firmware_type_dst == NULL) |
| 1698 | firmware_type_dst = fu_util_prompt_for_firmware_type (priv, error); |
| 1699 | if (firmware_type_dst == NULL) |
| 1700 | return FALSE; |
| 1701 | gtype_src = fu_engine_get_firmware_gtype_by_id (priv->engine, firmware_type_src); |
| 1702 | if (gtype_src == G_TYPE_INVALID) { |
| 1703 | g_set_error (error, |
| 1704 | G_IO_ERROR, |
| 1705 | G_IO_ERROR_NOT_FOUND, |
| 1706 | "GType %s not supported", firmware_type_src); |
| 1707 | return FALSE; |
| 1708 | } |
| 1709 | gtype_dst = fu_engine_get_firmware_gtype_by_id (priv->engine, firmware_type_dst); |
| 1710 | if (gtype_dst == G_TYPE_INVALID) { |
| 1711 | g_set_error (error, |
| 1712 | G_IO_ERROR, |
| 1713 | G_IO_ERROR_NOT_FOUND, |
| 1714 | "GType %s not supported", firmware_type_dst); |
| 1715 | return FALSE; |
| 1716 | } |
| 1717 | firmware_src = g_object_new (gtype_src, NULL); |
| 1718 | if (!fu_firmware_parse (firmware_src, blob_src, priv->flags, error)) |
| 1719 | return FALSE; |
| 1720 | str_src = fu_firmware_to_string (firmware_src); |
| 1721 | g_print ("%s", str_src); |
| 1722 | |
| 1723 | /* copy images */ |
| 1724 | firmware_dst = g_object_new (gtype_dst, NULL); |
| 1725 | images = fu_firmware_get_images (firmware_src); |
| 1726 | for (guint i = 0; i < images->len; i++) { |
| 1727 | FuFirmwareImage *img = g_ptr_array_index (images, i); |
| 1728 | fu_firmware_add_image (firmware_dst, img); |
| 1729 | } |
| 1730 | |
| 1731 | /* write new file */ |
| 1732 | blob_dst = fu_firmware_write (firmware_dst, error); |
| 1733 | if (blob_dst == NULL) |
| 1734 | return FALSE; |
| 1735 | if (!fu_common_set_contents_bytes (values[1], blob_dst, error)) |
| 1736 | return FALSE; |
| 1737 | str_dst = fu_firmware_to_string (firmware_dst); |
| 1738 | g_print ("%s", str_dst); |
| 1739 | |
| 1740 | /* success */ |
| 1741 | return TRUE; |
| 1742 | } |
| 1743 | |
| 1744 | static gboolean |
Richard Hughes | 1568449 | 2019-03-15 16:27:50 +0000 | [diff] [blame] | 1745 | fu_util_verify_update (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1746 | { |
| 1747 | g_autofree gchar *str = NULL; |
| 1748 | g_autoptr(FuDevice) dev = NULL; |
| 1749 | |
| 1750 | /* load engine */ |
| 1751 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
| 1752 | return FALSE; |
| 1753 | |
| 1754 | /* get device */ |
| 1755 | if (g_strv_length (values) == 1) { |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 1756 | dev = fu_util_get_device (priv, values[1], error); |
Richard Hughes | 1568449 | 2019-03-15 16:27:50 +0000 | [diff] [blame] | 1757 | if (dev == NULL) |
| 1758 | return FALSE; |
| 1759 | } else { |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 1760 | dev = fu_util_prompt_for_device (priv, NULL, error); |
Richard Hughes | 1568449 | 2019-03-15 16:27:50 +0000 | [diff] [blame] | 1761 | if (dev == NULL) |
| 1762 | return FALSE; |
| 1763 | } |
| 1764 | |
| 1765 | /* add checksums */ |
| 1766 | if (!fu_engine_verify_update (priv->engine, fu_device_get_id (dev), error)) |
| 1767 | return FALSE; |
| 1768 | |
| 1769 | /* show checksums */ |
| 1770 | str = fu_device_to_string (dev); |
| 1771 | g_print ("%s\n", str); |
| 1772 | return TRUE; |
| 1773 | } |
| 1774 | |
Mario Limonciello | fe59394 | 2019-04-03 13:48:52 -0500 | [diff] [blame] | 1775 | static gboolean |
| 1776 | fu_util_get_history (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1777 | { |
| 1778 | g_autoptr(GPtrArray) devices = NULL; |
Mario Limonciello | 4250d9d | 2019-08-29 09:53:44 -0500 | [diff] [blame] | 1779 | g_autoptr(GNode) root = g_node_new (NULL); |
Mario Limonciello | dc9a1a8 | 2020-02-20 14:20:20 -0600 | [diff] [blame] | 1780 | g_autofree gchar *title = NULL; |
Mario Limonciello | fe59394 | 2019-04-03 13:48:52 -0500 | [diff] [blame] | 1781 | |
| 1782 | /* load engine */ |
| 1783 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
| 1784 | return FALSE; |
Mario Limonciello | dc9a1a8 | 2020-02-20 14:20:20 -0600 | [diff] [blame] | 1785 | title = fu_util_get_tree_title (priv); |
Mario Limonciello | fe59394 | 2019-04-03 13:48:52 -0500 | [diff] [blame] | 1786 | |
| 1787 | /* get all devices from the history database */ |
| 1788 | devices = fu_engine_get_history (priv->engine, error); |
| 1789 | if (devices == NULL) |
| 1790 | return FALSE; |
| 1791 | |
| 1792 | /* show each device */ |
| 1793 | for (guint i = 0; i < devices->len; i++) { |
Mario Limonciello | ce94d16 | 2019-09-20 13:37:36 -0500 | [diff] [blame] | 1794 | g_autoptr(GPtrArray) rels = NULL; |
Mario Limonciello | fe59394 | 2019-04-03 13:48:52 -0500 | [diff] [blame] | 1795 | FwupdDevice *dev = g_ptr_array_index (devices, i); |
Mario Limonciello | 3be596b | 2019-09-20 10:10:08 -0500 | [diff] [blame] | 1796 | FwupdRelease *rel; |
Mario Limonciello | ce94d16 | 2019-09-20 13:37:36 -0500 | [diff] [blame] | 1797 | const gchar *remote; |
Mario Limonciello | 3be596b | 2019-09-20 10:10:08 -0500 | [diff] [blame] | 1798 | GNode *child; |
Mario Limonciello | ce94d16 | 2019-09-20 13:37:36 -0500 | [diff] [blame] | 1799 | |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 1800 | if (!fu_util_filter_device (priv, dev)) |
| 1801 | continue; |
Mario Limonciello | 3be596b | 2019-09-20 10:10:08 -0500 | [diff] [blame] | 1802 | child = g_node_append_data (root, dev); |
| 1803 | |
| 1804 | rel = fwupd_device_get_release_default (dev); |
Mario Limonciello | ce94d16 | 2019-09-20 13:37:36 -0500 | [diff] [blame] | 1805 | if (rel == NULL) |
| 1806 | continue; |
| 1807 | remote = fwupd_release_get_remote_id (rel); |
| 1808 | |
| 1809 | /* doesn't actually map to remote */ |
| 1810 | if (remote == NULL) { |
Mario Limonciello | 3be596b | 2019-09-20 10:10:08 -0500 | [diff] [blame] | 1811 | g_node_append_data (child, rel); |
Mario Limonciello | ce94d16 | 2019-09-20 13:37:36 -0500 | [diff] [blame] | 1812 | continue; |
| 1813 | } |
| 1814 | |
| 1815 | /* try to lookup releases from client */ |
| 1816 | rels = fu_engine_get_releases (priv->engine, fwupd_device_get_id (dev), error); |
| 1817 | if (rels == NULL) |
| 1818 | return FALSE; |
| 1819 | |
| 1820 | /* map to a release in client */ |
| 1821 | for (guint j = 0; j < rels->len; j++) { |
| 1822 | FwupdRelease *rel2 = g_ptr_array_index (rels, j); |
| 1823 | if (g_strcmp0 (remote, |
| 1824 | fwupd_release_get_remote_id (rel2)) != 0) |
| 1825 | continue; |
| 1826 | if (g_strcmp0 (fwupd_release_get_version (rel), |
| 1827 | fwupd_release_get_version (rel2)) != 0) |
| 1828 | continue; |
| 1829 | g_node_append_data (child, g_object_ref (rel2)); |
| 1830 | rel = NULL; |
| 1831 | break; |
| 1832 | } |
| 1833 | |
| 1834 | /* didn't match anything */ |
| 1835 | if (rels->len == 0 || rel != NULL) { |
| 1836 | g_node_append_data (child, rel); |
| 1837 | continue; |
| 1838 | } |
Mario Limonciello | 3be596b | 2019-09-20 10:10:08 -0500 | [diff] [blame] | 1839 | |
Mario Limonciello | fe59394 | 2019-04-03 13:48:52 -0500 | [diff] [blame] | 1840 | } |
Mario Limonciello | 20cc9ee | 2019-09-05 07:27:26 -0500 | [diff] [blame] | 1841 | fu_util_print_tree (root, title); |
Mario Limonciello | fe59394 | 2019-04-03 13:48:52 -0500 | [diff] [blame] | 1842 | |
| 1843 | return TRUE; |
| 1844 | } |
| 1845 | |
Richard Hughes | fd7e994 | 2020-01-17 14:09:13 +0000 | [diff] [blame] | 1846 | static gboolean |
Richard Hughes | 4959baa | 2020-01-17 14:33:00 +0000 | [diff] [blame] | 1847 | fu_util_refresh_remote (FuUtilPrivate *priv, FwupdRemote *remote, GError **error) |
| 1848 | { |
| 1849 | g_autofree gchar *fn_raw = NULL; |
| 1850 | g_autofree gchar *fn_sig = NULL; |
| 1851 | g_autoptr(GBytes) bytes_raw = NULL; |
| 1852 | g_autoptr(GBytes) bytes_sig = NULL; |
| 1853 | |
| 1854 | /* payload */ |
| 1855 | fn_raw = fu_util_get_user_cache_path (fwupd_remote_get_metadata_uri (remote)); |
| 1856 | if (!fu_common_mkdir_parent (fn_raw, error)) |
| 1857 | return FALSE; |
| 1858 | if (!fu_util_download_out_of_process (fwupd_remote_get_metadata_uri (remote), |
| 1859 | fn_raw, error)) |
| 1860 | return FALSE; |
| 1861 | bytes_raw = fu_common_get_contents_bytes (fn_raw, error); |
| 1862 | if (bytes_raw == NULL) |
| 1863 | return FALSE; |
| 1864 | |
| 1865 | /* signature */ |
| 1866 | fn_sig = fu_util_get_user_cache_path (fwupd_remote_get_metadata_uri_sig (remote)); |
| 1867 | if (!fu_util_download_out_of_process (fwupd_remote_get_metadata_uri_sig (remote), |
| 1868 | fn_sig, error)) |
| 1869 | return FALSE; |
| 1870 | bytes_sig = fu_common_get_contents_bytes (fn_sig, error); |
| 1871 | if (bytes_sig == NULL) |
| 1872 | return FALSE; |
| 1873 | |
| 1874 | /* send to daemon */ |
| 1875 | g_debug ("updating %s", fwupd_remote_get_id (remote)); |
| 1876 | return fu_engine_update_metadata_bytes (priv->engine, |
| 1877 | fwupd_remote_get_id (remote), |
| 1878 | bytes_raw, |
| 1879 | bytes_sig, |
| 1880 | error); |
| 1881 | |
| 1882 | } |
| 1883 | |
| 1884 | static gboolean |
| 1885 | fu_util_refresh (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1886 | { |
| 1887 | g_autoptr(GPtrArray) remotes = NULL; |
| 1888 | |
| 1889 | /* load engine */ |
| 1890 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
| 1891 | return FALSE; |
| 1892 | |
| 1893 | /* download new metadata */ |
| 1894 | remotes = fu_engine_get_remotes (priv->engine, error); |
| 1895 | if (remotes == NULL) |
| 1896 | return FALSE; |
| 1897 | for (guint i = 0; i < remotes->len; i++) { |
| 1898 | FwupdRemote *remote = g_ptr_array_index (remotes, i); |
| 1899 | if (!fwupd_remote_get_enabled (remote)) |
| 1900 | continue; |
| 1901 | if (fwupd_remote_get_kind (remote) != FWUPD_REMOTE_KIND_DOWNLOAD) |
| 1902 | continue; |
| 1903 | if (!fu_util_refresh_remote (priv, remote, error)) |
| 1904 | return FALSE; |
| 1905 | } |
| 1906 | return TRUE; |
| 1907 | } |
| 1908 | |
| 1909 | static gboolean |
Richard Hughes | fd7e994 | 2020-01-17 14:09:13 +0000 | [diff] [blame] | 1910 | fu_util_get_remotes (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1911 | { |
| 1912 | g_autoptr(GNode) root = g_node_new (NULL); |
| 1913 | g_autoptr(GPtrArray) remotes = NULL; |
Mario Limonciello | dc9a1a8 | 2020-02-20 14:20:20 -0600 | [diff] [blame] | 1914 | g_autofree gchar *title = NULL; |
Richard Hughes | fd7e994 | 2020-01-17 14:09:13 +0000 | [diff] [blame] | 1915 | |
| 1916 | /* load engine */ |
| 1917 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
| 1918 | return FALSE; |
Mario Limonciello | dc9a1a8 | 2020-02-20 14:20:20 -0600 | [diff] [blame] | 1919 | title = fu_util_get_tree_title (priv); |
Richard Hughes | fd7e994 | 2020-01-17 14:09:13 +0000 | [diff] [blame] | 1920 | |
| 1921 | /* list remotes */ |
| 1922 | remotes = fu_engine_get_remotes (priv->engine, error); |
| 1923 | if (remotes == NULL) |
| 1924 | return FALSE; |
| 1925 | if (remotes->len == 0) { |
| 1926 | g_set_error_literal (error, |
| 1927 | FWUPD_ERROR, |
| 1928 | FWUPD_ERROR_NOTHING_TO_DO, |
| 1929 | "no remotes available"); |
| 1930 | return FALSE; |
| 1931 | } |
| 1932 | for (guint i = 0; i < remotes->len; i++) { |
| 1933 | FwupdRemote *remote_tmp = g_ptr_array_index (remotes, i); |
| 1934 | g_node_append_data (root, remote_tmp); |
| 1935 | } |
| 1936 | fu_util_print_tree (root, title); |
| 1937 | |
| 1938 | return TRUE; |
| 1939 | } |
| 1940 | |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1941 | static gboolean |
| 1942 | fu_util_security (FuUtilPrivate *priv, gchar **values, GError **error) |
| 1943 | { |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame^] | 1944 | g_autoptr(FuSecurityAttrs) attrs = NULL; |
| 1945 | g_autoptr(GPtrArray) items = NULL; |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1946 | g_autofree gchar *str = NULL; |
| 1947 | |
| 1948 | /* not ready yet */ |
| 1949 | if ((priv->flags & FWUPD_INSTALL_FLAG_FORCE) == 0) { |
| 1950 | g_set_error_literal (error, |
| 1951 | FWUPD_ERROR, |
| 1952 | FWUPD_ERROR_NOT_SUPPORTED, |
| 1953 | "The HSI specification is not yet complete. " |
| 1954 | "To ignore this warning, use --force"); |
| 1955 | return FALSE; |
| 1956 | } |
| 1957 | |
| 1958 | if (!fu_util_start_engine (priv, FU_ENGINE_LOAD_FLAG_NONE, error)) |
| 1959 | return FALSE; |
| 1960 | |
| 1961 | /* TRANSLATORS: this is a string like 'HSI:2-U' */ |
| 1962 | g_print ("%s \033[1m%s\033[0m\n", _("Host Security ID:"), |
| 1963 | fu_engine_get_host_security_id (priv->engine)); |
| 1964 | |
| 1965 | /* print the "why" */ |
| 1966 | attrs = fu_engine_get_host_security_attrs (priv->engine, error); |
| 1967 | if (attrs == NULL) |
| 1968 | return FALSE; |
Richard Hughes | f58ac73 | 2020-05-12 15:23:44 +0100 | [diff] [blame^] | 1969 | items = fu_security_attrs_get_all (attrs); |
| 1970 | str = fu_util_security_attrs_to_string (items); |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 1971 | g_print ("%s\n", str); |
| 1972 | return TRUE; |
| 1973 | } |
| 1974 | |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 1975 | int |
| 1976 | main (int argc, char *argv[]) |
| 1977 | { |
Richard Hughes | 460226a | 2018-05-21 20:56:21 +0100 | [diff] [blame] | 1978 | gboolean allow_older = FALSE; |
| 1979 | gboolean allow_reinstall = FALSE; |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 1980 | gboolean force = FALSE; |
| 1981 | gboolean ret; |
Mario Limonciello | 2d4b7a5 | 2018-09-12 22:08:04 -0500 | [diff] [blame] | 1982 | gboolean version = FALSE; |
Mario Limonciello | 5d7aa40 | 2019-02-04 09:35:58 -0600 | [diff] [blame] | 1983 | gboolean interactive = isatty (fileno (stdout)) != 0; |
Richard Hughes | c02ee4d | 2018-05-22 15:46:03 +0100 | [diff] [blame] | 1984 | g_auto(GStrv) plugin_glob = NULL; |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 1985 | g_autoptr(FuUtilPrivate) priv = g_new0 (FuUtilPrivate, 1); |
| 1986 | g_autoptr(GError) error = NULL; |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 1987 | g_autoptr(GPtrArray) cmd_array = fu_util_cmd_array_new (); |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 1988 | g_autofree gchar *cmd_descriptions = NULL; |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 1989 | g_autofree gchar *filter = NULL; |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 1990 | const GOptionEntry options[] = { |
Mario Limonciello | 2d4b7a5 | 2018-09-12 22:08:04 -0500 | [diff] [blame] | 1991 | { "version", '\0', 0, G_OPTION_ARG_NONE, &version, |
| 1992 | /* TRANSLATORS: command line option */ |
| 1993 | _("Show client and daemon versions"), NULL }, |
Richard Hughes | 460226a | 2018-05-21 20:56:21 +0100 | [diff] [blame] | 1994 | { "allow-reinstall", '\0', 0, G_OPTION_ARG_NONE, &allow_reinstall, |
| 1995 | /* TRANSLATORS: command line option */ |
Mario Limonciello | 350fc4c | 2019-10-03 07:08:51 -0500 | [diff] [blame] | 1996 | _("Allow reinstalling existing firmware versions"), NULL }, |
Richard Hughes | 460226a | 2018-05-21 20:56:21 +0100 | [diff] [blame] | 1997 | { "allow-older", '\0', 0, G_OPTION_ARG_NONE, &allow_older, |
| 1998 | /* TRANSLATORS: command line option */ |
| 1999 | _("Allow downgrading firmware versions"), NULL }, |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2000 | { "force", '\0', 0, G_OPTION_ARG_NONE, &force, |
| 2001 | /* TRANSLATORS: command line option */ |
| 2002 | _("Override plugin warning"), NULL }, |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 2003 | { "no-reboot-check", '\0', 0, G_OPTION_ARG_NONE, &priv->no_reboot_check, |
| 2004 | /* TRANSLATORS: command line option */ |
| 2005 | _("Do not check for reboot after update"), NULL }, |
Mario Limonciello | 98b9516 | 2019-10-30 09:20:43 -0500 | [diff] [blame] | 2006 | { "no-safety-check", '\0', 0, G_OPTION_ARG_NONE, &priv->no_safety_check, |
| 2007 | /* TRANSLATORS: command line option */ |
| 2008 | _("Do not perform device safety checks"), NULL }, |
Mario Limonciello | ba9e5b9 | 2018-05-21 16:02:32 -0500 | [diff] [blame] | 2009 | { "show-all-devices", '\0', 0, G_OPTION_ARG_NONE, &priv->show_all_devices, |
| 2010 | /* TRANSLATORS: command line option */ |
| 2011 | _("Show devices that are not updatable"), NULL }, |
Richard Hughes | c02ee4d | 2018-05-22 15:46:03 +0100 | [diff] [blame] | 2012 | { "plugin-whitelist", '\0', 0, G_OPTION_ARG_STRING_ARRAY, &plugin_glob, |
| 2013 | /* TRANSLATORS: command line option */ |
| 2014 | _("Manually whitelist specific plugins"), NULL }, |
Mario Limonciello | 8402cea | 2019-02-07 20:25:31 -0600 | [diff] [blame] | 2015 | { "prepare", '\0', 0, G_OPTION_ARG_NONE, &priv->prepare_blob, |
Mario Limonciello | 53ce25d | 2019-02-01 16:09:03 +0000 | [diff] [blame] | 2016 | /* TRANSLATORS: command line option */ |
| 2017 | _("Run the plugin composite prepare routine when using install-blob"), NULL }, |
Mario Limonciello | 8402cea | 2019-02-07 20:25:31 -0600 | [diff] [blame] | 2018 | { "cleanup", '\0', 0, G_OPTION_ARG_NONE, &priv->cleanup_blob, |
Mario Limonciello | 53ce25d | 2019-02-01 16:09:03 +0000 | [diff] [blame] | 2019 | /* TRANSLATORS: command line option */ |
| 2020 | _("Run the plugin composite cleanup routine when using install-blob"), NULL }, |
Mario Limonciello | 3143bad | 2019-02-27 07:31:00 -0600 | [diff] [blame] | 2021 | { "enable-json-state", '\0', 0, G_OPTION_ARG_NONE, &priv->enable_json_state, |
| 2022 | /* TRANSLATORS: command line option */ |
| 2023 | _("Save device state into a JSON file between executions"), NULL }, |
Richard Hughes | 0e46b22 | 2019-09-05 12:13:35 +0100 | [diff] [blame] | 2024 | { "disable-ssl-strict", '\0', 0, G_OPTION_ARG_NONE, &priv->disable_ssl_strict, |
| 2025 | /* TRANSLATORS: command line option */ |
| 2026 | _("Ignore SSL strict checks when downloading files"), NULL }, |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 2027 | { "filter", '\0', 0, G_OPTION_ARG_STRING, &filter, |
| 2028 | /* TRANSLATORS: command line option */ |
| 2029 | _("Filter with a set of device flags using a ~ prefix to " |
| 2030 | "exclude, e.g. 'internal,~needs-reboot'"), NULL }, |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2031 | { NULL} |
| 2032 | }; |
| 2033 | |
Richard Hughes | 429f72b | 2020-01-16 12:18:19 +0000 | [diff] [blame] | 2034 | #ifdef _WIN32 |
| 2035 | /* workaround Windows setting the codepage to 1252 */ |
| 2036 | g_setenv ("LANG", "C.UTF-8", FALSE); |
| 2037 | #endif |
| 2038 | |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2039 | setlocale (LC_ALL, ""); |
| 2040 | |
Richard Hughes | 668ee21 | 2019-11-22 09:17:46 +0000 | [diff] [blame] | 2041 | bindtextdomain (GETTEXT_PACKAGE, FWUPD_LOCALEDIR); |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2042 | bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); |
| 2043 | textdomain (GETTEXT_PACKAGE); |
| 2044 | |
Richard Hughes | 01c0bad | 2019-11-22 09:08:51 +0000 | [diff] [blame] | 2045 | #ifdef HAVE_GETUID |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2046 | /* ensure root user */ |
Mario Limonciello | 5d7aa40 | 2019-02-04 09:35:58 -0600 | [diff] [blame] | 2047 | if (interactive && (getuid () != 0 || geteuid () != 0)) |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2048 | /* TRANSLATORS: we're poking around as a power user */ |
Mario Limonciello | b900c09 | 2018-05-22 14:22:21 -0500 | [diff] [blame] | 2049 | g_printerr ("%s\n", _("This program may only work correctly as root")); |
Richard Hughes | 01c0bad | 2019-11-22 09:08:51 +0000 | [diff] [blame] | 2050 | #endif |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2051 | |
| 2052 | /* create helper object */ |
| 2053 | priv->loop = g_main_loop_new (NULL, FALSE); |
| 2054 | priv->progressbar = fu_progressbar_new (); |
| 2055 | |
| 2056 | /* add commands */ |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2057 | fu_util_cmd_array_add (cmd_array, |
Mario Limonciello | f6d01b1 | 2018-10-18 12:57:10 -0500 | [diff] [blame] | 2058 | "build-firmware", |
| 2059 | "FILE-IN FILE-OUT [SCRIPT] [OUTPUT]", |
| 2060 | /* TRANSLATORS: command description */ |
| 2061 | _("Build firmware using a sandbox"), |
| 2062 | fu_util_firmware_builder); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2063 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2064 | "smbios-dump", |
| 2065 | "FILE", |
| 2066 | /* TRANSLATORS: command description */ |
| 2067 | _("Dump SMBIOS data from a file"), |
| 2068 | fu_util_smbios_dump); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2069 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | 8c71a3f | 2018-05-22 19:19:52 +0100 | [diff] [blame] | 2070 | "get-plugins", |
| 2071 | NULL, |
| 2072 | /* TRANSLATORS: command description */ |
| 2073 | _("Get all enabled plugins registered with the system"), |
| 2074 | fu_util_get_plugins); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2075 | fu_util_cmd_array_add (cmd_array, |
Mario Limonciello | 716ab27 | 2018-05-29 12:34:37 -0500 | [diff] [blame] | 2076 | "get-details", |
| 2077 | NULL, |
| 2078 | /* TRANSLATORS: command description */ |
| 2079 | _("Gets details about a firmware file"), |
| 2080 | fu_util_get_details); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2081 | fu_util_cmd_array_add (cmd_array, |
Mario Limonciello | fe59394 | 2019-04-03 13:48:52 -0500 | [diff] [blame] | 2082 | "get-history", |
| 2083 | NULL, |
| 2084 | /* TRANSLATORS: command description */ |
| 2085 | _("Show history of firmware updates"), |
| 2086 | fu_util_get_history); |
| 2087 | fu_util_cmd_array_add (cmd_array, |
Mario Limonciello | dfff18e | 2019-08-29 11:51:41 -0500 | [diff] [blame] | 2088 | "get-updates,get-upgrades", |
Mario Limonciello | 1e35e4c | 2019-01-28 11:13:02 -0600 | [diff] [blame] | 2089 | NULL, |
| 2090 | /* TRANSLATORS: command description */ |
| 2091 | _("Gets the list of updates for connected hardware"), |
| 2092 | fu_util_get_updates); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2093 | fu_util_cmd_array_add (cmd_array, |
Mario Limonciello | 1a9127d | 2019-08-27 11:32:51 +0100 | [diff] [blame] | 2094 | "get-devices,get-topology", |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 2095 | NULL, |
| 2096 | /* TRANSLATORS: command description */ |
| 2097 | _("Get all devices that support firmware updates"), |
| 2098 | fu_util_get_devices); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2099 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 2100 | "get-device-flags", |
| 2101 | NULL, |
| 2102 | /* TRANSLATORS: command description */ |
| 2103 | _("Get all device flags supported by fwupd"), |
| 2104 | fu_util_get_device_flags); |
| 2105 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 2106 | "watch", |
| 2107 | NULL, |
| 2108 | /* TRANSLATORS: command description */ |
Piotr DrÄ…g | 472fa59 | 2018-06-06 14:53:48 +0200 | [diff] [blame] | 2109 | _("Watch for hardware changes"), |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 2110 | fu_util_watch); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2111 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 2112 | "install-blob", |
| 2113 | "FILENAME DEVICE-ID", |
| 2114 | /* TRANSLATORS: command description */ |
| 2115 | _("Install a firmware blob on a device"), |
| 2116 | fu_util_install_blob); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2117 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 2118 | "install", |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 2119 | "FILE [DEVICE-ID|GUID]", |
Richard Hughes | a36c9cf | 2018-05-20 10:41:44 +0100 | [diff] [blame] | 2120 | /* TRANSLATORS: command description */ |
| 2121 | _("Install a firmware file on this hardware"), |
| 2122 | fu_util_install); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2123 | fu_util_cmd_array_add (cmd_array, |
Filipe LaÃns | b2f377a | 2020-03-30 21:05:50 +0100 | [diff] [blame] | 2124 | "reinstall", |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 2125 | "DEVICE-ID|GUID", |
Filipe LaÃns | b2f377a | 2020-03-30 21:05:50 +0100 | [diff] [blame] | 2126 | /* TRANSLATORS: command description */ |
| 2127 | _("Reinstall firmware on a device"), |
| 2128 | fu_util_reinstall); |
| 2129 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 2130 | "attach", |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 2131 | "DEVICE-ID|GUID", |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 2132 | /* TRANSLATORS: command description */ |
| 2133 | _("Attach to firmware mode"), |
| 2134 | fu_util_attach); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2135 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 2136 | "detach", |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 2137 | "DEVICE-ID|GUID", |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 2138 | /* TRANSLATORS: command description */ |
| 2139 | _("Detach to bootloader mode"), |
| 2140 | fu_util_detach); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2141 | fu_util_cmd_array_add (cmd_array, |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2142 | "activate", |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 2143 | "[DEVICE-ID|GUID]", |
Mario Limonciello | 96a0dd5 | 2019-02-25 13:50:03 -0600 | [diff] [blame] | 2144 | /* TRANSLATORS: command description */ |
| 2145 | _("Activate pending devices"), |
| 2146 | fu_util_activate); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2147 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | 1d894f1 | 2018-08-31 13:05:51 +0100 | [diff] [blame] | 2148 | "hwids", |
| 2149 | "[FILE]", |
| 2150 | /* TRANSLATORS: command description */ |
| 2151 | _("Return all the hardware IDs for the machine"), |
| 2152 | fu_util_hwids); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2153 | fu_util_cmd_array_add (cmd_array, |
Mario Limonciello | 62f8486 | 2018-10-18 13:15:23 -0500 | [diff] [blame] | 2154 | "monitor", |
| 2155 | NULL, |
| 2156 | /* TRANSLATORS: command description */ |
| 2157 | _("Monitor the daemon for events"), |
| 2158 | fu_util_monitor); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2159 | fu_util_cmd_array_add (cmd_array, |
Mario Limonciello | dfff18e | 2019-08-29 11:51:41 -0500 | [diff] [blame] | 2160 | "update,upgrade", |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 2161 | "[DEVICE-ID|GUID]", |
Mario Limonciello | 46aaee8 | 2019-01-10 12:58:00 -0600 | [diff] [blame] | 2162 | /* TRANSLATORS: command description */ |
| 2163 | _("Update all devices that match local metadata"), |
| 2164 | fu_util_update); |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 2165 | fu_util_cmd_array_add (cmd_array, |
| 2166 | "self-sign", |
| 2167 | "TEXT", |
| 2168 | /* TRANSLATORS: command description */ |
Richard Hughes | 12a021d | 2019-03-27 09:23:24 +0000 | [diff] [blame] | 2169 | C_("command-description", |
| 2170 | "Sign data using the client certificate"), |
Richard Hughes | 3d60762 | 2019-03-07 16:59:27 +0000 | [diff] [blame] | 2171 | fu_util_self_sign); |
Richard Hughes | 1568449 | 2019-03-15 16:27:50 +0000 | [diff] [blame] | 2172 | fu_util_cmd_array_add (cmd_array, |
| 2173 | "verify-update", |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 2174 | "[DEVICE-ID|GUID]", |
Richard Hughes | 1568449 | 2019-03-15 16:27:50 +0000 | [diff] [blame] | 2175 | /* TRANSLATORS: command description */ |
| 2176 | _("Update the stored metadata with current contents"), |
| 2177 | fu_util_verify_update); |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 2178 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | a58510b | 2019-10-30 10:03:12 +0000 | [diff] [blame] | 2179 | "firmware-read", |
Richard Hughes | 3aaf53c | 2020-04-20 09:39:46 +0100 | [diff] [blame] | 2180 | "FILENAME [DEVICE-ID|GUID]", |
Richard Hughes | a58510b | 2019-10-30 10:03:12 +0000 | [diff] [blame] | 2181 | /* TRANSLATORS: command description */ |
| 2182 | _("Read a firmware blob from a device"), |
| 2183 | fu_util_firmware_read); |
| 2184 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | bca63ed | 2020-03-09 20:20:03 +0000 | [diff] [blame] | 2185 | "firmware-convert", |
| 2186 | "FILENAME-SRC FILENAME-DST [FIRMWARE-TYPE-SRC] [FIRMWARE-TYPE-DST]", |
| 2187 | /* TRANSLATORS: command description */ |
| 2188 | _("Convert a firmware file"), |
| 2189 | fu_util_firmware_convert); |
| 2190 | fu_util_cmd_array_add (cmd_array, |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 2191 | "firmware-parse", |
Mario Limonciello | 234c864 | 2020-01-08 20:07:29 -0600 | [diff] [blame] | 2192 | "FILENAME [FIRMWARE-TYPE]", |
Richard Hughes | 95c98a9 | 2019-10-22 16:03:15 +0100 | [diff] [blame] | 2193 | /* TRANSLATORS: command description */ |
| 2194 | _("Parse and show details about a firmware file"), |
| 2195 | fu_util_firmware_parse); |
| 2196 | fu_util_cmd_array_add (cmd_array, |
| 2197 | "get-firmware-types", |
| 2198 | NULL, |
| 2199 | /* TRANSLATORS: command description */ |
| 2200 | _("List the available firmware types"), |
| 2201 | fu_util_get_firmware_types); |
Richard Hughes | fd7e994 | 2020-01-17 14:09:13 +0000 | [diff] [blame] | 2202 | fu_util_cmd_array_add (cmd_array, |
| 2203 | "get-remotes", |
| 2204 | NULL, |
| 2205 | /* TRANSLATORS: command description */ |
| 2206 | _("Gets the configured remotes"), |
| 2207 | fu_util_get_remotes); |
Richard Hughes | 4959baa | 2020-01-17 14:33:00 +0000 | [diff] [blame] | 2208 | fu_util_cmd_array_add (cmd_array, |
| 2209 | "refresh", |
| 2210 | NULL, |
| 2211 | /* TRANSLATORS: command description */ |
| 2212 | _("Refresh metadata from remote server"), |
| 2213 | fu_util_refresh); |
Richard Hughes | 196c6c6 | 2020-05-11 19:42:47 +0100 | [diff] [blame] | 2214 | fu_util_cmd_array_add (cmd_array, |
| 2215 | "security", |
| 2216 | NULL, |
| 2217 | /* TRANSLATORS: command description */ |
| 2218 | _("Gets the host security attributes."), |
| 2219 | fu_util_security); |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2220 | |
| 2221 | /* do stuff on ctrl+c */ |
| 2222 | priv->cancellable = g_cancellable_new (); |
Richard Hughes | 9e5675e | 2019-11-22 09:35:03 +0000 | [diff] [blame] | 2223 | #ifdef HAVE_GIO_UNIX |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2224 | g_unix_signal_add_full (G_PRIORITY_DEFAULT, |
| 2225 | SIGINT, fu_util_sigint_cb, |
| 2226 | priv, NULL); |
Richard Hughes | 9e5675e | 2019-11-22 09:35:03 +0000 | [diff] [blame] | 2227 | #endif |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2228 | g_signal_connect (priv->cancellable, "cancelled", |
| 2229 | G_CALLBACK (fu_util_cancelled_cb), priv); |
| 2230 | |
| 2231 | /* sort by command name */ |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2232 | fu_util_cmd_array_sort (cmd_array); |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2233 | |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 2234 | /* non-TTY consoles cannot answer questions */ |
Mario Limonciello | 5d7aa40 | 2019-02-04 09:35:58 -0600 | [diff] [blame] | 2235 | if (!interactive) { |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 2236 | priv->no_reboot_check = TRUE; |
Mario Limonciello | 98b9516 | 2019-10-30 09:20:43 -0500 | [diff] [blame] | 2237 | priv->no_safety_check = TRUE; |
Mario Limonciello | 9b31e6f | 2019-01-31 15:42:19 -0600 | [diff] [blame] | 2238 | fu_progressbar_set_interactive (priv->progressbar, FALSE); |
| 2239 | } |
Mario Limonciello | 3f243a9 | 2019-01-21 22:05:23 -0600 | [diff] [blame] | 2240 | |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2241 | /* get a list of the commands */ |
| 2242 | priv->context = g_option_context_new (NULL); |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2243 | cmd_descriptions = fu_util_cmd_array_to_string (cmd_array); |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2244 | g_option_context_set_summary (priv->context, cmd_descriptions); |
| 2245 | g_option_context_set_description (priv->context, |
| 2246 | "This tool allows an administrator to use the fwupd plugins " |
| 2247 | "without being installed on the host system."); |
| 2248 | |
| 2249 | /* TRANSLATORS: program name */ |
| 2250 | g_set_application_name (_("Firmware Utility")); |
| 2251 | g_option_context_add_main_entries (priv->context, options, NULL); |
Mario Limonciello | fde4773 | 2018-09-11 12:20:58 -0500 | [diff] [blame] | 2252 | g_option_context_add_group (priv->context, fu_debug_get_option_group ()); |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2253 | ret = g_option_context_parse (priv->context, &argc, &argv, &error); |
| 2254 | if (!ret) { |
| 2255 | /* TRANSLATORS: the user didn't read the man page */ |
| 2256 | g_print ("%s: %s\n", _("Failed to parse arguments"), |
| 2257 | error->message); |
| 2258 | return EXIT_FAILURE; |
| 2259 | } |
| 2260 | |
Richard Hughes | 0e46b22 | 2019-09-05 12:13:35 +0100 | [diff] [blame] | 2261 | /* allow disabling SSL strict mode for broken corporate proxies */ |
| 2262 | if (priv->disable_ssl_strict) { |
| 2263 | /* TRANSLATORS: try to help */ |
| 2264 | g_printerr ("%s\n", _("WARNING: Ignoring SSL strict checks, " |
| 2265 | "to do this automatically in the future " |
| 2266 | "export DISABLE_SSL_STRICT in your environment")); |
| 2267 | g_setenv ("DISABLE_SSL_STRICT", "1", TRUE); |
| 2268 | } |
| 2269 | |
Richard Hughes | 747f570 | 2019-08-06 14:27:26 +0100 | [diff] [blame] | 2270 | /* parse filter flags */ |
| 2271 | if (filter != NULL) { |
| 2272 | if (!fu_util_parse_filter_flags (filter, |
| 2273 | &priv->filter_include, |
| 2274 | &priv->filter_exclude, |
| 2275 | &error)) { |
| 2276 | /* TRANSLATORS: the user didn't read the man page */ |
| 2277 | g_print ("%s: %s\n", _("Failed to parse flags for --filter"), |
| 2278 | error->message); |
| 2279 | return EXIT_FAILURE; |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | |
Richard Hughes | 460226a | 2018-05-21 20:56:21 +0100 | [diff] [blame] | 2284 | /* set flags */ |
Richard Hughes | 460226a | 2018-05-21 20:56:21 +0100 | [diff] [blame] | 2285 | if (allow_reinstall) |
| 2286 | priv->flags |= FWUPD_INSTALL_FLAG_ALLOW_REINSTALL; |
| 2287 | if (allow_older) |
| 2288 | priv->flags |= FWUPD_INSTALL_FLAG_ALLOW_OLDER; |
| 2289 | if (force) |
| 2290 | priv->flags |= FWUPD_INSTALL_FLAG_FORCE; |
| 2291 | |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 2292 | /* load engine */ |
| 2293 | priv->engine = fu_engine_new (FU_APP_FLAGS_NO_IDLE_SOURCES); |
| 2294 | g_signal_connect (priv->engine, "device-added", |
| 2295 | G_CALLBACK (fu_main_engine_device_added_cb), |
| 2296 | priv); |
| 2297 | g_signal_connect (priv->engine, "device-removed", |
| 2298 | G_CALLBACK (fu_main_engine_device_removed_cb), |
| 2299 | priv); |
Richard Hughes | 98ca993 | 2018-05-18 10:24:07 +0100 | [diff] [blame] | 2300 | g_signal_connect (priv->engine, "status-changed", |
| 2301 | G_CALLBACK (fu_main_engine_status_changed_cb), |
| 2302 | priv); |
| 2303 | g_signal_connect (priv->engine, "percentage-changed", |
| 2304 | G_CALLBACK (fu_main_engine_percentage_changed_cb), |
| 2305 | priv); |
| 2306 | |
Mario Limonciello | 2d4b7a5 | 2018-09-12 22:08:04 -0500 | [diff] [blame] | 2307 | /* just show versions and exit */ |
| 2308 | if (version) { |
| 2309 | g_autofree gchar *version_str = fu_util_get_versions (); |
| 2310 | g_print ("%s\n", version_str); |
| 2311 | return EXIT_SUCCESS; |
| 2312 | } |
| 2313 | |
Richard Hughes | c02ee4d | 2018-05-22 15:46:03 +0100 | [diff] [blame] | 2314 | /* any plugin whitelist specified */ |
| 2315 | for (guint i = 0; plugin_glob != NULL && plugin_glob[i] != NULL; i++) |
| 2316 | fu_engine_add_plugin_filter (priv->engine, plugin_glob[i]); |
| 2317 | |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2318 | /* run the specified command */ |
Richard Hughes | c77e111 | 2019-03-01 10:16:26 +0000 | [diff] [blame] | 2319 | ret = fu_util_cmd_array_run (cmd_array, priv, argv[1], (gchar**) &argv[2], &error); |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2320 | if (!ret) { |
Mario Limonciello | 8909631 | 2020-04-30 09:51:14 -0500 | [diff] [blame] | 2321 | g_printerr ("%s\n", error->message); |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2322 | if (g_error_matches (error, FWUPD_ERROR, FWUPD_ERROR_INVALID_ARGS)) { |
Mario Limonciello | 8909631 | 2020-04-30 09:51:14 -0500 | [diff] [blame] | 2323 | /* TRANSLATORS: error message explaining command to run to how to get help */ |
| 2324 | g_printerr ("\n%s\n", _("Use fwupdtool --help for help")); |
| 2325 | } else if (g_error_matches (error, FWUPD_ERROR, FWUPD_ERROR_NOTHING_TO_DO)) { |
| 2326 | g_debug ("%s\n", error->message); |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2327 | return EXIT_NOTHING_TO_DO; |
| 2328 | } |
Richard Hughes | b597683 | 2018-05-18 10:02:09 +0100 | [diff] [blame] | 2329 | return EXIT_FAILURE; |
| 2330 | } |
| 2331 | |
| 2332 | /* success */ |
| 2333 | return EXIT_SUCCESS; |
| 2334 | } |