admin: Add -r option to upgrade to initiate a reboot if tree changes
$ ostree admin upgrade -r is convenient to fire off inside a VM and come back to it later.
This commit is contained in:
parent
18af230e17
commit
f9484e9bab
|
|
@ -35,21 +35,6 @@ static GOptionEntry options[] = {
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *
|
|
||||||
parse_deploy_name_from_path (GFile *osdir,
|
|
||||||
GFile *path)
|
|
||||||
{
|
|
||||||
ot_lfree char *relpath = g_file_get_relative_path (osdir, path);
|
|
||||||
const char *last_dash;
|
|
||||||
|
|
||||||
g_assert (relpath);
|
|
||||||
last_dash = strrchr (relpath, '-');
|
|
||||||
if (!last_dash)
|
|
||||||
g_error ("Failed to parse deployment name %s", relpath);
|
|
||||||
|
|
||||||
return g_strndup (relpath, last_dash - relpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ensure_remote_branch (OstreeRepo *repo,
|
ensure_remote_branch (OstreeRepo *repo,
|
||||||
const char *remote,
|
const char *remote,
|
||||||
|
|
@ -116,7 +101,6 @@ ot_admin_builtin_pull_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_o
|
||||||
ot_lobj GFile *current_deployment = NULL;
|
ot_lobj GFile *current_deployment = NULL;
|
||||||
ot_lfree char *deploy_name = NULL;
|
ot_lfree char *deploy_name = NULL;
|
||||||
ot_lobj GFile *deploy_dir = NULL;
|
ot_lobj GFile *deploy_dir = NULL;
|
||||||
ot_lobj GFile *os_dir = NULL;
|
|
||||||
ot_lfree char *remote_name = NULL;
|
ot_lfree char *remote_name = NULL;
|
||||||
ot_lptrarray GPtrArray *subproc_args = NULL;
|
ot_lptrarray GPtrArray *subproc_args = NULL;
|
||||||
__attribute__((unused)) GCancellable *cancellable = NULL;
|
__attribute__((unused)) GCancellable *cancellable = NULL;
|
||||||
|
|
@ -142,9 +126,6 @@ ot_admin_builtin_pull_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_o
|
||||||
if (!ostree_repo_check (repo, error))
|
if (!ostree_repo_check (repo, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
deploy_dir = g_file_get_child (ostree_dir, "deploy");
|
|
||||||
os_dir = g_file_get_child (deploy_dir, osname);
|
|
||||||
|
|
||||||
if (argc > 2)
|
if (argc > 2)
|
||||||
{
|
{
|
||||||
target = argv[2];
|
target = argv[2];
|
||||||
|
|
@ -167,20 +148,12 @@ ot_admin_builtin_pull_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_o
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
deploy_name = parse_deploy_name_from_path (os_dir, current_deployment);
|
ot_admin_parse_deploy_name (ostree_dir, osname, current_deployment,
|
||||||
|
&deploy_name, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
if (!ot_admin_pull (ostree_dir, osname, cancellable, error))
|
||||||
ot_lfree char *repo_arg = g_strconcat ("--repo=",
|
goto out;
|
||||||
gs_file_get_path_cached (repo_path),
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (!gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
|
|
||||||
GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
|
|
||||||
cancellable, error,
|
|
||||||
"ostree", "pull", repo_arg, osname, NULL))
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
ot_lfree char *opt_ostree_dir_arg = g_strconcat ("--ostree-dir=",
|
ot_lfree char *opt_ostree_dir_arg = g_strconcat ("--ostree-dir=",
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,17 @@
|
||||||
|
|
||||||
#include "ot-admin-builtins.h"
|
#include "ot-admin-builtins.h"
|
||||||
#include "ot-admin-functions.h"
|
#include "ot-admin-functions.h"
|
||||||
|
#include "ostree.h"
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
|
static gboolean opt_reboot;
|
||||||
|
|
||||||
static GOptionEntry options[] = {
|
static GOptionEntry options[] = {
|
||||||
|
{ "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Reboot after a successful upgrade", NULL },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -42,6 +46,12 @@ ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts,
|
||||||
GFile *ostree_dir = admin_opts->ostree_dir;
|
GFile *ostree_dir = admin_opts->ostree_dir;
|
||||||
gs_free char *booted_osname = NULL;
|
gs_free char *booted_osname = NULL;
|
||||||
const char *osname = NULL;
|
const char *osname = NULL;
|
||||||
|
gs_unref_object GFile *deployment = NULL;
|
||||||
|
gs_unref_object GFile *repo_path = NULL;
|
||||||
|
gs_unref_object OstreeRepo *repo = NULL;
|
||||||
|
gs_free char *deploy_name = NULL;
|
||||||
|
gs_free char *current_rev = NULL;
|
||||||
|
gs_free char *new_rev = 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;
|
||||||
|
|
||||||
|
|
@ -57,7 +67,8 @@ ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!ot_admin_get_active_deployment (NULL, &booted_osname, NULL, cancellable, error))
|
if (!ot_admin_get_booted_os (&booted_osname, NULL,
|
||||||
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
if (booted_osname == NULL)
|
if (booted_osname == NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -67,15 +78,18 @@ ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts,
|
||||||
}
|
}
|
||||||
osname = booted_osname;
|
osname = booted_osname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ot_admin_get_current_deployment (ostree_dir, osname, &deployment,
|
||||||
|
cancellable, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
ot_admin_parse_deploy_name (ostree_dir, osname, deployment, &deploy_name, ¤t_rev);
|
||||||
|
|
||||||
ostree_dir_arg = g_strconcat ("--ostree-dir=",
|
ostree_dir_arg = g_strconcat ("--ostree-dir=",
|
||||||
gs_file_get_path_cached (ostree_dir),
|
gs_file_get_path_cached (ostree_dir),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
|
if (!ot_admin_pull (ostree_dir, osname, cancellable, error))
|
||||||
GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
|
|
||||||
cancellable, error,
|
|
||||||
"ostree", "admin", ostree_dir_arg, "pull-deploy", osname, NULL))
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (!gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
|
if (!gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
|
||||||
|
|
@ -84,6 +98,26 @@ ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts,
|
||||||
"ostree", "admin", ostree_dir_arg, "prune", osname, NULL))
|
"ostree", "admin", ostree_dir_arg, "prune", osname, NULL))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
if (opt_reboot)
|
||||||
|
{
|
||||||
|
repo_path = g_file_get_child (ostree_dir, "repo");
|
||||||
|
|
||||||
|
repo = ostree_repo_new (repo_path);
|
||||||
|
if (!ostree_repo_check (repo, error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (!ostree_repo_resolve_rev (repo, deploy_name, TRUE, &new_rev,
|
||||||
|
error))
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
if (strcmp (current_rev, new_rev) != 0 && opt_reboot)
|
||||||
|
{
|
||||||
|
gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
|
||||||
|
cancellable, error,
|
||||||
|
"systemctl", "reboot", NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
if (context)
|
if (context)
|
||||||
|
|
|
||||||
|
|
@ -313,11 +313,11 @@ ot_admin_list_deployments (GFile *ostree_dir,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
gboolean
|
||||||
ot_admin_get_booted_os (char **out_osname,
|
ot_admin_get_booted_os (char **out_osname,
|
||||||
char **out_tree,
|
char **out_tree,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gs_free char *ret_osname = NULL;
|
gs_free char *ret_osname = NULL;
|
||||||
|
|
@ -467,3 +467,43 @@ ot_admin_get_default_ostree_dir (GFile **out_ostree_dir,
|
||||||
ot_transfer_out_value (out_ostree_dir, &ret_ostree_dir);
|
ot_transfer_out_value (out_ostree_dir, &ret_ostree_dir);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
ot_admin_pull (GFile *ostree_dir,
|
||||||
|
const char *osname,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gs_unref_object GFile *repo_path = g_file_get_child (ostree_dir, "repo");
|
||||||
|
gs_free char *repo_arg = g_strconcat ("--repo=",
|
||||||
|
gs_file_get_path_cached (repo_path),
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
return gs_subprocess_simple_run_sync (gs_file_get_path_cached (ostree_dir),
|
||||||
|
GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
|
||||||
|
cancellable, error,
|
||||||
|
"ostree", "pull", repo_arg, osname, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ot_admin_parse_deploy_name (GFile *ostree_dir,
|
||||||
|
const char *osname,
|
||||||
|
GFile *deployment,
|
||||||
|
char **out_name,
|
||||||
|
char **out_rev)
|
||||||
|
{
|
||||||
|
gs_unref_object GFile *deploy_dir = g_file_get_child (ostree_dir, "deploy");
|
||||||
|
gs_unref_object GFile *os_dir = g_file_get_child (deploy_dir, osname);
|
||||||
|
gs_free char *relpath = g_file_get_relative_path (os_dir, deployment);
|
||||||
|
const char *last_dash;
|
||||||
|
|
||||||
|
g_assert (relpath);
|
||||||
|
last_dash = strrchr (relpath, '-');
|
||||||
|
if (!last_dash)
|
||||||
|
g_error ("Failed to parse deployment name %s", relpath);
|
||||||
|
|
||||||
|
if (out_name)
|
||||||
|
*out_name = g_strndup (relpath, last_dash - relpath);
|
||||||
|
if (out_rev)
|
||||||
|
*out_rev = g_strdup (last_dash + 1);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ gboolean ot_admin_ensure_initialized (GFile *ostree_dir,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
gboolean ot_admin_get_booted_os (char **out_osname,
|
||||||
|
char **out_tree,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
gboolean ot_admin_get_current_deployment (GFile *ostree_dir,
|
gboolean ot_admin_get_current_deployment (GFile *ostree_dir,
|
||||||
const char *osname,
|
const char *osname,
|
||||||
GFile **out_deployment,
|
GFile **out_deployment,
|
||||||
|
|
@ -58,6 +63,18 @@ gboolean ot_admin_get_default_ostree_dir (GFile **out_ostree_dir,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
gboolean ot_admin_pull (GFile *ostree_dir,
|
||||||
|
const char *osname,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
|
void
|
||||||
|
ot_admin_parse_deploy_name (GFile *ostree_dir,
|
||||||
|
const char *osname,
|
||||||
|
GFile *deployment,
|
||||||
|
char **out_name,
|
||||||
|
char **out_rev);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue