gboolean
ot_admin_builtin_update_kernel (int argc, char **argv, GError **error)
{
  GOptionContext *context;
  OtAdminUpdateKernel self_data;
  OtAdminUpdateKernel *self = &self_data;
  gboolean ret = FALSE;
  const char *deploy_target = NULL;
  struct utsname utsname;
  const char *release;
  __attribute__((unused)) GCancellable *cancellable = NULL;

  if (!opt_ostree_dir)
    opt_ostree_dir = "/ostree";

  memset (self, 0, sizeof (*self));

  context = g_option_context_new ("[OSTREE_REVISION [KERNEL_RELEASE]] - Update kernel and regenerate initial ramfs");
  g_option_context_add_main_entries (context, options, NULL);

  if (!g_option_context_parse (context, &argc, &argv, error))
    goto out;

  if (argc > 1)
    deploy_target = argv[1];
  else
    deploy_target = "current";

  (void) uname (&utsname);
  
  if (strcmp (utsname.sysname, "Linux") != 0)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Unsupported machine %s", utsname.sysname);
      goto out;
    }
  
  release = utsname.release;
  if (argc > 2)
    release = argv[2];
  
  if (!copy_modules (release, cancellable, error))
    goto out;
  
  if (!update_initramfs (release, deploy_target, cancellable, error))
    goto out;
  
  if (!update_grub (release, cancellable, error))
    goto out;

  ret = TRUE;
 out:
  if (context)
    g_option_context_free (context);
  return ret;
}
Ejemplo n.º 2
0
gboolean
ot_admin_builtin_deploy (int argc, char **argv, GError **error)
{
  GOptionContext *context;
  OtAdminDeploy self_data;
  OtAdminDeploy *self = &self_data;
  gboolean ret = FALSE;
  const char *deploy_target = NULL;
  const char *revision = NULL;
  __attribute__((unused)) GCancellable *cancellable = NULL;

  memset (self, 0, sizeof (*self));

  context = g_option_context_new ("NAME [REVISION] - Check out revision NAME (or REVISION as NAME)");
  g_option_context_add_main_entries (context, options, NULL);

  if (!g_option_context_parse (context, &argc, &argv, error))
    goto out;

  if (argc < 3)
    {
      ot_util_usage_error (context, "NAME must be specified", error);
      goto out;
    }
    
  deploy_target = argv[2];
  if (argc > 3)
    revision = argv[3];

  if (!do_checkout (self, deploy_target, revision, cancellable, error))
    goto out;

  if (!opt_checkout_only)
    {

      struct utsname utsname;
      const char *release;
  
      (void) uname (&utsname);
  
      if (strcmp (utsname.sysname, "Linux") != 0)
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "Unsupported machine %s", utsname.sysname);
          goto out;
        }
      
      release = utsname.release;

      if (!update_initramfs (release, deploy_target, cancellable, error))
        goto out;

      if (!update_grub (release, cancellable, error))
        goto out;
    }

  if (!update_current (deploy_target, cancellable, error))
    goto out;

  ret = TRUE;
 out:
  if (context)
    g_option_context_free (context);
  return ret;
}