Unify rpm-ostree into one binary
And start making an internal library.
This commit is contained in:
parent
bd50265d1c
commit
802cace05f
@ -17,10 +17,13 @@
|
||||
|
||||
privlib_SCRIPTS = src/rpmqa-sorted src/repoquery-sorted
|
||||
|
||||
bin_PROGRAMS += rpm-ostree rpm-ostree-postprocess-and-commit
|
||||
bin_PROGRAMS += rpm-ostree
|
||||
|
||||
rpm_ostree_SOURCES = src/rpm-ostree.c
|
||||
rpm_ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/libgsystem -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_OSTREE_CFLAGS)
|
||||
rpm_ostree_SOURCES = src/rpm-ostree.c \
|
||||
src/rpmostree-postprocess.h \
|
||||
src/rpmostree-postprocess.c \
|
||||
$(NULL)
|
||||
rpm_ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/libgsystem -I$(srcdir)/src -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_OSTREE_CFLAGS)
|
||||
rpm_ostree_LDADD = $(AM_LDFLAGS) $(PKGDEP_OSTREE_LIBS) libgsystem.la
|
||||
|
||||
rpm_ostree_postprocess_and_commit_SOURCES = src/rpm-ostree-postprocess-and-commit.c
|
||||
|
@ -23,7 +23,8 @@
|
||||
#include <string.h>
|
||||
#include <glib-unix.h>
|
||||
|
||||
#include <ostree.h>
|
||||
#include "rpmostree-postprocess.h"
|
||||
|
||||
#include "libgsystem.h"
|
||||
|
||||
static char **opt_enable_repos;
|
||||
@ -384,6 +385,7 @@ main (int argc,
|
||||
gs_unref_object GFile *yumcachedir = NULL;
|
||||
gs_unref_object GFile *yumcache_lookaside = NULL;
|
||||
gs_unref_object GFile *yumroot_varcache = NULL;
|
||||
gs_unref_object OstreeRepo *repo = NULL;
|
||||
gs_unref_ptrarray GPtrArray *all_packages = NULL;
|
||||
|
||||
g_option_context_add_main_entries (context, option_entries, NULL);
|
||||
@ -602,24 +604,18 @@ main (int argc,
|
||||
goto out;
|
||||
|
||||
{
|
||||
gs_unref_object GFile *repo_path = g_file_new_for_path ("repo");
|
||||
repo = ostree_repo_new (repo_path);
|
||||
}
|
||||
|
||||
{
|
||||
/* OSTree commit messages aren't really useful. */
|
||||
const char *commit_message = "";
|
||||
if (!gs_subprocess_simple_run_sync (NULL,
|
||||
GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
|
||||
cancellable,
|
||||
error,
|
||||
"rpm-ostree-postprocess-and-commit",
|
||||
"--repo=repo",
|
||||
"-m", commit_message,
|
||||
gs_file_get_path_cached (yumroot),
|
||||
ref,
|
||||
NULL))
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!ostree_repo_open (repo, cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (!rpmostree_postprocess_and_commit (yumroot, repo,
|
||||
ref, NULL,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (!gs_file_rename (rpmtextlist_path_new, rpmtextlist_path,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
@ -22,20 +22,9 @@
|
||||
|
||||
#include "string.h"
|
||||
|
||||
#include <ostree.h>
|
||||
#include "rpmostree-postprocess.h"
|
||||
#include "libgsystem.h"
|
||||
|
||||
static char *opt_repo_path;
|
||||
static char *opt_message;
|
||||
static char *opt_gpg_sign_keyid;
|
||||
|
||||
static GOptionEntry option_entries[] = {
|
||||
{ "repo", 'r', 0, G_OPTION_ARG_STRING, &opt_repo_path, "Path to OSTree repository", "REPO" },
|
||||
{ "message", 'm', 0, G_OPTION_ARG_STRING, &opt_message, "Commit message", "MESSAGE" },
|
||||
{ "gpg-sign", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_sign_keyid, "Sign commit using GPG key", "KEYID" },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static gboolean
|
||||
move_to_dir (GFile *src,
|
||||
GFile *dest_dir,
|
||||
@ -576,45 +565,26 @@ create_rootfs_from_yumroot_content (GFile *targetroot,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
gboolean
|
||||
rpmostree_postprocess_and_commit (GFile *rootfs,
|
||||
OstreeRepo *repo,
|
||||
const char *refname,
|
||||
const char *gpg_keyid,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
GError *local_error = NULL;
|
||||
GError **error = &local_error;
|
||||
const char *rootfs_path;
|
||||
GCancellable *cancellable = NULL;
|
||||
gs_free char *rootfs_tmp_path = NULL;
|
||||
gs_free char *parent_revision = NULL;
|
||||
gs_free char *new_revision = NULL;
|
||||
gs_unref_object GFile *rootfs_tmp = NULL;
|
||||
gs_unref_object GFile *rootfs = NULL;
|
||||
gboolean ret = FALSE;
|
||||
gs_unref_object GFile *root_tree = NULL;
|
||||
gs_unref_object GFile *rootfs_tmp = NULL;
|
||||
gs_unref_object OstreeMutableTree *mtree = NULL;
|
||||
OstreeRepoCommitModifier *commit_modifier = NULL;
|
||||
gs_unref_object OstreeRepo *repo = NULL;
|
||||
const char *refname;
|
||||
GOptionContext *context = g_option_context_new ("- Commit the result of an RPM installroot to OSTree repository");
|
||||
gs_free char *parent_revision = NULL;
|
||||
gs_free char *new_revision = NULL;
|
||||
|
||||
g_option_context_add_main_entries (context, option_entries, NULL);
|
||||
|
||||
if (!g_option_context_parse (context, &argc, &argv, error))
|
||||
goto out;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
g_printerr ("usage: %s ROOTFS_PATH REFNAME\n", argv[0]);
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"Option processing failed");
|
||||
goto out;
|
||||
}
|
||||
|
||||
rootfs_path = argv[1];
|
||||
refname = argv[2];
|
||||
|
||||
rootfs = g_file_new_for_path (rootfs_path);
|
||||
|
||||
rootfs_tmp_path = g_strconcat (rootfs_path, ".tmp", NULL);
|
||||
rootfs_tmp = g_file_new_for_path (rootfs_tmp_path);
|
||||
{
|
||||
gs_free char *rootfs_tmp_path = g_strconcat (gs_file_get_path_cached (rootfs), ".tmp", NULL);
|
||||
rootfs_tmp = g_file_new_for_path (rootfs_tmp_path);
|
||||
}
|
||||
|
||||
if (!gs_shutil_rm_rf (rootfs_tmp, cancellable, error))
|
||||
goto out;
|
||||
@ -627,19 +597,6 @@ main (int argc, char **argv)
|
||||
if (!gs_file_rename (rootfs_tmp, rootfs, cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (opt_repo_path)
|
||||
{
|
||||
gs_unref_object GFile *repo_path = g_file_new_for_path (opt_repo_path);
|
||||
repo = ostree_repo_new (repo_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
repo = ostree_repo_new_default ();
|
||||
}
|
||||
|
||||
if (!ostree_repo_open (repo, cancellable, error))
|
||||
goto out;
|
||||
|
||||
// To make SELinux work, we need to do the labeling right before this.
|
||||
// This really needs some sort of API, so we can apply the xattrs as
|
||||
// we're committing into the repo, rather than having to label the
|
||||
@ -659,14 +616,14 @@ main (int argc, char **argv)
|
||||
if (!ostree_repo_resolve_rev (repo, refname, TRUE, &parent_revision, error))
|
||||
goto out;
|
||||
|
||||
if (!ostree_repo_write_commit (repo, parent_revision, "", opt_message,
|
||||
if (!ostree_repo_write_commit (repo, parent_revision, "", "",
|
||||
NULL, (OstreeRepoFile*)root_tree, &new_revision,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
|
||||
if (opt_gpg_sign_keyid)
|
||||
if (gpg_keyid)
|
||||
{
|
||||
if (!ostree_repo_sign_commit (repo, new_revision, opt_gpg_sign_keyid, NULL,
|
||||
if (!ostree_repo_sign_commit (repo, new_revision, gpg_keyid, NULL,
|
||||
cancellable, error))
|
||||
goto out;
|
||||
}
|
||||
@ -683,22 +640,7 @@ main (int argc, char **argv)
|
||||
else
|
||||
g_print ("Preserved %s\n", gs_file_get_path_cached (rootfs));
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
if (local_error != NULL)
|
||||
{
|
||||
int is_tty = isatty (1);
|
||||
const char *prefix = "";
|
||||
const char *suffix = "";
|
||||
if (is_tty)
|
||||
{
|
||||
prefix = "\x1b[31m\x1b[1m"; /* red, bold */
|
||||
suffix = "\x1b[22m\x1b[0m"; /* bold off, color reset */
|
||||
}
|
||||
g_printerr ("%serror: %s%s\n", prefix, suffix, local_error->message);
|
||||
g_error_free (local_error);
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
31
src/rpmostree-postprocess.h
Normal file
31
src/rpmostree-postprocess.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright (C) 2013,2014 Colin Walters <walters@verbum.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 2 of the licence or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General
|
||||
* Public License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ostree.h>
|
||||
|
||||
gboolean
|
||||
rpmostree_postprocess_and_commit (GFile *rootfs,
|
||||
OstreeRepo *repo,
|
||||
const char *refname,
|
||||
const char *gpg_keyid,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
Loading…
Reference in New Issue
Block a user