grub2/grub2-default-distributor.patch
Michael Chang da8194b45d Accepting request 928444 from home:michael-chang:branches:Base:System
- Remove openSUSE Tumbleweed specific handling for default grub
  distributor (bsc#1191198)
- Use /usr/lib/os-release as fallback (bsc#1191196)
  * grub2-default-distributor.patch
  * grub2-check-default.sh
- VUL-0: grub2: grub2-once uses fixed file name in /var/tmp (bsc#1190474)
  * grub2-once
  * grub2-once.service
- Fix unknown TPM error on buggy uefi firmware (bsc#1191504)
  * 0001-tpm-Pass-unknown-error-as-non-fatal-but-debug-print-.patch
- Fix error /boot/grub2/locale/POSIX.gmo not found (bsc#1189769)
  * 0001-Filter-out-POSIX-locale-for-translation.patch
- Fix error lvmid disk cannot be found after second disk added to the root
  volume group (bsc#1189874) (bsc#1071559)
  * 0001-ieee1275-implement-FCP-methods-for-WWPN-and-LUNs.patch
- Fix error in grub installation due to unnecessary requirement to support
  excessive device for the root logical volume (bsc#1184135)
  * 0001-disk-diskfilter-Use-nodes-in-logical-volume-s-segmen.patch
- Fix regression in reading xfs v4
  *0001-fs-xfs-Fix-unreadable-filesystem-with-v4-superblock.patch

OBS-URL: https://build.opensuse.org/request/show/928444
OBS-URL: https://build.opensuse.org/package/show/Base:System/grub2?expand=0&rev=396
2021-11-02 05:52:57 +00:00

202 lines
4.6 KiB
Diff

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
===================================================================
--- 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)
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_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);
+ cfgfile = grub_util_path_concat (2, "/usr/lib", "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_name
+ && (os_name = os_release_get_val (buf, "NAME")))
+ continue;
+ if (!os_version
+ && (os_version = os_release_get_val (buf, "VERSION")))
+ continue;
+ if (os_name && os_version)
+ break;
+ }
+
+ fclose (fp);
+
+ 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);
+
+ return os_name_version;
+ }
+
+ grub_free (os_version);
+
+ return os_name;
+}
+#endif
+
void
grub_util_load_config (struct grub_util_config *cfg)
{
@@ -125,7 +250,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 +271,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.06/util/grub-mkconfig.in
===================================================================
--- grub-2.06.orig/util/grub-mkconfig.in
+++ grub-2.06/util/grub-mkconfig.in
@@ -225,6 +225,19 @@ 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 ] ; 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
+ GRUB_DISTRIBUTOR="${NAME} ${VERSION}"
+ else
+ GRUB_DISTRIBUTOR="${NAME}"
+ fi
+fi
# These are defined in this script, export them here so that user can
# override them.