core: Split pull functionality into separate ostree-pull binary
This is to avoid everything depending on libsoup.
This commit is contained in:
parent
3ac841d931
commit
e8865af09e
|
|
@ -24,5 +24,5 @@ ostreed_SOURCES = src/daemon/ostreed.c \
|
||||||
src/daemon/ot-daemon.c \
|
src/daemon/ot-daemon.c \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
ostreed_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -I$(srcdir)/src/daemon -DLOCALEDIR=\"$(datadir)/locale\" $(OT_COREBIN_DEP_CFLAGS)
|
ostreed_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -I$(srcdir)/src/daemon -DLOCALEDIR=\"$(datadir)/locale\" $(OT_DEP_GIO_UNIX_CFLAGS)
|
||||||
ostreed_LDADD = libotutil.la libostree.la $(OT_COREBIN_DEP_LIBS)
|
ostreed_LDADD = libotutil.la libostree.la $(OT_DEP_GIO_UNIX_LIBS)
|
||||||
|
|
|
||||||
|
|
@ -31,5 +31,5 @@ libostree_la_SOURCES = src/libostree/ostree.h \
|
||||||
src/libostree/ostree-checkout.c \
|
src/libostree/ostree-checkout.c \
|
||||||
src/libostree/ostree-checkout.h \
|
src/libostree/ostree-checkout.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
libostree_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -DLOCALEDIR=\"$(datadir)/locale\" $(OT_COREBIN_DEP_CFLAGS)
|
libostree_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -DLOCALEDIR=\"$(datadir)/locale\" $(OT_DEP_GIO_UNIX_CFLAGS)
|
||||||
libostree_la_LIBADD = libotutil.la $(OT_COREBIN_DEP_LIBS)
|
libostree_la_LIBADD = libotutil.la $(OT_DEP_GIO_UNIX_LIBS)
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,23 @@ ostree_SOURCES = src/ostree/main.c \
|
||||||
src/ostree/ot-builtin-remote.c \
|
src/ostree/ot-builtin-remote.c \
|
||||||
src/ostree/ot-builtin-rev-parse.c \
|
src/ostree/ot-builtin-rev-parse.c \
|
||||||
src/ostree/ot-builtin-show.c \
|
src/ostree/ot-builtin-show.c \
|
||||||
|
src/ostree/ot-main.h \
|
||||||
|
src/ostree/ot-main.c \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
ostree_bin_shared_cflags = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -I$(srcdir)/src/ostree -DLOCALEDIR=\"$(datadir)/locale\"
|
||||||
|
ostree_bin_shared_ldadd = libotutil.la libostree.la
|
||||||
|
|
||||||
|
ostree_CFLAGS = $(ostree_bin_shared_cflags) $(OT_DEP_GIO_UNIX_CFLAGS)
|
||||||
|
ostree_LDADD = $(ostree_bin_shared_ldadd) $(OT_DEP_GIO_UNIX_LIBS)
|
||||||
|
|
||||||
if USE_LIBSOUP_GNOME
|
if USE_LIBSOUP_GNOME
|
||||||
ostree_SOURCES += src/ostree/ot-builtin-pull.c
|
bin_PROGRAMS += ostree-pull
|
||||||
|
ostree_pull_SOURCES = src/ostree/ot-main.h \
|
||||||
|
src/ostree/ot-main.c \
|
||||||
|
src/ostree/ostree-pull.c
|
||||||
|
|
||||||
|
ostree_pull_CFLAGS = $(ostree_bin_shared_cflags) $(OT_DEP_SOUP_CFLAGS)
|
||||||
|
ostree_pull_LDADD = $(ostree_bin_shared_ldadd) $(OT_DEP_SOUP_LIBS)
|
||||||
endif
|
endif
|
||||||
ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -I$(srcdir)/src/ostree -DLOCALEDIR=\"$(datadir)/locale\" $(OT_COREBIN_DEP_CFLAGS)
|
|
||||||
ostree_LDADD = libotutil.la libostree.la $(OT_COREBIN_DEP_LIBS)
|
|
||||||
|
|
|
||||||
|
|
@ -32,5 +32,5 @@ libotutil_la_SOURCES = \
|
||||||
src/libotutil/ot-glib-compat.h \
|
src/libotutil/ot-glib-compat.h \
|
||||||
src/libotutil/otutil.h \
|
src/libotutil/otutil.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
libotutil_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -DLOCALEDIR=\"$(datadir)/locale\" $(GIO_UNIX_CFLAGS)
|
libotutil_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src/libotutil -DLOCALEDIR=\"$(datadir)/locale\" $(OT_DEP_GIO_UNIX_CFLAGS)
|
||||||
libotutil_la_LIBADD = $(GIO_UNIX_LIBS)
|
libotutil_la_LIBADD = $(OT_DEP_GIO_UNIX_LIBS)
|
||||||
|
|
|
||||||
12
configure.ac
12
configure.ac
|
|
@ -25,23 +25,23 @@ LT_INIT([disable-static])
|
||||||
PKG_PROG_PKG_CONFIG
|
PKG_PROG_PKG_CONFIG
|
||||||
|
|
||||||
GIO_DEPENDENCY="gio-unix-2.0 >= 2.28"
|
GIO_DEPENDENCY="gio-unix-2.0 >= 2.28"
|
||||||
PKG_CHECK_MODULES(GIO_UNIX, [gio-unix-2.0 >= 2.28])
|
SOUP_DEPENDENCY="libsoup-gnome-2.4 >= 2.34.0"
|
||||||
|
|
||||||
|
PKG_CHECK_MODULES(OT_DEP_GIO_UNIX, $GIO_DEPENDENCY)
|
||||||
|
|
||||||
AC_ARG_WITH(soup-gnome,
|
AC_ARG_WITH(soup-gnome,
|
||||||
AS_HELP_STRING([--without-soup-gnome], [Do not use libsoup-gnome (implies no pull support)]),
|
AS_HELP_STRING([--without-soup-gnome], [Do not use libsoup-gnome (implies no pull support)]),
|
||||||
:, with_soup_gnome=maybe)
|
:, with_soup_gnome=maybe)
|
||||||
if test x$with_soup_gnome != xno; then
|
if test x$with_soup_gnome != xno; then
|
||||||
PKG_CHECK_MODULES(OT_COREBIN_DEP, [libsoup-gnome-2.4 >= 2.34.0 $GIO_DEPENDENCY], have_soup_gnome=yes, have_soup_gnome=no)
|
PKG_CHECK_EXISTS($SOUP_DEPENDENCY, have_soup_gnome=yes, have_soup_gnome=no)
|
||||||
if test x$have_soup_gnome = xno && test x$with_soup_gnome != xmaybe; then
|
if test x$have_soup_gnome = xno && test x$with_soup_gnome != xmaybe; then
|
||||||
AC_MSG_ERROR([libsoup-gnome is enabled but could not be found])
|
AC_MSG_ERROR([libsoup-gnome is enabled but could not be found])
|
||||||
fi
|
fi
|
||||||
if test x$have_soup_gnome = xyes; then
|
if test x$have_soup_gnome = xyes; then
|
||||||
AC_DEFINE([HAVE_LIBSOUP_GNOME], [1], [Define if we have libsoup-gnome])
|
PKG_CHECK_MODULES(OT_DEP_SOUP, $SOUP_DEPENDENCY)
|
||||||
else
|
else
|
||||||
PKG_CHECK_MODULES(OT_COREBIN_DEP, [$GIO_DEPENDENCY])
|
|
||||||
with_soup_gnome=no
|
with_soup_gnome=no
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
PKG_CHECK_MODULES(OT_COREBIN_DEP, [$GIO_DEPENDENCY])
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
AM_CONDITIONAL(USE_LIBSOUP_GNOME, test $with_soup_gnome != no)
|
AM_CONDITIONAL(USE_LIBSOUP_GNOME, test $with_soup_gnome != no)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
||||||
|
#
|
||||||
|
# This library 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 License, 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.
|
||||||
|
|
||||||
|
# ostbuild-compile-one-make wraps systems that implement the GNOME build API:
|
||||||
|
# http://people.gnome.org/~walters/docs/build-api.txt
|
||||||
|
|
||||||
|
import os,sys,subprocess,tempfile,re
|
||||||
|
|
||||||
|
i=1
|
||||||
|
repo=sys.argv[i]
|
||||||
|
|
||||||
|
artifact_re = re.compile(r'^artifact-([^,]+)-([^,]+),(.+).tar.gz$')
|
||||||
|
|
||||||
|
if os.getuid() != 0:
|
||||||
|
print "This program must be run as root."
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def call_ostree_sync(*args):
|
||||||
|
subprocess.check_call(['ostree', '--repo=' + repo] + args)
|
||||||
|
|
||||||
|
for arg in sys.argv[1:]:
|
||||||
|
match = artifact_re.match(arg)
|
||||||
|
if match is None
|
||||||
|
print "Invalid artifact name: %s" % (arg, )
|
||||||
|
sys.exit(1)
|
||||||
|
arch = match.group(1)
|
||||||
|
name = match.group(2)
|
||||||
|
version = match.group(3)
|
||||||
|
|
||||||
|
branch_name = 'artifact-%s-%s' % (arch, name)
|
||||||
|
|
||||||
|
call_ostree_sync('commit', '-b', branch_name, '-s', version,
|
||||||
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
||||||
|
#
|
||||||
|
# This library 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 License, 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.
|
||||||
|
#
|
||||||
|
# Author: Colin Walters <walters@verbum.org>
|
||||||
|
|
||||||
|
|
||||||
|
bn=$(basename $(pwd))
|
||||||
|
ostbuild-nice-and-log-output "compile-${bn}.log" ostbuild-chroot-compile-one-impl "$@"
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
||||||
|
#
|
||||||
|
# This library 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 License, 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.
|
||||||
|
|
||||||
|
import os,sys,re,subprocess
|
||||||
|
|
||||||
|
i=1
|
||||||
|
repo=sys.argv[i]
|
||||||
|
i += 1
|
||||||
|
chroot_path=sys.argv[i]
|
||||||
|
i += 1
|
||||||
|
args=sys.argv[i:]
|
||||||
|
|
||||||
|
if os.getuid() != 0:
|
||||||
|
print "This program must be run as root."
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
rootdir=os.path.join(chroot_path, 'root')
|
||||||
|
|
||||||
|
if not os.path.isdir(rootdir):
|
||||||
|
print "Not a directory: %s" % (rootdir, )
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
builddir = os.path.join(rootdir, 'ostree-build')
|
||||||
|
if not os.path.isdir(builddir):
|
||||||
|
os.mkdir(builddir)
|
||||||
|
|
||||||
|
|
||||||
|
def run_in_chroot(args):
|
||||||
|
proc_path=os.path.join(chroot_path, 'proc')
|
||||||
|
subprocess.check_call(['mount', '-t', 'proc', 'proc', proc_path])
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.check_call(['chroot', chroot_path])
|
||||||
|
finally:
|
||||||
|
subprocess.call(['umount', proc_path])
|
||||||
|
|
||||||
|
run_in_chroot(args)
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "ot-main.h"
|
||||||
#include "ot-builtins.h"
|
#include "ot-builtins.h"
|
||||||
|
|
||||||
static OstreeBuiltin builtins[] = {
|
static OstreeBuiltin builtins[] = {
|
||||||
|
|
@ -38,9 +39,6 @@ static OstreeBuiltin builtins[] = {
|
||||||
{ "local-clone", ostree_builtin_local_clone, 0 },
|
{ "local-clone", ostree_builtin_local_clone, 0 },
|
||||||
{ "log", ostree_builtin_log, 0 },
|
{ "log", ostree_builtin_log, 0 },
|
||||||
{ "ls", ostree_builtin_ls, 0 },
|
{ "ls", ostree_builtin_ls, 0 },
|
||||||
#ifdef HAVE_LIBSOUP_GNOME
|
|
||||||
{ "pull", ostree_builtin_pull, 0 },
|
|
||||||
#endif
|
|
||||||
{ "fsck", ostree_builtin_fsck, 0 },
|
{ "fsck", ostree_builtin_fsck, 0 },
|
||||||
{ "remote", ostree_builtin_remote, 0 },
|
{ "remote", ostree_builtin_remote, 0 },
|
||||||
{ "rev-parse", ostree_builtin_rev_parse, 0 },
|
{ "rev-parse", ostree_builtin_rev_parse, 0 },
|
||||||
|
|
@ -50,126 +48,9 @@ static OstreeBuiltin builtins[] = {
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
|
||||||
usage (char **argv, gboolean is_error)
|
|
||||||
{
|
|
||||||
OstreeBuiltin *builtin = builtins;
|
|
||||||
void (*print_func) (const gchar *format, ...);
|
|
||||||
|
|
||||||
if (is_error)
|
|
||||||
print_func = g_printerr;
|
|
||||||
else
|
|
||||||
print_func = g_print;
|
|
||||||
|
|
||||||
print_func ("usage: %s --repo=PATH COMMAND [options]\n",
|
|
||||||
argv[0]);
|
|
||||||
print_func ("Builtin commands:\n");
|
|
||||||
|
|
||||||
while (builtin->name)
|
|
||||||
{
|
|
||||||
print_func (" %s\n", builtin->name);
|
|
||||||
builtin++;
|
|
||||||
}
|
|
||||||
return (is_error ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
prep_builtin_argv (const char *builtin,
|
|
||||||
int argc,
|
|
||||||
char **argv,
|
|
||||||
int *out_argc,
|
|
||||||
char ***out_argv)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char **cmd_argv;
|
|
||||||
|
|
||||||
cmd_argv = g_new0 (char *, argc + 2);
|
|
||||||
|
|
||||||
cmd_argv[0] = (char*)builtin;
|
|
||||||
for (i = 0; i < argc; i++)
|
|
||||||
cmd_argv[i+1] = argv[i];
|
|
||||||
cmd_argv[i+1] = NULL;
|
|
||||||
*out_argc = argc+1;
|
|
||||||
*out_argv = cmd_argv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
set_error_print_usage (GError **error, const char *msg, char **argv)
|
|
||||||
{
|
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, msg);
|
|
||||||
usage (argv, TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char **argv)
|
char **argv)
|
||||||
{
|
{
|
||||||
OstreeBuiltin *builtin;
|
return ostree_main (argc, argv, builtins);
|
||||||
GError *error = NULL;
|
|
||||||
int cmd_argc;
|
|
||||||
char **cmd_argv = NULL;
|
|
||||||
gboolean am_root;
|
|
||||||
gboolean have_repo_arg;
|
|
||||||
const char *cmd = NULL;
|
|
||||||
const char *repo = NULL;
|
|
||||||
|
|
||||||
g_type_init ();
|
|
||||||
|
|
||||||
g_set_prgname (argv[0]);
|
|
||||||
|
|
||||||
if (argc < 2)
|
|
||||||
return usage (argv, 1);
|
|
||||||
|
|
||||||
am_root = getuid () == 0;
|
|
||||||
have_repo_arg = g_str_has_prefix (argv[1], "--repo=");
|
|
||||||
|
|
||||||
if (!have_repo_arg && am_root)
|
|
||||||
repo = "/sysroot/ostree/repo";
|
|
||||||
else if (have_repo_arg)
|
|
||||||
repo = argv[1] + strlen ("--repo=");
|
|
||||||
else
|
|
||||||
repo = NULL;
|
|
||||||
|
|
||||||
if (!have_repo_arg)
|
|
||||||
cmd = argv[1];
|
|
||||||
else
|
|
||||||
cmd = argv[2];
|
|
||||||
|
|
||||||
builtin = builtins;
|
|
||||||
while (builtin->name)
|
|
||||||
{
|
|
||||||
if (strcmp (cmd, builtin->name) == 0)
|
|
||||||
break;
|
|
||||||
builtin++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!builtin)
|
|
||||||
{
|
|
||||||
set_error_print_usage (&error, "Unknown command", argv);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (repo == NULL && !(builtin->flags & OSTREE_BUILTIN_FLAG_NO_REPO))
|
|
||||||
{
|
|
||||||
set_error_print_usage (&error, "Command requires a --repo argument", argv);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!have_repo_arg)
|
|
||||||
prep_builtin_argv (cmd, argc-2, argv+2, &cmd_argc, &cmd_argv);
|
|
||||||
else
|
|
||||||
prep_builtin_argv (cmd, argc-3, argv+3, &cmd_argc, &cmd_argv);
|
|
||||||
|
|
||||||
if (!builtin->fn (cmd_argc, cmd_argv, repo, &error))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
out:
|
|
||||||
g_free (cmd_argv);
|
|
||||||
if (error)
|
|
||||||
{
|
|
||||||
g_printerr ("%s\n", error->message);
|
|
||||||
g_clear_error (&error);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,11 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "ot-builtins.h"
|
|
||||||
#include "ostree.h"
|
|
||||||
|
|
||||||
#include <glib/gi18n.h>
|
|
||||||
|
|
||||||
#include <libsoup/soup-gnome.h>
|
#include <libsoup/soup-gnome.h>
|
||||||
|
|
||||||
|
#include "ostree.h"
|
||||||
|
#include "ot-main.h"
|
||||||
|
|
||||||
gboolean verbose;
|
gboolean verbose;
|
||||||
|
|
||||||
static GOptionEntry options[] = {
|
static GOptionEntry options[] = {
|
||||||
|
|
@ -275,7 +273,7 @@ store_commit_recurse (OstreeRepo *repo,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
static gboolean
|
||||||
ostree_builtin_pull (int argc, char **argv, const char *repo_path, GError **error)
|
ostree_builtin_pull (int argc, char **argv, const char *repo_path, GError **error)
|
||||||
{
|
{
|
||||||
GOptionContext *context;
|
GOptionContext *context;
|
||||||
|
|
@ -393,3 +391,15 @@ ostree_builtin_pull (int argc, char **argv, const char *repo_path, GError **erro
|
||||||
g_clear_object (&soup);
|
g_clear_object (&soup);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static OstreeBuiltin builtins[] = {
|
||||||
|
{ "pull", ostree_builtin_pull, 0 },
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc,
|
||||||
|
char **argv)
|
||||||
|
{
|
||||||
|
return ostree_main (argc, argv, builtins);
|
||||||
|
}
|
||||||
|
|
@ -27,17 +27,6 @@
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
OSTREE_BUILTIN_FLAG_NONE = 0,
|
|
||||||
OSTREE_BUILTIN_FLAG_NO_REPO = 1,
|
|
||||||
} OstreeBuiltinFlags;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *name;
|
|
||||||
gboolean (*fn) (int argc, char **argv, const char *repo, GError **error);
|
|
||||||
int flags; /* OstreeBuiltinFlags */
|
|
||||||
} OstreeBuiltin;
|
|
||||||
|
|
||||||
gboolean ostree_builtin_checkout (int argc, char **argv, const char *repo, GError **error);
|
gboolean ostree_builtin_checkout (int argc, char **argv, const char *repo, GError **error);
|
||||||
gboolean ostree_builtin_checksum (int argc, char **argv, const char *repo, GError **error);
|
gboolean ostree_builtin_checksum (int argc, char **argv, const char *repo, GError **error);
|
||||||
gboolean ostree_builtin_commit (int argc, char **argv, const char *repo, GError **error);
|
gboolean ostree_builtin_commit (int argc, char **argv, const char *repo, GError **error);
|
||||||
|
|
@ -47,7 +36,6 @@ gboolean ostree_builtin_init (int argc, char **argv, const char *repo, GError **
|
||||||
gboolean ostree_builtin_local_clone (int argc, char **argv, const char *repo, GError **error);
|
gboolean ostree_builtin_local_clone (int argc, char **argv, const char *repo, GError **error);
|
||||||
gboolean ostree_builtin_log (int argc, char **argv, const char *repo, GError **error);
|
gboolean ostree_builtin_log (int argc, char **argv, const char *repo, GError **error);
|
||||||
gboolean ostree_builtin_ls (int argc, char **argv, const char *repo, GError **error);
|
gboolean ostree_builtin_ls (int argc, char **argv, const char *repo, GError **error);
|
||||||
gboolean ostree_builtin_pull (int argc, char **argv, const char *repo, GError **error);
|
|
||||||
gboolean ostree_builtin_run_triggers (int argc, char **argv, const char *repo, GError **error);
|
gboolean ostree_builtin_run_triggers (int argc, char **argv, const char *repo, GError **error);
|
||||||
gboolean ostree_builtin_fsck (int argc, char **argv, const char *repo, GError **error);
|
gboolean ostree_builtin_fsck (int argc, char **argv, const char *repo, GError **error);
|
||||||
gboolean ostree_builtin_show (int argc, char **argv, const char *repo, GError **error);
|
gboolean ostree_builtin_show (int argc, char **argv, const char *repo, GError **error);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,166 @@
|
||||||
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
||||||
|
*
|
||||||
|
* This library 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 License, 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.
|
||||||
|
*
|
||||||
|
* Author: Colin Walters <walters@verbum.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <gio/gio.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "ot-main.h"
|
||||||
|
|
||||||
|
static int
|
||||||
|
usage (char **argv, OstreeBuiltin *builtins, gboolean is_error)
|
||||||
|
{
|
||||||
|
OstreeBuiltin *builtin = builtins;
|
||||||
|
void (*print_func) (const gchar *format, ...);
|
||||||
|
|
||||||
|
if (is_error)
|
||||||
|
print_func = g_printerr;
|
||||||
|
else
|
||||||
|
print_func = g_print;
|
||||||
|
|
||||||
|
print_func ("usage: %s --repo=PATH COMMAND [options]\n",
|
||||||
|
argv[0]);
|
||||||
|
print_func ("Builtin commands:\n");
|
||||||
|
|
||||||
|
while (builtin->name)
|
||||||
|
{
|
||||||
|
print_func (" %s\n", builtin->name);
|
||||||
|
builtin++;
|
||||||
|
}
|
||||||
|
return (is_error ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
prep_builtin_argv (const char *builtin,
|
||||||
|
int argc,
|
||||||
|
char **argv,
|
||||||
|
int *out_argc,
|
||||||
|
char ***out_argv)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char **cmd_argv;
|
||||||
|
|
||||||
|
cmd_argv = g_new0 (char *, argc + 2);
|
||||||
|
|
||||||
|
cmd_argv[0] = (char*)builtin;
|
||||||
|
for (i = 0; i < argc; i++)
|
||||||
|
cmd_argv[i+1] = argv[i];
|
||||||
|
cmd_argv[i+1] = NULL;
|
||||||
|
*out_argc = argc+1;
|
||||||
|
*out_argv = cmd_argv;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_error_print_usage (GError **error, OstreeBuiltin *builtins, const char *msg, char **argv)
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, msg);
|
||||||
|
usage (argv, builtins, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ostree_main (int argc,
|
||||||
|
char **argv,
|
||||||
|
OstreeBuiltin *builtins)
|
||||||
|
{
|
||||||
|
OstreeBuiltin *builtin;
|
||||||
|
GError *error = NULL;
|
||||||
|
int cmd_argc;
|
||||||
|
char **cmd_argv = NULL;
|
||||||
|
gboolean am_root;
|
||||||
|
gboolean have_repo_arg;
|
||||||
|
const char *cmd = NULL;
|
||||||
|
const char *repo = NULL;
|
||||||
|
int arg_off;
|
||||||
|
|
||||||
|
g_type_init ();
|
||||||
|
|
||||||
|
g_set_prgname (argv[0]);
|
||||||
|
|
||||||
|
if (argc < 2)
|
||||||
|
return usage (argv, builtins, 1);
|
||||||
|
|
||||||
|
am_root = getuid () == 0;
|
||||||
|
have_repo_arg = g_str_has_prefix (argv[1], "--repo=");
|
||||||
|
|
||||||
|
if (!have_repo_arg && am_root)
|
||||||
|
repo = "/sysroot/ostree/repo";
|
||||||
|
else if (have_repo_arg)
|
||||||
|
repo = argv[1] + strlen ("--repo=");
|
||||||
|
else
|
||||||
|
repo = NULL;
|
||||||
|
|
||||||
|
cmd = strchr (argv[0], '-');
|
||||||
|
if (cmd)
|
||||||
|
{
|
||||||
|
cmd += 1;
|
||||||
|
arg_off = 1;
|
||||||
|
if (have_repo_arg)
|
||||||
|
arg_off += 1;
|
||||||
|
}
|
||||||
|
else if (!have_repo_arg)
|
||||||
|
{
|
||||||
|
arg_off = 2;
|
||||||
|
cmd = argv[arg_off-1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arg_off = 3;
|
||||||
|
cmd = argv[arg_off-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
builtin = builtins;
|
||||||
|
while (builtin->name)
|
||||||
|
{
|
||||||
|
if (strcmp (cmd, builtin->name) == 0)
|
||||||
|
break;
|
||||||
|
builtin++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!builtin->name)
|
||||||
|
{
|
||||||
|
set_error_print_usage (&error, builtins, "Unknown command", argv);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (repo == NULL && !(builtin->flags & OSTREE_BUILTIN_FLAG_NO_REPO))
|
||||||
|
{
|
||||||
|
set_error_print_usage (&error, builtins, "Command requires a --repo argument", argv);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
prep_builtin_argv (cmd, argc-arg_off, argv+arg_off, &cmd_argc, &cmd_argv);
|
||||||
|
|
||||||
|
if (!builtin->fn (cmd_argc, cmd_argv, repo, &error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
out:
|
||||||
|
g_free (cmd_argv);
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
g_printerr ("%s\n", error->message);
|
||||||
|
g_clear_error (&error);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
||||||
|
*
|
||||||
|
* This library 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 License, 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.
|
||||||
|
*
|
||||||
|
* Author: Colin Walters <walters@verbum.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gio/gio.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
OSTREE_BUILTIN_FLAG_NONE = 0,
|
||||||
|
OSTREE_BUILTIN_FLAG_NO_REPO = 1,
|
||||||
|
} OstreeBuiltinFlags;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char *name;
|
||||||
|
gboolean (*fn) (int argc, char **argv, const char *repo, GError **error);
|
||||||
|
int flags; /* OstreeBuiltinFlags */
|
||||||
|
} OstreeBuiltin;
|
||||||
|
|
||||||
|
int ostree_main (int argc, char **argv, OstreeBuiltin *builtins);
|
||||||
|
|
||||||
|
|
@ -26,9 +26,9 @@ echo '1..2'
|
||||||
setup_fake_remote_repo1
|
setup_fake_remote_repo1
|
||||||
cd ${test_tmpdir}
|
cd ${test_tmpdir}
|
||||||
mkdir repo
|
mkdir repo
|
||||||
$OSTREE init
|
ostree --repo=repo init
|
||||||
$OSTREE remote add origin $(cat httpd-address)/ostree/gnomerepo
|
ostree --repo=repo remote add origin $(cat httpd-address)/ostree/gnomerepo
|
||||||
$OSTREE pull origin main
|
ostree-pull --repo=repo origin main
|
||||||
echo "ok pull"
|
echo "ok pull"
|
||||||
|
|
||||||
cd ${test_tmpdir}
|
cd ${test_tmpdir}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue