admin: Allow specifying --boot-dir

This is intended for use by QA tools that want to manipulate a
loopback-mounted disk image or the like.
This commit is contained in:
Colin Walters 2013-01-02 22:44:06 -05:00
parent 6c9c7b0173
commit 2db497fd3f
12 changed files with 61 additions and 31 deletions

View File

@ -30,6 +30,7 @@
typedef struct { typedef struct {
OstreeRepo *repo; OstreeRepo *repo;
OtAdminBuiltinOpts *admin_opts;
GFile *ostree_dir; GFile *ostree_dir;
char *osname; char *osname;
GFile *osname_dir; GFile *osname_dir;
@ -621,7 +622,7 @@ do_update_kernel (OtAdminDeploy *self,
} }
gboolean gboolean
ot_admin_builtin_deploy (int argc, char **argv, GFile *ostree_dir, GError **error) ot_admin_builtin_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{ {
GOptionContext *context; GOptionContext *context;
OtAdminDeploy self_data; OtAdminDeploy self_data;
@ -649,7 +650,8 @@ ot_admin_builtin_deploy (int argc, char **argv, GFile *ostree_dir, GError **erro
goto out; goto out;
} }
self->ostree_dir = g_object_ref (ostree_dir); self->admin_opts = admin_opts;
self->ostree_dir = g_object_ref (admin_opts->ostree_dir);
if (!ot_admin_ensure_initialized (self->ostree_dir, cancellable, error)) if (!ot_admin_ensure_initialized (self->ostree_dir, cancellable, error))
goto out; goto out;

View File

@ -33,11 +33,12 @@ static GOptionEntry options[] = {
}; };
gboolean gboolean
ot_admin_builtin_diff (int argc, char **argv, GFile *ostree_dir, GError **error) ot_admin_builtin_diff (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{ {
GOptionContext *context; GOptionContext *context;
gboolean ret = FALSE; gboolean ret = FALSE;
const char *osname; const char *osname;
GFile *ostree_dir = admin_opts->ostree_dir;
ot_lobj GFile *repo_path = NULL; ot_lobj GFile *repo_path = NULL;
ot_lobj GFile *deployment = NULL; ot_lobj GFile *deployment = NULL;
ot_lobj GFile *deploy_parent = NULL; ot_lobj GFile *deploy_parent = NULL;

View File

@ -33,7 +33,7 @@ static GOptionEntry options[] = {
}; };
gboolean gboolean
ot_admin_builtin_init_fs (int argc, char **argv, GFile *ostree_dir, GError **error) ot_admin_builtin_init_fs (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{ {
GOptionContext *context; GOptionContext *context;
gboolean ret = FALSE; gboolean ret = FALSE;

View File

@ -62,7 +62,7 @@ on_keyfile_retrieved (GObject *obj,
} }
gboolean gboolean
ot_admin_builtin_install (int argc, char **argv, GFile *ostree_dir, GError **error) ot_admin_builtin_install (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{ {
OtAdminBuiltinInstall self_data; OtAdminBuiltinInstall self_data;
OtAdminBuiltinInstall *self = &self_data; OtAdminBuiltinInstall *self = &self_data;
@ -70,6 +70,7 @@ ot_admin_builtin_install (int argc, char **argv, GFile *ostree_dir, GError **err
gboolean ret = FALSE; gboolean ret = FALSE;
const char *keyfile_arg = NULL; const char *keyfile_arg = NULL;
const char *treename_arg = NULL; const char *treename_arg = NULL;
GFile *ostree_dir = admin_opts->ostree_dir;
ot_lobj GFile *deploy_dir = NULL; ot_lobj GFile *deploy_dir = NULL;
ot_lobj GFile *osdir = NULL; ot_lobj GFile *osdir = NULL;
ot_lobj GFile *dest_osconfig_path = NULL; ot_lobj GFile *dest_osconfig_path = NULL;

View File

@ -33,11 +33,12 @@ static GOptionEntry options[] = {
}; };
gboolean gboolean
ot_admin_builtin_os_init (int argc, char **argv, GFile *ostree_dir, GError **error) ot_admin_builtin_os_init (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{ {
GOptionContext *context; GOptionContext *context;
gboolean ret = FALSE; gboolean ret = FALSE;
const char *osname = NULL; const char *osname = NULL;
GFile *ostree_dir = admin_opts->ostree_dir;
ot_lobj GFile *deploy_dir = NULL; ot_lobj GFile *deploy_dir = NULL;
ot_lobj GFile *dir = NULL; ot_lobj GFile *dir = NULL;
__attribute__((unused)) GCancellable *cancellable = NULL; __attribute__((unused)) GCancellable *cancellable = NULL;

View File

@ -98,12 +98,13 @@ list_deployments (GFile *from_dir,
} }
gboolean gboolean
ot_admin_builtin_prune (int argc, char **argv, GFile *ostree_dir, GError **error) ot_admin_builtin_prune (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{ {
GOptionContext *context; GOptionContext *context;
gboolean ret = FALSE; gboolean ret = FALSE;
guint i; guint i;
const char *osname; const char *osname;
GFile *ostree_dir = admin_opts->ostree_dir;
ot_lobj GFile *repo_path = NULL; ot_lobj GFile *repo_path = NULL;
ot_lobj GFile *deploy_dir = NULL; ot_lobj GFile *deploy_dir = NULL;
ot_lobj GFile *current_deployment = NULL; ot_lobj GFile *current_deployment = NULL;

View File

@ -51,11 +51,12 @@ parse_deploy_name_from_path (GFile *osdir,
} }
gboolean gboolean
ot_admin_builtin_pull_deploy (int argc, char **argv, GFile *ostree_dir, GError **error) ot_admin_builtin_pull_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{ {
GOptionContext *context; GOptionContext *context;
gboolean ret = FALSE; gboolean ret = FALSE;
const char *osname; const char *osname;
GFile *ostree_dir = admin_opts->ostree_dir;
ot_lobj GFile *repo_path = NULL; ot_lobj GFile *repo_path = NULL;
ot_lobj GFile *current_deployment = NULL; ot_lobj GFile *current_deployment = NULL;
ot_lfree char *deploy_name = NULL; ot_lfree char *deploy_name = NULL;

View File

@ -35,7 +35,7 @@ static GOptionEntry options[] = {
}; };
gboolean gboolean
ot_admin_builtin_run_triggers (int argc, char **argv, GFile *ostree_dir, GError **error) ot_admin_builtin_run_triggers (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{ {
GOptionContext *context; GOptionContext *context;
gboolean ret = FALSE; gboolean ret = FALSE;

View File

@ -29,7 +29,9 @@
#include <sys/utsname.h> #include <sys/utsname.h>
typedef struct { typedef struct {
OtAdminBuiltinOpts *admin_opts;
GFile *ostree_dir; GFile *ostree_dir;
GFile *boot_ostree_dir;
const char *deploy_path; const char *deploy_path;
GFile *kernel_path; GFile *kernel_path;
char *release; char *release;
@ -122,7 +124,6 @@ setup_kernel (OtAdminUpdateKernel *self,
ot_lobj GFile *deploy_path = NULL; ot_lobj GFile *deploy_path = NULL;
ot_lobj GFile *deploy_boot_path = NULL; ot_lobj GFile *deploy_boot_path = NULL;
ot_lobj GFile *src_kernel_path = NULL; ot_lobj GFile *src_kernel_path = NULL;
ot_lobj GFile *host_boot = NULL;
ot_lfree char *prefix = NULL; ot_lfree char *prefix = NULL;
const char *release = NULL; const char *release = NULL;
const char *kernel_name = NULL; const char *kernel_name = NULL;
@ -140,8 +141,7 @@ setup_kernel (OtAdminUpdateKernel *self,
goto out; goto out;
} }
host_boot = g_file_new_for_path ("/boot/ostree"); if (!gs_file_ensure_directory (self->boot_ostree_dir, TRUE, cancellable, error))
if (!gs_file_ensure_directory (host_boot, TRUE, cancellable, error))
goto out; goto out;
kernel_name = gs_file_get_basename_cached (src_kernel_path); kernel_name = gs_file_get_basename_cached (src_kernel_path);
@ -155,7 +155,7 @@ setup_kernel (OtAdminUpdateKernel *self,
self->release = g_strdup (release + 1); self->release = g_strdup (release + 1);
prefix = g_strndup (kernel_name, release - kernel_name); prefix = g_strndup (kernel_name, release - kernel_name);
self->kernel_path = ot_gfile_get_child_strconcat (host_boot, prefix, "-", self->release, NULL); self->kernel_path = ot_gfile_get_child_strconcat (self->boot_ostree_dir, prefix, "-", self->release, NULL);
if (!g_file_copy (src_kernel_path, self->kernel_path, if (!g_file_copy (src_kernel_path, self->kernel_path,
G_FILE_COPY_OVERWRITE | G_FILE_COPY_ALL_METADATA | G_FILE_COPY_NOFOLLOW_SYMLINKS, G_FILE_COPY_OVERWRITE | G_FILE_COPY_ALL_METADATA | G_FILE_COPY_NOFOLLOW_SYMLINKS,
@ -183,7 +183,7 @@ update_initramfs (OtAdminUpdateKernel *self,
initramfs_name = g_strconcat ("initramfs-", self->release, ".img", NULL); initramfs_name = g_strconcat ("initramfs-", self->release, ".img", NULL);
initramfs_file = ot_gfile_from_build_path ("/boot", "ostree", initramfs_name, NULL); initramfs_file = g_file_get_child (self->boot_ostree_dir, initramfs_name);
if (!g_file_query_exists (initramfs_file, NULL)) if (!g_file_query_exists (initramfs_file, NULL))
{ {
gs_unref_ptrarray GPtrArray *mkinitramfs_args = NULL; gs_unref_ptrarray GPtrArray *mkinitramfs_args = NULL;
@ -324,7 +324,7 @@ get_kernel_path_from_release (OtAdminUpdateKernel *self,
/* TODO - replace this with grubby code */ /* TODO - replace this with grubby code */
name = g_strconcat ("vmlinuz-", release, NULL); name = g_strconcat ("vmlinuz-", release, NULL);
possible_path = ot_gfile_from_build_path ("/boot", name, NULL); possible_path = g_file_get_child (self->admin_opts->boot_dir, name);
if (!g_file_query_exists (possible_path, cancellable)) if (!g_file_query_exists (possible_path, cancellable))
g_clear_object (&possible_path); g_clear_object (&possible_path);
@ -340,7 +340,7 @@ update_grub (OtAdminUpdateKernel *self,
GError **error) GError **error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
ot_lobj GFile *grub_path = g_file_new_for_path ("/boot/grub/grub.conf"); ot_lobj GFile *grub_path = g_file_resolve_relative_path (self->admin_opts->boot_dir, "grub/grub.conf");
if (g_file_query_exists (grub_path, cancellable)) if (g_file_query_exists (grub_path, cancellable))
{ {
@ -353,7 +353,9 @@ update_grub (OtAdminUpdateKernel *self,
{ {
ot_lfree char *add_kernel_arg = NULL; ot_lfree char *add_kernel_arg = NULL;
ot_lfree char *initramfs_arg = NULL; ot_lfree char *initramfs_arg = NULL;
ot_lfree char *initramfs_name = NULL;
ot_lobj GFile *kernel_path = NULL; ot_lobj GFile *kernel_path = NULL;
ot_lobj GFile *initramfs_path = NULL;
if (!self->kernel_path) if (!self->kernel_path)
{ {
@ -371,8 +373,11 @@ update_grub (OtAdminUpdateKernel *self,
else else
kernel_path = g_object_ref (self->kernel_path); kernel_path = g_object_ref (self->kernel_path);
initramfs_name = g_strconcat ("initramfs-", self->release, ".img", NULL);
initramfs_path = g_file_get_child (self->boot_ostree_dir, initramfs_name);
add_kernel_arg = g_strconcat ("--add-kernel=", gs_file_get_path_cached (kernel_path), NULL); add_kernel_arg = g_strconcat ("--add-kernel=", gs_file_get_path_cached (kernel_path), NULL);
initramfs_arg = g_strconcat ("--initrd=", "/boot/ostree/initramfs-", self->release, ".img", NULL); initramfs_arg = g_strconcat ("--initrd=", gs_file_get_path_cached (initramfs_path), NULL);
g_print ("Adding OSTree grub entry...\n"); g_print ("Adding OSTree grub entry...\n");
if (!gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_NULL, if (!gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_NULL,
@ -395,17 +400,20 @@ update_grub (OtAdminUpdateKernel *self,
} }
gboolean gboolean
ot_admin_builtin_update_kernel (int argc, char **argv, GFile *ostree_dir, GError **error) ot_admin_builtin_update_kernel (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{ {
GOptionContext *context; GOptionContext *context;
OtAdminUpdateKernel self_data; OtAdminUpdateKernel self_data;
OtAdminUpdateKernel *self = &self_data; OtAdminUpdateKernel *self = &self_data;
GFile *ostree_dir = admin_opts->ostree_dir;
gboolean ret = FALSE; gboolean ret = FALSE;
struct utsname utsname; struct utsname utsname;
GCancellable *cancellable = NULL; GCancellable *cancellable = NULL;
memset (self, 0, sizeof (*self)); memset (self, 0, sizeof (*self));
self->admin_opts = admin_opts;
context = g_option_context_new ("OSNAME DEPLOY_PATH - Update kernel and regenerate initial ramfs"); context = g_option_context_new ("OSNAME DEPLOY_PATH - Update kernel and regenerate initial ramfs");
g_option_context_add_main_entries (context, options, NULL); g_option_context_add_main_entries (context, options, NULL);
@ -446,6 +454,7 @@ ot_admin_builtin_update_kernel (int argc, char **argv, GFile *ostree_dir, GError
} }
self->ostree_dir = g_object_ref (ostree_dir); self->ostree_dir = g_object_ref (ostree_dir);
self->boot_ostree_dir = g_file_get_child (admin_opts->boot_dir, "ostree");
if (opt_host_kernel) if (opt_host_kernel)
{ {
@ -471,6 +480,7 @@ ot_admin_builtin_update_kernel (int argc, char **argv, GFile *ostree_dir, GError
ret = TRUE; ret = TRUE;
out: out:
g_clear_object (&self->ostree_dir); g_clear_object (&self->ostree_dir);
g_clear_object (&self->boot_ostree_dir);
g_clear_object (&self->kernel_path); g_clear_object (&self->kernel_path);
g_free (self->release); g_free (self->release);
if (context) if (context)

View File

@ -35,10 +35,11 @@ static GOptionEntry options[] = {
}; };
gboolean gboolean
ot_admin_builtin_upgrade (int argc, char **argv, GFile *ostree_dir, GError **error) ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error)
{ {
GOptionContext *context; GOptionContext *context;
gboolean ret = FALSE; gboolean ret = FALSE;
GFile *ostree_dir = admin_opts->ostree_dir;
const char *osname = NULL; const char *osname = NULL;
gs_free char *ostree_dir_arg = NULL; gs_free char *ostree_dir_arg = NULL;
__attribute__((unused)) GCancellable *cancellable = NULL; __attribute__((unused)) GCancellable *cancellable = NULL;

View File

@ -27,16 +27,21 @@
G_BEGIN_DECLS G_BEGIN_DECLS
gboolean ot_admin_builtin_os_init (int argc, char **argv, GFile *ostree_dir, GError **error); typedef struct {
gboolean ot_admin_builtin_install (int argc, char **argv, GFile *ostree_dir, GError **error); GFile *ostree_dir;
gboolean ot_admin_builtin_init_fs (int argc, char **argv, GFile *ostree_dir, GError **error); GFile *boot_dir;
gboolean ot_admin_builtin_deploy (int argc, char **argv, GFile *ostree_dir, GError **error); } OtAdminBuiltinOpts;
gboolean ot_admin_builtin_prune (int argc, char **argv, GFile *ostree_dir, GError **error);
gboolean ot_admin_builtin_pull_deploy (int argc, char **argv, GFile *ostree_dir, GError **error); gboolean ot_admin_builtin_os_init (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
gboolean ot_admin_builtin_diff (int argc, char **argv, GFile *ostree_dir, GError **error); gboolean ot_admin_builtin_install (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
gboolean ot_admin_builtin_run_triggers (int argc, char **argv, GFile *ostree_dir, GError **error); gboolean ot_admin_builtin_init_fs (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
gboolean ot_admin_builtin_update_kernel (int argc, char **argv, GFile *ostree_dir, GError **error); gboolean ot_admin_builtin_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
gboolean ot_admin_builtin_upgrade (int argc, char **argv, GFile *ostree_dir, GError **error); gboolean ot_admin_builtin_prune (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
gboolean ot_admin_builtin_pull_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
gboolean ot_admin_builtin_diff (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
gboolean ot_admin_builtin_run_triggers (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
gboolean ot_admin_builtin_update_kernel (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
gboolean ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
G_END_DECLS G_END_DECLS

View File

@ -31,15 +31,17 @@
#include <glib/gi18n.h> #include <glib/gi18n.h>
static char *opt_ostree_dir = "/ostree"; static char *opt_ostree_dir = "/ostree";
static char *opt_boot_dir = "/boot";
static GOptionEntry options[] = { static GOptionEntry options[] = {
{ "ostree-dir", 0, 0, G_OPTION_ARG_STRING, &opt_ostree_dir, "Path to OSTree root directory (default: /ostree)", NULL }, { "ostree-dir", 0, 0, G_OPTION_ARG_STRING, &opt_ostree_dir, "Path to OSTree root directory (default: /ostree)", NULL },
{ "boot-dir", 0, 0, G_OPTION_ARG_STRING, &opt_boot_dir, "Path to system boot directory (default: /boot)", NULL },
{ NULL } { NULL }
}; };
typedef struct { typedef struct {
const char *name; const char *name;
gboolean (*fn) (int argc, char **argv, GFile *ostree_dir, GError **error); gboolean (*fn) (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error);
} OstreeAdminCommand; } OstreeAdminCommand;
static OstreeAdminCommand admin_subcommands[] = { static OstreeAdminCommand admin_subcommands[] = {
@ -65,8 +67,10 @@ ostree_builtin_admin (int argc, char **argv, GFile *repo_path, GError **error)
const char *subcommand_name; const char *subcommand_name;
OstreeAdminCommand *subcommand; OstreeAdminCommand *subcommand;
int subcmd_argc; int subcmd_argc;
OtAdminBuiltinOpts admin_opts;
char **subcmd_argv = NULL; char **subcmd_argv = NULL;
ot_lobj GFile *ostree_dir = NULL; ot_lobj GFile *ostree_dir = NULL;
ot_lobj GFile *boot_dir = NULL;
context = g_option_context_new ("[OPTIONS] SUBCOMMAND - Run an administrative subcommand"); context = g_option_context_new ("[OPTIONS] SUBCOMMAND - Run an administrative subcommand");
@ -113,10 +117,13 @@ ostree_builtin_admin (int argc, char **argv, GFile *repo_path, GError **error)
} }
ostree_dir = g_file_new_for_path (opt_ostree_dir); ostree_dir = g_file_new_for_path (opt_ostree_dir);
boot_dir = g_file_new_for_path (opt_boot_dir);
ostree_prep_builtin_argv (subcommand_name, argc-2, argv+2, &subcmd_argc, &subcmd_argv); ostree_prep_builtin_argv (subcommand_name, argc-2, argv+2, &subcmd_argc, &subcmd_argv);
if (!subcommand->fn (subcmd_argc, subcmd_argv, ostree_dir, error)) admin_opts.ostree_dir = ostree_dir;
admin_opts.boot_dir = boot_dir;
if (!subcommand->fn (subcmd_argc, subcmd_argv, &admin_opts, error))
goto out; goto out;
ret = TRUE; ret = TRUE;