static gboolean
as_app_parse_shell_extension_data (AsbPlugin *plugin,
				   AsApp *app,
				   const gchar *data,
				   gsize len,
				   GError **error)
{
	JsonArray *json_array;
	JsonNode *json_root;
	JsonObject *json_obj;
	const gchar *tmp;
	g_autoptr(JsonParser) json_parser = NULL;

	/* parse the data */
	json_parser = json_parser_new ();
	if (!json_parser_load_from_data (json_parser, data, (gssize) len, error))
		return FALSE;
	json_root = json_parser_get_root (json_parser);
	if (json_root == NULL) {
		g_set_error_literal (error,
				     ASB_PLUGIN_ERROR,
				     ASB_PLUGIN_ERROR_FAILED,
				     "no root");
		return FALSE;
	}
	json_obj = json_node_get_object (json_root);
	if (json_obj == NULL) {
		g_set_error_literal (error,
				     ASB_PLUGIN_ERROR,
				     ASB_PLUGIN_ERROR_FAILED,
				     "no object");
		return FALSE;
	}

	as_app_set_kind (app, AS_APP_KIND_SHELL_EXTENSION);
	as_app_set_comment (app, NULL, "GNOME Shell Extension");
	if (asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_ADD_DEFAULT_ICONS)) {
		as_app_add_category (AS_APP (app), "Addons");
		as_app_add_category (AS_APP (app), "ShellExtensions");
	}
	tmp = json_object_get_string_member (json_obj, "uuid");
	if (tmp != NULL) {
		g_autofree gchar *id = NULL;
		id = as_utils_appstream_id_build (tmp);
		as_app_set_id (app, id);
		as_app_add_metadata (AS_APP (app), "shell-extensions::uuid", tmp);
	}
	if (json_object_has_member (json_obj, "gettext-domain")) {
		tmp = json_object_get_string_member (json_obj, "gettext-domain");
		if (tmp != NULL) {
			g_autoptr(AsTranslation) transaction = NULL;
			transaction = as_translation_new ();
			as_translation_set_kind (transaction, AS_TRANSLATION_KIND_GETTEXT);
			as_translation_set_id (transaction, tmp);
			as_app_add_translation (app, transaction);
		}
	}
	if (json_object_has_member (json_obj, "name")) {
		tmp = json_object_get_string_member (json_obj, "name");
		if (tmp != NULL)
			as_app_set_name (app, NULL, tmp);
	}
	if (json_object_has_member (json_obj, "description")) {
		tmp = json_object_get_string_member (json_obj, "description");
		if (tmp != NULL) {
			g_autofree gchar *desc = NULL;
			desc = as_markup_import (tmp,
						 AS_MARKUP_CONVERT_FORMAT_SIMPLE,
						 error);
			if (desc == NULL)
				return FALSE;
			as_app_set_description (app, NULL, desc);
		}
	}
	if (json_object_has_member (json_obj, "url")) {
		tmp = json_object_get_string_member (json_obj, "url");
		if (tmp != NULL)
			as_app_add_url (app, AS_URL_KIND_HOMEPAGE, tmp);
	}
	if (json_object_has_member (json_obj, "original-authors")) {
		json_array = json_object_get_array_member (json_obj, "original-authors");
		if (json_array != NULL) {
			tmp = json_array_get_string_element (json_array, 0);
			as_app_set_developer_name (app, NULL, tmp);
		}
	}
	if (as_app_get_release_default (app) == NULL &&
	    json_object_has_member (json_obj, "shell-version")) {
		json_array = json_object_get_array_member (json_obj, "shell-version");
		if (json_array != NULL) {
			g_autoptr(AsRelease) release = NULL;
			tmp = json_array_get_string_element (json_array, 0);
			release = as_release_new ();
			as_release_set_state (release, AS_RELEASE_STATE_INSTALLED);
			as_release_set_version (release, tmp);
			as_app_add_release (app, release);
		}
	}

	/* use a stock icon */
	if (asb_context_get_flag (plugin->ctx, ASB_CONTEXT_FLAG_ADD_DEFAULT_ICONS)) {
		g_autoptr(AsIcon) ic = as_icon_new ();
		as_icon_set_kind (ic, AS_ICON_KIND_STOCK);
		as_icon_set_name (ic, "application-x-addon-symbolic");
		as_app_add_icon (app, ic);
	}
	return TRUE;
}
Example #2
0
/**
 * pkgen_make_template:
 */
