diff --git a/app/xdg-app-builtins-build-export.c b/app/xdg-app-builtins-build-export.c index f20b30a0..200eab8f 100644 --- a/app/xdg-app-builtins-build-export.c +++ b/app/xdg-app-builtins-build-export.c @@ -34,7 +34,8 @@ static char *opt_subject; static char *opt_body; static gboolean opt_runtime; -static char **opt_key_ids; +static gboolean opt_update_appstream; +static char **opt_gpg_key_ids; static char **opt_exclude; static char **opt_include; static char *opt_gpg_homedir; @@ -45,9 +46,10 @@ static GOptionEntry options[] = { { "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject", "SUBJECT" }, { "body", 'b', 0, G_OPTION_ARG_STRING, &opt_body, "Full description", "BODY" }, { "runtime", 'r', 0, G_OPTION_ARG_NONE, &opt_runtime, "Commit runtime (/usr), not /app" }, + { "update-appstream", 0, 0, G_OPTION_ARG_NONE, &opt_runtime, "Update the appstream branch" }, { "files", 0, 0, G_OPTION_ARG_STRING, &opt_files, "Use alternative directory for the files", "SUBDIR"}, { "metadata", 0, 0, G_OPTION_ARG_STRING, &opt_metadata, "Use alternative file for the metadata", "FILE"}, - { "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "GPG Key ID to sign the commit with", "KEY-ID"}, + { "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gpg_key_ids, "GPG Key ID to sign the commit with", "KEY-ID"}, { "exclude", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_exclude, "Files to exclude", "PATTERN"}, { "include", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_include, "Excluded files to include", "PATTERN"}, { "gpg-homedir", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_homedir, "GPG Homedir to use when looking for keyrings", "HOMEDIR"}, @@ -402,11 +404,11 @@ xdg_app_builtin_build_export (int argc, char **argv, GCancellable *cancellable, &commit_checksum, cancellable, error)) goto out; - if (opt_key_ids) + if (opt_gpg_key_ids) { char **iter; - for (iter = opt_key_ids; iter && *iter; iter++) + for (iter = opt_gpg_key_ids; iter && *iter; iter++) { const char *keyid = *iter; @@ -425,7 +427,25 @@ xdg_app_builtin_build_export (int argc, char **argv, GCancellable *cancellable, if (!ostree_repo_commit_transaction (repo, &stats, cancellable, error)) goto out; + if (opt_update_appstream) + { + g_autoptr(GError) my_error = NULL; + + if (!xdg_app_repo_generate_appstream (repo, (const char **)opt_gpg_key_ids, opt_gpg_homedir, cancellable, &my_error)) + { + if (g_error_matches (my_error, G_SPAWN_ERROR, G_SPAWN_ERROR_NOENT)) + g_print ("WARNING: Can't find appstream-builder, unable to update appstream branch\n"); + else + { + g_propagate_error (error, g_steal_pointer (&my_error)); + return FALSE; + } + } + } + if (!xdg_app_repo_update (repo, + (const char **)opt_gpg_key_ids, + opt_gpg_homedir, cancellable, error)) goto out; diff --git a/app/xdg-app-builtins-repo-update.c b/app/xdg-app-builtins-repo-update.c index 407c5fb9..df5c0e41 100644 --- a/app/xdg-app-builtins-repo-update.c +++ b/app/xdg-app-builtins-repo-update.c @@ -32,15 +32,20 @@ #include "xdg-app-utils.h" static char *opt_title; +static char *opt_gpg_homedir; +static char **opt_gpg_key_ids; static GOptionEntry options[] = { { "title", 0, 0, G_OPTION_ARG_STRING, &opt_title, "A nice name to use for this repository", "TITLE" }, + { "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_gpg_key_ids, "GPG Key ID to sign the commit with", "KEY-ID"}, + { "gpg-homedir", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_homedir, "GPG Homedir to use when looking for keyrings", "HOMEDIR"}, { NULL } }; gboolean -xdg_app_builtin_build_update_repo (int argc, char **argv, GCancellable *cancellable, GError **error) +xdg_app_builtin_build_update_repo (int argc, char **argv, + GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GFile) repofile = NULL; @@ -69,7 +74,7 @@ xdg_app_builtin_build_update_repo (int argc, char **argv, GCancellable *cancella return FALSE; g_print ("Updating appstream branch\n"); - if (!xdg_app_repo_generate_appstream (repo, cancellable, &my_error)) + if (!xdg_app_repo_generate_appstream (repo, (const char **)opt_gpg_key_ids, opt_gpg_homedir, cancellable, &my_error)) { if (g_error_matches (my_error, G_SPAWN_ERROR, G_SPAWN_ERROR_NOENT)) g_print ("WARNING: Can't find appstream-builder, unable to update appstream branch\n"); @@ -81,7 +86,7 @@ xdg_app_builtin_build_update_repo (int argc, char **argv, GCancellable *cancella } g_print ("Updating summary\n"); - if (!xdg_app_repo_update (repo, cancellable, error)) + if (!xdg_app_repo_update (repo, (const char **)opt_gpg_key_ids, opt_gpg_homedir, cancellable, error)) return FALSE; return TRUE; diff --git a/common/xdg-app-utils.c b/common/xdg-app-utils.c index 302e4aea..4816aaff 100644 --- a/common/xdg-app-utils.c +++ b/common/xdg-app-utils.c @@ -1272,7 +1272,7 @@ xdg_app_variant_bsearch_str (GVariant *array, imid = (imin + imax) / 2; child = g_variant_get_child_value (array, imid); - g_variant_get_child (child, 0, "&s", &cur, NULL); + g_variant_get_child (child, 0, "&s", &cur, NULL); cmp = strcmp (cur, str); if (cmp < 0) @@ -1315,9 +1315,11 @@ xdg_app_repo_set_title (OstreeRepo *repo, } gboolean -xdg_app_repo_update (OstreeRepo *repo, +xdg_app_repo_update (OstreeRepo *repo, + const char **gpg_key_ids, + const char *gpg_homedir, GCancellable *cancellable, - GError **error) + GError **error) { GVariantBuilder builder; GKeyFile *config; @@ -1340,7 +1342,15 @@ xdg_app_repo_update (OstreeRepo *repo, cancellable, error)) return FALSE; - /* TODO: appstream data */ + if (gpg_key_ids) + { + if (!ostree_repo_add_gpg_signature_summary (repo, + gpg_key_ids, + gpg_homedir, + cancellable, + error)) + return FALSE; + } return TRUE; } @@ -1380,6 +1390,8 @@ commit_filter (OstreeRepo *repo, gboolean xdg_app_repo_generate_appstream (OstreeRepo *repo, + const char **gpg_key_ids, + const char *gpg_homedir, GCancellable *cancellable, GError **error) { @@ -1466,7 +1478,7 @@ xdg_app_repo_generate_appstream (OstreeRepo *repo, branch = g_strdup_printf ("appstream/%s", arch); if (!ostree_repo_resolve_rev (repo, branch, TRUE, &parent, error)) - return FALSE; + goto out; mtree = ostree_mutable_tree_new (); @@ -1474,21 +1486,43 @@ xdg_app_repo_generate_appstream (OstreeRepo *repo, (OstreeRepoCommitFilter)commit_filter, NULL, NULL); if (!ostree_repo_write_directory_to_mtree (repo, G_FILE (tmpdir_file), mtree, modifier, cancellable, error)) - return FALSE; + goto out; if (!ostree_repo_write_mtree (repo, mtree, &root, cancellable, error)) - return FALSE; + goto out; if (!ostree_repo_write_commit (repo, parent, "Update", NULL, NULL, OSTREE_REPO_FILE (root), &commit_checksum, cancellable, error)) - return FALSE; + goto out; + + if (gpg_key_ids) + { + int i; + + for (i = 0; gpg_key_ids[i] != NULL; i++) + { + const char *keyid = gpg_key_ids[i]; + + if (!ostree_repo_sign_commit (repo, + commit_checksum, + keyid, + gpg_homedir, + cancellable, + error)) + goto out; + } + } ostree_repo_transaction_set_ref (repo, NULL, branch, commit_checksum); if (!ostree_repo_commit_transaction (repo, &stats, cancellable, error)) - return FALSE; + goto out; } return TRUE; + + out: + ostree_repo_abort_transaction (repo, cancellable, NULL); + return FALSE; } diff --git a/common/xdg-app-utils.h b/common/xdg-app-utils.h index d8bf250e..25c2760c 100644 --- a/common/xdg-app-utils.h +++ b/common/xdg-app-utils.h @@ -174,9 +174,13 @@ gboolean xdg_app_repo_set_title (OstreeRepo *repo, const char *title, GError **error); gboolean xdg_app_repo_update (OstreeRepo *repo, + const char **gpg_key_ids, + const char *gpg_homedir, GCancellable *cancellable, GError **error); gboolean xdg_app_repo_generate_appstream (OstreeRepo *repo, + const char **gpg_key_ids, + const char *gpg_homedir, GCancellable *cancellable, GError **error); diff --git a/doc/xdg-app-build-export.xml b/doc/xdg-app-build-export.xml index 6827d429..02f0543c 100644 --- a/doc/xdg-app-build-export.xml +++ b/doc/xdg-app-build-export.xml @@ -138,6 +138,14 @@ + + + + + Run appstream-builder and to update the appstream branch after build. + + + diff --git a/doc/xdg-app-build-update-repo.xml b/doc/xdg-app-build-update-repo.xml index 067c3fd4..88a59fa7 100644 --- a/doc/xdg-app-build-update-repo.xml +++ b/doc/xdg-app-build-update-repo.xml @@ -77,6 +77,22 @@ + + + + + Sign the commit with this GPG key + + + + + + + + GPG Homedir to use when looking for keyrings + + +