diff options
author | Colin Walters <walters@verbum.org> | 2012-12-19 17:52:46 -0500 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2012-12-21 13:47:15 -0500 |
commit | 3832544ac40b5bbfcee3621cc5ab096ac64e578d (patch) | |
tree | d951a4240dda9cf8f2ee1df3d515546dc1768096 /src/ostree/ot-admin-builtin-os-init.c | |
parent | 16d312e82f08f27bfa4d4f3dd4b0404ceab731de (diff) | |
download | ostree-3832544ac40b5bbfcee3621cc5ab096ac64e578d.tar.gz |
admin: Rework /ostree/deploy to support multiple independent operating systems
The real vision of OSTree is to "multiple versions of multiple
operating systems". Up until now, it's worked to install gnome-ostree
inside a host distribution, but several things don't work quite right
if you try to do completely different systems.
In the new model, there's the concept of an "osname" which encompasses
a few properties:
1) Its own /var
2) A set of trees deployed in /ostree/deploy/OSNAME/
3) Its own "current" and "previous" links.
Now it no longer really makes sense to boot with "ostree=current".
Instead, you specify e.g. "ostree=gnome/current".
This is an incompatible change to the deployment code - you will need
to run init-os gnome and redeploy.
All "ostree admin" subcommands now take an OSNAME argument.
Diffstat (limited to 'src/ostree/ot-admin-builtin-os-init.c')
-rw-r--r-- | src/ostree/ot-admin-builtin-os-init.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/ostree/ot-admin-builtin-os-init.c b/src/ostree/ot-admin-builtin-os-init.c new file mode 100644 index 00000000..3cd38aa8 --- /dev/null +++ b/src/ostree/ot-admin-builtin-os-init.c @@ -0,0 +1,105 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2012 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 "ot-admin-builtins.h" +#include "ot-admin-functions.h" +#include "otutil.h" + +#include <glib/gi18n.h> + +static GOptionEntry options[] = { + { NULL } +}; + +gboolean +ot_admin_builtin_os_init (int argc, char **argv, GFile *ostree_dir, GError **error) +{ + GOptionContext *context; + gboolean ret = FALSE; + const char *osname = NULL; + ot_lobj GFile *deploy_dir = NULL; + ot_lobj GFile *dir = NULL; + __attribute__((unused)) GCancellable *cancellable = NULL; + + context = g_option_context_new ("OSNAME - Initialize empty state for given operating system"); + g_option_context_add_main_entries (context, options, NULL); + + if (!g_option_context_parse (context, &argc, &argv, error)) + goto out; + + if (!ot_admin_ensure_initialized (ostree_dir, cancellable, error)) + goto out; + + if (argc < 2) + { + ot_util_usage_error (context, "OSNAME must be specified", error); + goto out; + } + + osname = argv[1]; + + deploy_dir = ot_gfile_get_child_build_path (ostree_dir, "deploy", osname, NULL); + + /* Ensure core subdirectories of /var exist, since we need them for + * dracut generation, and the host will want them too. + */ + g_clear_object (&dir); + dir = ot_gfile_get_child_build_path (deploy_dir, "var", "log", NULL); + if (!gs_file_ensure_directory (dir, TRUE, cancellable, error)) + goto out; + + g_clear_object (&dir); + dir = ot_gfile_get_child_build_path (deploy_dir, "var", "tmp", NULL); + if (!gs_file_ensure_directory (dir, TRUE, cancellable, error)) + goto out; + if (chmod (gs_file_get_path_cached (dir), 01777) < 0) + { + ot_util_set_error_from_errno (error, errno); + goto out; + } + + g_clear_object (&dir); + dir = ot_gfile_get_child_build_path (deploy_dir, "var", "lib", NULL); + if (!gs_file_ensure_directory (dir, TRUE, cancellable, error)) + goto out; + + g_clear_object (&dir); + dir = ot_gfile_get_child_build_path (deploy_dir, "var", "run", NULL); + if (!g_file_test (gs_file_get_path_cached (dir), G_FILE_TEST_IS_SYMLINK)) + { + if (symlink ("../run", gs_file_get_path_cached (dir)) < 0) + { + ot_util_set_error_from_errno (error, errno); + goto out; + } + } + + g_print ("%s initialized as OSTree root\n", gs_file_get_path_cached (deploy_dir)); + + ret = TRUE; + out: + if (context) + g_option_context_free (context); + return ret; +} |