2021-11-02 06:52:57 +01:00
|
|
|
v1:
|
|
|
|
As long as VERSION in /etc/os-release has been commented out for rolling
|
|
|
|
release, we can replace openSUSE Tumbleweed specific handling for grub
|
|
|
|
distributor with a generic one.
|
|
|
|
|
|
|
|
v2:
|
|
|
|
Use /usr/lib/os-release as fallback to /etc/os-release
|
|
|
|
|
|
|
|
Index: grub-2.06/grub-core/osdep/unix/config.c
|
2015-09-15 13:16:16 +02:00
|
|
|
===================================================================
|
2021-11-02 06:52:57 +01:00
|
|
|
--- grub-2.06.orig/grub-core/osdep/unix/config.c
|
|
|
|
+++ grub-2.06/grub-core/osdep/unix/config.c
|
|
|
|
@@ -61,6 +61,131 @@ grub_util_get_localedir (void)
|
2015-09-15 13:16:16 +02:00
|
|
|
return LOCALEDIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
+#ifdef __linux__
|
2016-09-30 14:07:25 +02:00
|
|
|
+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;
|
|
|
|
+}
|
2015-09-15 13:16:16 +02:00
|
|
|
+
|
|
|
|
+static char*
|
|
|
|
+grub_util_default_distributor (void)
|
|
|
|
+{
|
2016-09-30 14:07:25 +02:00
|
|
|
+ char *cfgfile;
|
|
|
|
+ char buf[1024];
|
|
|
|
+ FILE *fp = NULL;
|
|
|
|
+ char *os_name = NULL;
|
|
|
|
+ char *os_version = NULL;
|
2015-09-15 13:16:16 +02:00
|
|
|
+
|
|
|
|
+ cfgfile = grub_util_path_concat (2, GRUB_SYSCONFDIR, "os-release");
|
|
|
|
+ if (!grub_util_is_regular (cfgfile))
|
|
|
|
+ {
|
|
|
|
+ grub_free (cfgfile);
|
2021-11-02 06:52:57 +01:00
|
|
|
+ cfgfile = grub_util_path_concat (2, "/usr/lib", "os-release");
|
|
|
|
+ if (!grub_util_is_regular (cfgfile))
|
|
|
|
+ {
|
|
|
|
+ grub_free (cfgfile);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
2015-09-15 13:16:16 +02:00
|
|
|
+ }
|
|
|
|
+
|
2016-09-30 14:07:25 +02:00
|
|
|
+ fp = grub_util_fopen (cfgfile, "r");
|
2015-09-15 13:16:16 +02:00
|
|
|
+
|
2016-09-30 14:07:25 +02:00
|
|
|
+ if (!fp)
|
2015-09-15 13:16:16 +02:00
|
|
|
+ {
|
2016-09-30 14:07:25 +02:00
|
|
|
+ grub_util_warn (_("cannot open configuration file `%s': %s"),
|
|
|
|
+ cfgfile, strerror (errno));
|
|
|
|
+ grub_free (cfgfile);
|
|
|
|
+ return NULL;
|
2015-09-15 13:16:16 +02:00
|
|
|
+ }
|
|
|
|
+
|
2016-09-30 14:07:25 +02:00
|
|
|
+ grub_free (cfgfile);
|
2015-09-15 13:16:16 +02:00
|
|
|
+
|
2016-09-30 14:07:25 +02:00
|
|
|
+ while (fgets (buf, sizeof (buf), fp))
|
2015-09-15 13:16:16 +02:00
|
|
|
+ {
|
2016-10-28 11:04:35 +02:00
|
|
|
+ if (buf[grub_strlen(buf) - 1] == '\n')
|
|
|
|
+ buf[grub_strlen(buf) - 1] = '\0';
|
|
|
|
+
|
2016-09-30 14:07:25 +02:00
|
|
|
+ if (!os_name
|
|
|
|
+ && (os_name = os_release_get_val (buf, "NAME")))
|
|
|
|
+ continue;
|
|
|
|
+ if (!os_version
|
|
|
|
+ && (os_version = os_release_get_val (buf, "VERSION")))
|
|
|
|
+ continue;
|
2021-11-02 06:52:57 +01:00
|
|
|
+ if (os_name && os_version)
|
2016-09-30 14:07:25 +02:00
|
|
|
+ break;
|
|
|
|
+ }
|
2015-09-15 13:16:16 +02:00
|
|
|
+
|
2016-09-30 14:07:25 +02:00
|
|
|
+ fclose (fp);
|
2015-09-15 13:16:16 +02:00
|
|
|
+
|
2021-11-02 06:52:57 +01:00
|
|
|
+ if (os_name && os_version)
|
2016-09-30 14:07:25 +02:00
|
|
|
+ {
|
|
|
|
+ char *os_name_version;
|
2015-09-15 13:16:16 +02:00
|
|
|
+
|
2016-09-30 14:07:25 +02:00
|
|
|
+ os_name_version = grub_xasprintf ("%s %s", os_name, os_version);
|
2015-09-15 13:16:16 +02:00
|
|
|
+
|
2016-09-30 14:07:25 +02:00
|
|
|
+ grub_free (os_name);
|
|
|
|
+ grub_free (os_version);
|
2015-09-15 13:16:16 +02:00
|
|
|
+
|
2016-09-30 14:07:25 +02:00
|
|
|
+ return os_name_version;
|
2015-09-15 13:16:16 +02:00
|
|
|
+ }
|
|
|
|
+
|
2021-11-02 06:52:57 +01:00
|
|
|
+ grub_free (os_version);
|
2015-09-15 13:16:16 +02:00
|
|
|
+
|
2016-09-30 14:07:25 +02:00
|
|
|
+ return os_name;
|
2015-09-15 13:16:16 +02:00
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
void
|
|
|
|
grub_util_load_config (struct grub_util_config *cfg)
|
|
|
|
{
|
2021-11-02 06:52:57 +01:00
|
|
|
@@ -125,7 +250,17 @@ grub_util_load_config (struct grub_util_
|
2015-09-15 13:16:16 +02:00
|
|
|
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)
|
2021-11-02 06:52:57 +01:00
|
|
|
@@ -136,4 +271,13 @@ grub_util_load_config (struct grub_util_
|
2015-09-15 13:16:16 +02:00
|
|
|
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
|
|
|
|
}
|
2021-11-02 06:52:57 +01:00
|
|
|
Index: grub-2.06/util/grub-mkconfig.in
|
2015-09-15 13:16:16 +02:00
|
|
|
===================================================================
|
2021-11-02 06:52:57 +01:00
|
|
|
--- grub-2.06.orig/util/grub-mkconfig.in
|
|
|
|
+++ grub-2.06/util/grub-mkconfig.in
|
|
|
|
@@ -225,6 +225,19 @@ GRUB_ACTUAL_DEFAULT="$GRUB_DEFAULT"
|
2015-09-15 13:16:16 +02:00
|
|
|
|
|
|
|
if [ "x${GRUB_ACTUAL_DEFAULT}" = "xsaved" ] ; then GRUB_ACTUAL_DEFAULT="`"${grub_editenv}" - list | sed -n '/^saved_entry=/ s,^saved_entry=,,p'`" ; fi
|
|
|
|
|
2021-11-02 06:52:57 +01:00
|
|
|
+if [ x"${GRUB_DISTRIBUTOR}" = x ] ; then
|
|
|
|
+ for i in "${sysconfdir}/os-release" "/usr/lib/os-release" ; do
|
|
|
|
+ if [ -f "$i" ] ; then
|
|
|
|
+ . "$i"
|
|
|
|
+ break
|
|
|
|
+ fi
|
|
|
|
+ done
|
|
|
|
+ if [ x"${NAME}" != x ] && [ x"${VERSION}" != x ] ; then
|
2016-09-30 14:07:25 +02:00
|
|
|
+ GRUB_DISTRIBUTOR="${NAME} ${VERSION}"
|
2021-11-02 06:52:57 +01:00
|
|
|
+ else
|
|
|
|
+ GRUB_DISTRIBUTOR="${NAME}"
|
2016-09-30 14:07:25 +02:00
|
|
|
+ fi
|
2015-09-15 13:16:16 +02:00
|
|
|
+fi
|
|
|
|
|
|
|
|
# These are defined in this script, export them here so that user can
|
|
|
|
# override them.
|