File grub2-default-distributor.patch of Package grub2.19555
Index: grub-2.02~beta3/grub-core/osdep/unix/config.c
===================================================================
--- grub-2.02~beta3.orig/grub-core/osdep/unix/config.c
+++ grub-2.02~beta3/grub-core/osdep/unix/config.c
@@ -61,6 +61,143 @@ grub_util_get_localedir (void)
return LOCALEDIR;
}
+#ifdef __linux__
+static char *
+os_release_get_val (const char *buf, const char *key)
+{
+ const char *ptr = buf;
+ char *ret;
+
+ while (*ptr && grub_isspace(*ptr))
+ ptr++;
+
+ if (*ptr == '#')
+ return NULL;
+
+ if (grub_strncmp (ptr, key, grub_strlen (key)) != 0)
+ return NULL;
+
+ ptr += grub_strlen (key);
+ if (*ptr++ != '=' || *ptr == '\0')
+ return NULL;
+
+ if (*ptr == '"' || *ptr == '\'')
+ {
+ char c = *ptr;
+ int i = 0;
+ char *tmp, *ptmp;
+
+ if (*++ptr == '\0')
+ return NULL;
+
+ tmp = grub_strdup (ptr);
+ if ((ptmp = grub_strrchr (tmp, c)))
+ *ptmp = '\0';
+
+ ret = malloc (grub_strlen (tmp) + 1);
+ ptmp = tmp;
+ while (*ptmp)
+ {
+ if (*ptmp != '\\' || *(ptmp + 1) != c)
+ ret[i++] = *ptmp;
+ ++ptmp;
+ }
+
+ grub_free (tmp);
+ ret[i] = '\0';
+ }
+ else
+ {
+ char *pret;
+
+ ret = grub_strdup (ptr);
+ if ((pret = grub_strchr (ret, ' ')))
+ *pret = '\0';
+ }
+
+ return ret;
+}
+
+static char*
+grub_util_default_distributor (void)
+{
+ char *cfgfile;
+ char buf[1024];
+ FILE *fp = NULL;
+ char *os_pretty_name = NULL;
+ char *os_name = NULL;
+ char *os_version = NULL;
+
+ cfgfile = grub_util_path_concat (2, GRUB_SYSCONFDIR, "os-release");
+ if (!grub_util_is_regular (cfgfile))
+ {
+ grub_free (cfgfile);
+ return NULL;
+ }
+
+ fp = grub_util_fopen (cfgfile, "r");
+
+ if (!fp)
+ {
+ grub_util_warn (_("cannot open configuration file `%s': %s"),
+ cfgfile, strerror (errno));
+ grub_free (cfgfile);
+ return NULL;
+ }
+
+ grub_free (cfgfile);
+
+ while (fgets (buf, sizeof (buf), fp))
+ {
+ if (buf[grub_strlen(buf) - 1] == '\n')
+ buf[grub_strlen(buf) - 1] = '\0';
+
+ if (!os_pretty_name
+ && (os_pretty_name = os_release_get_val (buf, "PRETTY_NAME")))
+ continue;
+ if (!os_name
+ && (os_name = os_release_get_val (buf, "NAME")))
+ continue;
+ if (!os_version
+ && (os_version = os_release_get_val (buf, "VERSION")))
+ continue;
+ if (os_pretty_name && os_name && os_version)
+ break;
+ }
+
+ fclose (fp);
+
+ if (os_name && grub_strncmp (os_name, "openSUSE Tumbleweed", sizeof ("openSUSE Tumbleweed") - 1) == 0)
+ {
+ grub_free (os_name);
+ if (os_version)
+ grub_free (os_version);
+
+ return os_pretty_name;
+ }
+ else if (os_name && os_version)
+ {
+ char *os_name_version;
+
+ os_name_version = grub_xasprintf ("%s %s", os_name, os_version);
+
+ grub_free (os_name);
+ grub_free (os_version);
+ if (os_pretty_name)
+ grub_free (os_pretty_name);
+
+ return os_name_version;
+ }
+
+ if (os_pretty_name)
+ grub_free (os_pretty_name);
+ if (os_version)
+ grub_free (os_version);
+
+ return os_name;
+}
+#endif
+
void
grub_util_load_config (struct grub_util_config *cfg)
{
@@ -125,7 +262,17 @@ grub_util_load_config (struct grub_util_
waitpid (pid, NULL, 0);
}
if (f)
- return;
+ {
+#ifdef __linux__
+ if (!cfg->grub_distributor || cfg->grub_distributor[0] == '\0')
+ {
+ if (cfg->grub_distributor)
+ grub_free (cfg->grub_distributor);
+ cfg->grub_distributor = grub_util_default_distributor ();
+ }
+#endif
+ return;
+ }
f = grub_util_fopen (cfgfile, "r");
if (f)
@@ -136,4 +283,13 @@ grub_util_load_config (struct grub_util_
else
grub_util_warn (_("cannot open configuration file `%s': %s"),
cfgfile, strerror (errno));
+
+#ifdef __linux__
+ if (!cfg->grub_distributor || cfg->grub_distributor[0] == '\0')
+ {
+ if (cfg->grub_distributor)
+ grub_free (cfg->grub_distributor);
+ cfg->grub_distributor = grub_util_default_distributor ();
+ }
+#endif
}
Index: grub-2.02~beta3/util/grub-mkconfig.in
===================================================================
--- grub-2.02~beta3.orig/util/grub-mkconfig.in
+++ grub-2.02~beta3/util/grub-mkconfig.in
@@ -206,6 +206,14 @@ GRUB_ACTUAL_DEFAULT="$GRUB_DEFAULT"
if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
+if [ x"${GRUB_DISTRIBUTOR}" = x ] && [ -f "${sysconfdir}/os-release" ] ; then
+ . "${sysconfdir}/os-release"
+ if echo "$NAME" | grep -q "^openSUSE Tumbleweed" ; then
+ GRUB_DISTRIBUTOR="${PRETTY_NAME}"
+ else
+ GRUB_DISTRIBUTOR="${NAME} ${VERSION}"
+ fi
+fi
# These are defined in this script, export them here so that user can
# override them.