Ejemplo n.º 1
0
static int context_read_data(Context *c) {
        int r;
        struct utsname u;

        assert(c);

        context_reset(c);

        assert_se(uname(&u) >= 0);
        c->data[PROP_KERNEL_NAME] = strdup(u.sysname);
        c->data[PROP_KERNEL_RELEASE] = strdup(u.release);
        c->data[PROP_KERNEL_VERSION] = strdup(u.version);
        if (!c->data[PROP_KERNEL_NAME] || !c->data[PROP_KERNEL_RELEASE] ||
            !c->data[PROP_KERNEL_VERSION])
                return -ENOMEM;

        c->data[PROP_HOSTNAME] = gethostname_malloc();
        if (!c->data[PROP_HOSTNAME])
                return -ENOMEM;

        r = read_etc_hostname(NULL, &c->data[PROP_STATIC_HOSTNAME]);
        if (r < 0 && r != -ENOENT)
                return r;

        r = parse_env_file(NULL, "/etc/machine-info",
                           "PRETTY_HOSTNAME", &c->data[PROP_PRETTY_HOSTNAME],
                           "ICON_NAME", &c->data[PROP_ICON_NAME],
                           "CHASSIS", &c->data[PROP_CHASSIS],
                           "DEPLOYMENT", &c->data[PROP_DEPLOYMENT],
                           "LOCATION", &c->data[PROP_LOCATION]);
        if (r < 0 && r != -ENOENT)
                return r;

        r = parse_os_release(NULL,
                             "PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME],
                             "CPE_NAME", &c->data[PROP_OS_CPE_NAME],
                             "HOME_URL", &c->data[PROP_HOME_URL],
                             NULL);
        if (r < 0 && r != -ENOENT)
                return r;

        r = id128_read("/sys/class/dmi/id/product_uuid", ID128_UUID, &c->uuid);
        if (r < 0)
                log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
                               "Failed to read product UUID, ignoring: %m");
        else if (sd_id128_is_null(c->uuid) || sd_id128_is_allf(c->uuid))
                log_debug("DMI product UUID " SD_ID128_FORMAT_STR " is all 0x00 or all 0xFF, ignoring.", SD_ID128_FORMAT_VAL(c->uuid));
        else
                c->has_uuid = true;

        return 0;
}
Ejemplo n.º 2
0
static void print_welcome(void) {
        _cleanup_free_ char *pretty_name = NULL;
        static bool done = false;
        int r;

        if (done)
                return;

        r = parse_os_release(arg_root, "PRETTY_NAME", &pretty_name, NULL);
        if (r < 0)
                log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
                               "Failed to read os-release file, ignoring: %m");

        printf("\nWelcome to your new installation of %s!\nPlease configure a few basic system settings:\n\n",
               isempty(pretty_name) ? "Linux" : pretty_name);

        press_any_key();

        done = true;
}
Ejemplo n.º 3
0
static gboolean
do_initial_setup (GCancellable     *cancellable,
                  GError          **error)
{
  gboolean ret = FALSE;
  gs_unref_object GFile *etc_os_release =
    g_file_new_for_path ("/etc/os-release");
  gs_free char *contents = NULL;
  gs_unref_hashtable GHashTable *osrelease_values = NULL;
  const char *pretty_name;
  const char *passwd_root_argv[] = { "passwd", "root", NULL };
  gsize len;
  guint i;
  const guint max_passwd_attempts = 5;

  if (!g_file_load_contents (etc_os_release, cancellable,
                             &contents, &len, NULL, error))
    {
      g_prefix_error (error, "Reading /etc/os-release: ");
      goto out;
    }

  osrelease_values = parse_os_release (contents, "\n");
  pretty_name = g_hash_table_lookup (osrelease_values, "PRETTY_NAME");
  if (!pretty_name)
    pretty_name = g_hash_table_lookup (osrelease_values, "ID");
  if (!pretty_name)
    pretty_name = " (/etc/os-release not found)";

  g_print (_("Welcome to %s"), pretty_name);
  g_print ("\n");

  (void) readline (_("Press Enter to begin setup"));

  g_print (_("No user accounts found, and root password is locked"));
  g_print ("\n");

  for (i = 0; i < max_passwd_attempts; i++)
    {
      int estatus;

      if (!g_spawn_sync (NULL, (char**)passwd_root_argv, NULL,
                         G_SPAWN_CHILD_INHERITS_STDIN,
                         NULL, NULL, NULL, NULL,
                         &estatus, error))
        goto out;

      if (g_spawn_check_exit_status (estatus, NULL))
        break;
    }
  if (i == max_passwd_attempts)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Failed to run \"passwd root\" after %u attempts",
                   max_passwd_attempts);
      goto out;
    }

  ret = TRUE;
 out:
  return ret;
}
Ejemplo n.º 4
0
static int is_wrlinux(void)
{
	return parse_os_release("cpe:/o:windriver:wrlinux");
}