From 972f6eaba5dba35eda74c62d5ffe9b688a0569bf Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Wed, 11 Apr 2018 11:03:05 +0100 Subject: [PATCH] Allow customising the warning shown when enabling the remote --- contrib/fwupd.spec.in | 2 +- data/remotes.d/lvfs-testing.metainfo.xml | 35 ++++++++ data/remotes.d/lvfs.metainfo.xml | 29 +++++++ data/remotes.d/meson.build | 18 ++++ po/POTFILES.in | 2 + po/its/appdata.its | 14 ++++ po/its/appdata.loc | 9 ++ src/fu-util.c | 102 ++++++++++++++++++++++- 8 files changed, 207 insertions(+), 4 deletions(-) create mode 100644 data/remotes.d/lvfs-testing.metainfo.xml create mode 100644 data/remotes.d/lvfs.metainfo.xml create mode 100644 po/its/appdata.its create mode 100644 po/its/appdata.loc diff --git a/contrib/fwupd.spec.in b/contrib/fwupd.spec.in index b7223dc5c..3105f07cd 100644 --- a/contrib/fwupd.spec.in +++ b/contrib/fwupd.spec.in @@ -210,7 +210,7 @@ mkdir -p --mode=0700 $RPM_BUILD_ROOT%{_localstatedir}/lib/fwupd/gnupg %{_datadir}/dbus-1/system-services/org.freedesktop.fwupd.service %{_datadir}/man/man1/dfu-tool.1.gz %{_datadir}/man/man1/fwupdmgr.1.gz -%{_datadir}/metainfo/org.freedesktop.fwupd.metainfo.xml +%{_datadir}/metainfo/org.freedesktop.fwupd*.metainfo.xml %{_datadir}/fwupd/firmware-packager %{_unitdir}/fwupd-offline-update.service %{_unitdir}/fwupd.service diff --git a/data/remotes.d/lvfs-testing.metainfo.xml b/data/remotes.d/lvfs-testing.metainfo.xml new file mode 100644 index 000000000..5ca2bb432 --- /dev/null +++ b/data/remotes.d/lvfs-testing.metainfo.xml @@ -0,0 +1,35 @@ + + + + + org.freedesktop.fwupd.remotes.lvfs-testing + Linux Vendor Firmware Service (testing firmware) + CC0 + + + + +

+ The LVFS is a free service that operates as an independent legal + entity and has no connection with $OS_RELEASE:NAME$. + Your distributor may not have verified any of the firmware updates for + compatibility with your system or connected devices. + All firmware is provided only by the original equipment manufacturer. +

+

+ This remote contains firmware which is not embargoed, but is still being + tested by the hardware vendor. + You should ensure you have a way to manually downgrade the firmware if + the firmware update fails. +

+

+ Enabling this functionality is done at your own risk, which means you + have to contact your original equipment manufacturer regarding any + problems caused by these updates. + Only problems with the update process itself should be filed at + $OS_RELEASE:BUG_REPORT_URL$. +

+
+
+
+
diff --git a/data/remotes.d/lvfs.metainfo.xml b/data/remotes.d/lvfs.metainfo.xml new file mode 100644 index 000000000..6827d5dba --- /dev/null +++ b/data/remotes.d/lvfs.metainfo.xml @@ -0,0 +1,29 @@ + + + + + org.freedesktop.fwupd.remotes.lvfs + Linux Vendor Firmware Service (stable firmware) + CC0 + + + + +

+ The LVFS is a free service that operates as an independent legal + entity and has no connection with $OS_RELEASE:NAME$. + Your distributor may not have verified any of the firmware updates for + compatibility with your system or connected devices. + All firmware is provided only by the original equipment manufacturer. +

+

+ Enabling this functionality is done at your own risk, which means you + have to contact your original equipment manufacturer regarding any + problems caused by these updates. + Only problems with the update process itself should be filed at + $OS_RELEASE:BUG_REPORT_URL$. +