static gint
pkgen_make_template (const gchar *dir)
{
	gint res = 0;
	gchar *res_dir = NULL;
	gchar *tmp;
	gchar *fname;
	gboolean appstream_linked = FALSE;
	GError *error = NULL;

	if (dir == NULL) {
		tmp = g_get_current_dir ();
		res_dir = g_build_filename (tmp, "pkginstall", NULL);
		g_free (tmp);
	} else {
		res_dir = g_strdup (dir);
	}

	g_mkdir_with_parents (res_dir, 0755);

	g_print (_("Do you have an AppStream XML file for your software? [y/N]"));
	tmp = li_get_stdin ();
	if (tmp != NULL) {
		gchar *str;
		str = g_utf8_strdown (tmp, -1);
		g_free (tmp);
		g_strstrip (str);

		if (g_strcmp0 (str, "y") == 0) {
			g_print ("%s ", _("Please specify a path to the AppStream XML data:"));
			tmp = li_get_stdin ();
			if (tmp != NULL) {
				gchar *asfile;
				asfile = g_build_filename (res_dir, "metainfo.xml", NULL);
				/* TODO: create relative symlink */
				symlink (tmp, asfile);
				g_free (tmp);
				appstream_linked = TRUE;
			} else {
				res = 1;
				g_print ("%s\n", _("No path given. Exiting."));
				g_free (str);
				goto out;
			}
		}
		g_free (str);
    }

    if (!appstream_linked) {
		AsComponent *cpt;
		gchar *asfile;
		cpt = as_component_new ();

		while (TRUE) {
			g_print ("%s ", _("Your software needs a unique name.\nIn case of a GUI application, this is its .desktop filename.\nUnique software name:"));
			tmp = li_get_stdin ();
			if (tmp != NULL) {
				as_component_set_id (cpt, tmp);
				g_free (tmp);
				break;
			}
		}

		while (TRUE) {
			g_print ("%s ", _("Define a software name (human readable):"));
			tmp = li_get_stdin ();
			if (tmp != NULL) {
				as_component_set_name (cpt, tmp);
				g_free (tmp);
				break;
			}
		}

		while (TRUE) {
			g_print ("%s ", _("Define a software version:"));
			tmp = li_get_stdin ();
			if (tmp != NULL) {
				AsRelease *rel;
				rel = as_release_new ();
				as_release_set_version (rel, tmp);
				as_component_add_release (cpt, rel);
				g_object_unref (rel);
				g_free (tmp);
				break;
			}
		}

		while (TRUE) {
			g_print ("%s ", _("Write a short summary (one sentence) about your software:"));
			tmp = li_get_stdin ();
			if (tmp != NULL) {
				as_component_set_summary (cpt, tmp);
				g_free (tmp);
				break;
			}
		}

		asfile = g_build_filename (res_dir, "metainfo.xml", NULL);
		tmp = as_component_to_xml (cpt);
		g_file_set_contents (asfile, tmp, -1, &error);
		g_free (tmp);
		if (error != NULL) {
			li_print_stderr (_("Unable to write AppStream data. %s"), error->message);
			g_error_free (error);
			res = 2;
			g_free (asfile);
			goto out;
		}

		if (g_file_test ("/usr/bin/xmllint", G_FILE_TEST_EXISTS)) {
			gchar *cmd;
			/* we can try to pretty-print our XML file. Using xmllint from the environment should
			 * not be a security risk here */
			cmd = g_strdup_printf ("xmllint --format %s -o %s", asfile, asfile);

			/* any error / exit-code isn't relevant here - a failed attempt to format the XML will do no harm */
			g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL);
			g_free (cmd);
		}
		g_free (asfile);
    }

    fname = g_build_filename (res_dir, "control", NULL);
	g_file_set_contents (fname, "Format-Version: 1.0\n\nRequires:\n", -1, &error);
	g_free (fname);
	if (error != NULL) {
		li_print_stderr (_("Unable to write 'control' file. %s"), error->message);
		g_error_free (error);
		res = 2;
		goto out;
	}

	li_print_stdout ("\n========");\
	li_print_stdout (_("Created project template in '%s'.\n\n" \
"Please edit the files in that directory, e.g. add a long description to your\n" \
"application and specify its run-time dependencies.\n" \
"When you are done with this, build your software with --prefix=%s\n" \
"and install it into the inst_target subdirectory of your 'pkginstall' directory.\n" \
"Then run 'lipkgen build pkginstall/' to create your package. \n" \
"If you want to embed dependencies, place their IPK packages in the 'repo/'\n" \
"subdirectory of 'pkginstall/'"), res_dir, LI_SW_ROOT_PREFIX);
	li_print_stdout ("========\n");

