Add upgrade builtin

This is just the start of moving more functionality into rpm-ostree,
with the goal of more tightly binding the rpm and ostree worldviews.

For exmaple, supporting package installation on top, showing the
package-level diff between trees, etc.
This commit is contained in:
Colin Walters 2014-03-24 18:11:21 -04:00
parent 1319e1616d
commit c2b242f200
4 changed files with 143 additions and 0 deletions

View File

@ -25,6 +25,7 @@ rpm_ostree_SOURCES = src/main.c \
src/rpmostree-builtins.h \
src/rpmostree-builtin-treecompose.c \
src/rpmostree-builtin-sign.c \
src/rpmostree-builtin-upgrade.c \
$(NULL)
rpm_ostree_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/src -DPKGLIBDIR=\"$(pkglibdir)\" $(PKGDEP_RPMOSTREE_CFLAGS)
rpm_ostree_LDADD = $(AM_LDFLAGS) $(PKGDEP_RPMOSTREE_LIBS)

View File

@ -34,6 +34,7 @@
static RpmOstreeCommand commands[] = {
{ "treecompose", rpmostree_builtin_treecompose, 0 },
{ "sign", rpmostree_builtin_sign, 0 },
{ "upgrade", rpmostree_builtin_upgrade, 0 },
{ NULL }
};

View File

@ -0,0 +1,140 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright (C) 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.
*/
#include "config.h"
#include <string.h>
#include <glib-unix.h>
#include "rpmostree-builtins.h"
#include "libgsystem.h"
static gboolean opt_reboot;
static GOptionEntry option_entries[] = {
{ "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Initiate a reboot after an upgrade is prepared", NULL },
{ NULL }
};
static void
pull_progress (OstreeAsyncProgress *progress,
gpointer user_data)
{
GSConsole *console = user_data;
GString *buf;
gs_free char *status = NULL;
guint outstanding_fetches;
guint outstanding_writes;
guint n_scanned_metadata;
if (!console)
return;
buf = g_string_new ("");
status = ostree_async_progress_get_status (progress);
outstanding_fetches = ostree_async_progress_get_uint (progress, "outstanding-fetches");
outstanding_writes = ostree_async_progress_get_uint (progress, "outstanding-writes");
n_scanned_metadata = ostree_async_progress_get_uint (progress, "scanned-metadata");
if (status)
{
g_string_append (buf, status);
}
else if (outstanding_fetches)
{
guint64 bytes_transferred = ostree_async_progress_get_uint64 (progress, "bytes-transferred");
guint fetched = ostree_async_progress_get_uint (progress, "fetched");
guint requested = ostree_async_progress_get_uint (progress, "requested");
gs_free char *formatted_bytes_transferred =
g_format_size_full (bytes_transferred, 0);
g_string_append_printf (buf, "Receiving objects: %u%% (%u/%u) %s",
(guint)((((double)fetched) / requested) * 100),
fetched, requested, formatted_bytes_transferred);
}
else if (outstanding_writes)
{
g_string_append_printf (buf, "Writing objects: %u", outstanding_writes);
}
else
{
g_string_append_printf (buf, "Scanning metadata: %u", n_scanned_metadata);
}
gs_console_begin_status_line (console, buf->str, NULL, NULL);
g_string_free (buf, TRUE);
}
gboolean
rpmostree_builtin_upgrade (int argc,
char **argv,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
GOptionContext *context = g_option_context_new ("- Perform a system upgrade");
gs_unref_object OstreeSysroot *sysroot = NULL;
gs_unref_object OstreeSysrootUpgrader *upgrader = NULL;
gs_unref_object OstreeAsyncProgress *progress = NULL;
GSConsole *console;
gboolean changed;
g_option_context_add_main_entries (context, option_entries, NULL);
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;
sysroot = ostree_sysroot_new_default ();
if (!ostree_sysroot_load (sysroot, cancellable, error))
goto out;
upgrader = ostree_sysroot_upgrader_new (sysroot, cancellable, error);
if (!upgrader)
goto out;
console = gs_console_get ();
if (console)
{
gs_console_begin_status_line (console, "", NULL, NULL);
progress = ostree_async_progress_new_and_connect (pull_progress, console);
}
if (!ostree_sysroot_upgrader_pull (upgrader, 0, 0, progress, &changed,
cancellable, error))
goto out;
if (!changed)
{
g_print ("No update available.\n");
}
else if (opt_reboot)
{
gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
cancellable, error,
"systemctl", "reboot", NULL);
}
ret = TRUE;
out:
return ret;
}

View File

@ -34,6 +34,7 @@ typedef struct {
BUILTINPROTO(treecompose);
BUILTINPROTO(sign);
BUILTINPROTO(upgrade);
#undef BUILTINPROTO