+
+
+
+
diff --git a/data/remotes.d/meson.build b/data/remotes.d/meson.build index 1484f38f2..da2206eb1 100644 --- a/data/remotes.d/meson.build +++ b/data/remotes.d/meson.build @@ -5,6 +5,24 @@ if get_option('lvfs') ], install_dir : join_paths(sysconfdir, 'fwupd', 'remotes.d') ) + i18n.merge_file( + input: 'lvfs.metainfo.xml', + output: 'org.freedesktop.fwupd.remotes.lvfs.metainfo.xml', + type: 'xml', + po_dir: join_paths(meson.source_root(), 'po'), + data_dirs: join_paths(meson.source_root(), 'po'), + install: true, + install_dir: join_paths(get_option('datadir'), 'metainfo') + ) + i18n.merge_file( + input: 'lvfs-testing.metainfo.xml', + output: 'org.freedesktop.fwupd.remotes.lvfs-testing.metainfo.xml', + type: 'xml', + po_dir: join_paths(meson.source_root(), 'po'), + data_dirs: join_paths(meson.source_root(), 'po'), + install: true, + install_dir: join_paths(get_option('datadir'), 'metainfo') + ) endif install_data('README.md', diff --git a/po/POTFILES.in b/po/POTFILES.in index 03ffe868b..e3e867648 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,4 +1,6 @@ data/org.freedesktop.fwupd.metainfo.xml +data/remotes.d/lvfs.metainfo.xml +data/remotes.d/lvfs-testing.metainfo.xml policy/org.freedesktop.fwupd.policy.in plugins/dfu/dfu-tool.c plugins/synapticsmst/synapticsmst-tool.c diff --git a/po/its/appdata.its b/po/its/appdata.its new file mode 100644 index 000000000..c41680c7e --- /dev/null +++ b/po/its/appdata.its @@ -0,0 +1,14 @@ + + + + + diff --git a/po/its/appdata.loc b/po/its/appdata.loc new file mode 100644 index 000000000..97dd7eb31 --- /dev/null +++ b/po/its/appdata.loc @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/src/fu-util.c b/src/fu-util.c index 954c9b215..3cf50562d 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -481,15 +481,111 @@ fu_util_get_remote_warning (FuUtilPrivate *priv, FwupdRemote *remote, GError **e return str; } +static GString * +fu_util_get_component_agreement (FuUtilPrivate *priv, AsApp *app, GError **error) +{ + g_autofree gchar *tmp = NULL; +#if AS_CHECK_VERSION(0,7,8) + AsAgreement *agreement; + AsAgreementSection *section; + + /* get the default agreement section */ + agreement = as_app_get_agreement_default (app); + if (agreement == NULL) { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_FOUND, + "No agreement found"); + return NULL; + } + section = as_agreement_get_section_default (agreement); + if (section == NULL) { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_FOUND, + "No default section for agreement found"); + return NULL; + } + tmp = as_agreement_section_get_description (section, NULL); + if (tmp == NULL) { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_FOUND, + "No description found in agreement section"); + return NULL; + } + + /* convert to console text */ + tmp = as_markup_convert_simple (tmp, error); +#else + AsFormat *format; + GNode *n; + g_autoptr(AsNode) root = NULL; + g_autoptr(GFile) file = NULL; + g_autoptr(GString) str = NULL; + + /* parse the XML file */ + format = as_app_get_format_default (app); + if (format == NULL) { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_FOUND, + "No format for Metainfo file"); + return NULL; + } + file = g_file_new_for_path (as_format_get_filename (format)); + root = as_node_from_file (file, AS_NODE_FROM_XML_FLAG_NONE, NULL, error); + if (root == NULL) + return NULL; + + /* manually find the first agreement section */ + n = as_node_find (root, "component/agreement/agreement_section/description"); + if (n == NULL) { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_NOT_FOUND, + "No agreement description found"); + return NULL; + } + str = as_node_to_xml (n->children, AS_NODE_TO_XML_FLAG_INCLUDE_SIBLINGS); + tmp = as_markup_convert_simple (str->str, error); +#endif + return g_string_new (tmp); +} + static gboolean fu_util_modify_remote_warning (FuUtilPrivate *priv, FwupdRemote *remote, GError **error) { + AsApp *app; + g_autofree gchar *component_id = NULL; + g_autoptr(AsStore) store = NULL; + g_autoptr(GHashTable) os_release = NULL; g_autoptr(GString) desc_plain_str = NULL; - /* get a generic warning */ - desc_plain_str = fu_util_get_remote_warning (priv, remote, error); - if (desc_plain_str == NULL) + /* try to find a custom agreement, falling back to a generic warning */ + store = as_store_new (); + as_store_add_filter (store, AS_APP_KIND_SOURCE); + if (!as_store_load (store, AS_STORE_LOAD_FLAG_APPDATA, NULL, error)) return FALSE; + component_id = g_strdup_printf ("org.freedesktop.fwupd.remotes.%s", + fwupd_remote_get_id (remote)); + app = as_store_get_app_by_id (store, component_id); + if (app != NULL) { + desc_plain_str = fu_util_get_component_agreement (priv, app, error); + if (desc_plain_str == NULL) + return FALSE; + } else { + desc_plain_str = fu_util_get_remote_warning (priv, remote, error); + if (desc_plain_str == NULL) + return FALSE; + } + + /* replace any dynamic values from os-release */ + os_release = fwupd_get_os_release (error); + as_utils_string_replace (desc_plain_str, "$OS_RELEASE:NAME$", + g_hash_table_lookup (os_release, "NAME")); + as_utils_string_replace (desc_plain_str, "$OS_RELEASE:BUG_REPORT_URL$", + g_hash_table_lookup (os_release, "BUG_REPORT_URL")); /* show and ask user to confirm */ g_print ("%s", desc_plain_str->str);