out:
	g_free (res_dir);
	return res;
}
Example #3
0
/**
 * fu_util_verify_update:
 **/
static gboolean
fu_util_verify_update (FuUtilPrivate *priv, gchar **values, GError **error)
{
	guint i;
	_cleanup_object_unref_ AsStore *store = NULL;
	_cleanup_object_unref_ GFile *xml_file = NULL;

	if (g_strv_length (values) < 2) {
		g_set_error_literal (error,
				     FWUPD_ERROR,
				     FWUPD_ERROR_INTERNAL,
				     "Invalid arguments: expected 'filename.xml' 'filename.rom'");
		return FALSE;
	}
	store = as_store_new ();

	/* open existing file */
	xml_file = g_file_new_for_path (values[0]);
	if (g_file_query_exists (xml_file, NULL)) {
		if (!as_store_from_file (store, xml_file, NULL, NULL, error))
			return FALSE;
	}

	/* add new values */
	as_store_set_api_version (store, 0.9);
	for (i = 1; values[i] != NULL; i++) {
		_cleanup_free_ gchar *guid = NULL;
		_cleanup_free_ gchar *id = NULL;
		_cleanup_object_unref_ AsApp *app = NULL;
		_cleanup_object_unref_ AsRelease *rel = NULL;
		_cleanup_object_unref_ FuRom *rom = NULL;
		_cleanup_object_unref_ GFile *file = NULL;
		_cleanup_error_free_ GError *error_local = NULL;

		file = g_file_new_for_path (values[i]);
		rom = fu_rom_new ();
		g_print ("Processing %s...\n", values[i]);
		if (!fu_rom_load_file (rom, file, FU_ROM_LOAD_FLAG_BLANK_PPID,
				       NULL, &error_local)) {
			g_print ("%s\n", error_local->message);
			continue;
		}

		/* add app to store */
		app = as_app_new ();
		id = g_strdup_printf ("0x%04x:0x%04x",
				      fu_rom_get_vendor (rom),
				      fu_rom_get_model (rom));
		guid = fu_guid_generate_from_string (id);
		as_app_set_id (app, guid, -1);
		as_app_set_id_kind (app, AS_ID_KIND_FIRMWARE);
		as_app_set_source_kind (app, AS_APP_SOURCE_KIND_INF);
		rel = as_release_new ();
		as_release_set_version (rel, fu_rom_get_version (rom), -1);
		as_release_set_checksum (rel, G_CHECKSUM_SHA1,
					 fu_rom_get_checksum (rom), -1);
		as_app_add_release (app, rel);
		as_store_add_app (store, app);
	}
	if (!as_store_to_file (store, xml_file,
			       AS_NODE_TO_XML_FLAG_ADD_HEADER |
			       AS_NODE_TO_XML_FLAG_FORMAT_INDENT |
			       AS_NODE_TO_XML_FLAG_FORMAT_MULTILINE,
			       NULL, error))
		return FALSE;
	return TRUE;
}