Page MenuHome

Fix detection of OpenSUSE and other distributions (that are not deb, arch or rpm-based) like Slackware
Needs ReviewPublic

Authored by Mohamed AMAZIRH (m.amazirh) on Jan 10 2021, 11:14 AM.

Details

Summary

Currently install_deps.sh treats all other distributions (that aren't deb, arch or rpm based) as rpm distributions. And it doesn't detect OpenSUSE.

It treats all other distributions as rpm based because of a faulty check [ -f /etc/redhat-release -o /etc/SuSE-release ] (at line 5951) which always evaluates to true because of a missing -f before /etc/SuSE-release.

It also doesn't detect OpenSUSE because the detection sequence checks the existence of the file /etc/SuSE-release which was deprecated in OpenSUSE 13.1 and removed in OpenSUSE Leap 15.0 in favour of /etc/os-release. (os-release was already used in install_deps.sh but only to build packman repo's url). See https://en.opensuse.org/Etc_SuSE-release.

This patch fixes both issues and also modifies the code used to build packman repo's url to take into account both OpenSUSE Leap and Tumbleweed (the urls for the two distributions do not use the same format).

I tested the patch on OpenSUSE Leap 15.2, OpenSUSE Tumbleweed, Fedora 33 (to check for regressions) and Slackware 14.2. and it seems to work :)

Diff Detail

Repository
rB Blender
Branch
bugfix/mah/opensuse-detection-fix (branched from master)
Build Status
Buildable 12070
Build 12070: arc lint + arc unit

Event Timeline

Mohamed AMAZIRH (m.amazirh) requested review of this revision.Jan 10 2021, 11:14 AM

removed some unnecessary changes (extra spaces that were removed in first version of the patch)

Mohamed AMAZIRH (m.amazirh) retitled this revision from Fix detection for OpenSUSE and other distributions (that are not deb, arch or rpm-based) like Slackware to Fix detection of OpenSUSE and other distributions (that are not deb, arch or rpm-based) like Slackware.

removed a leftover mention of SuSE-release (used in a preliminary version of the patch)

Sybren A. Stüvel (sybren) requested changes to this revision.Jan 11 2021, 12:21 PM

Thanks for your patch.

This patch fixes both issues

In that case sending in two patches would have been much preferred. A simple fix for a faulty check is easily reviewed, accepted, and merged. A whole new way to detect SUSE is a different thing.

This patch not only adds detection of SUSE via /etc/os-release, but also removes detection via /etc/SuSE-release. This means that an incompatibility with older SUSE releases is introduced, which I don't want to take lightly. When did SUSE start using /etc/os-release?

build_files/build_environment/install_deps.sh
4296

The /etc/os-release file is written in shell-style. This makes is simple to parse, as you only need to do source /etc/os-release. After that you can use the variables declared in that file directly. There is no need to use tools like sed.

4306

No need for an else after return.

4308–4309

Are there any OpenSUSE variants that do not use RPM? If all of them use RPM, just use opensuse*) instead of having these two cases.

4310

According to wikipedia there are more distributions that are RPM-based than just RedHat and SUSE. This code won't be correct on those distributions.

It's fine to have some limitations in the code, but wherever they are known (and kept around instead of being fixed) they should be documented in a comment.

4313

There is no explicit return value at the end of this function.

4316

The patch is inconsistent with regard to using case or if to distinguish between different releases of SUSE.

4332–4333

Here you can also use one opensuse-* case.

4467

Put the URL in a variable, and use that variable in both places (INFO and zypper commands).

This revision now requires changes to proceed.Jan 11 2021, 12:21 PM

Hi Sybren,

Thanks for your feedback.

In that case sending in two patches would have been much preferred. A simple fix for a faulty check is easily reviewed, accepted, and merged. A whole new way to detect SUSE is a different thing.

I think that any fix for the second issue (opensuse detection) will automatically fix the first one, so I didn't see the need for creating a specific patch for the first issue and just mentioned it in the summary. But I can create another patch if it's better for tracking code changes.

This patch not only adds detection of SUSE via /etc/os-release, but also removes detection via /etc/SuSE-release. This means that an incompatibility with older SUSE releases is introduced, which I don't want to take lightly.

In my first version of the patch D10061, I kept the test checking for /etc/SuSE-release, but then realised that the last version of OpenSUSE that has only /etc/SuSE-release (Leap 42.3) (and doesn't have os-release) has reached its end of life in 2019. So I thought that the test was no longer useful and removed it.

When did SUSE start using /etc/os-release?

Since OpenSUSE 13.1 (or even before but I can't say for sure). According to the OpenSUSE wiki, /etc/SuSE-release was deprecated in 13.1 and removed in Leap 15.0.

I'll try to prepare a new version of the patch this week (or the next at the latest) to fix the issues you raised in the comments below. But before that I would like you to give me some feedback on a few comments I'll post later.

Thanks in advance.

build_files/build_environment/install_deps.sh
4296

I chose not to use source to avoid possible name collisions with existing (or future) variables in install_deps.sh (As this is my first time modifying script shells I just followed the advice from here). Plus the current version of the script already parses os-release in similar way (grep + sed) on line 4434.

4306

I assume you're talking about elif. In this case, yes, but then I'll need to add an extra line to put an fi to close the first if (unless there is some other way to do it).

4308–4309

Not to my knowledge. I'll change it.

4313

There is also another missing from the case opensuse-tumbleweed). But it doesn't change the result in the case of opensuse because bash returns 0 implicitly when there is no explicit return.

I removed the other return by mistake, I think, in some last minute changes. (it exists in my first version of the patch D10061).

I'll put it back and add another one at the end of the function.

4316

I'll use case here too.

Mohamed AMAZIRH (m.amazirh) marked 5 inline comments as not done.Jan 11 2021, 9:11 PM
build_files/build_environment/install_deps.sh
4310

I agree. But in this case, wouldn't be better to split and change the name of the function is_rpm_based (which now I think is misleading) to is_fedora/is_opensuse/is_redhat, as the current version of install_deps.sh (without my patch and if not for the current bug) really supports only Redhat, Fedora and OpenSUSE (and the blender build documentation lists only Fedora and OpenSUSE`).

I think that a separate test function per distribution will make the code more explicit about what the script really supports (without adding comments).

When did SUSE start using /etc/os-release?

Since OpenSUSE 13.1 (or even before but I can't say for sure). According to the OpenSUSE wiki, /etc/SuSE-release was deprecated in 13.1 and removed in Leap 15.0.

I was rather hoping for years instead of version numbers ;-)

For context: according to wikipedia they have weird version numbers. The sequence is 10, 11, 12, 13, 42, 15. For some major versions x.0 is the first one, for other ones it starts with x.1.

  • v 13 was released in November 2013.
  • v 15 was released in May 2018.
  • The only maintained versions are 15.1, 15.2, and Tumbleweed (their rolling release).

@Bastien Montagne (mont29) which versions do you think are reasonable to support in install_deps.sh?

OpenSuse 13.1 (first to introduce that new /etc/os-release iirc) is from early 2014 right? That sounds more that old enough to me, install_deps is not typically dedicated to support old linux systems, rather fairly new ones.

build_files/build_environment/install_deps.sh
4296

Fair enough. The sed command is incomplete, though. For example, quotes around the values aren't mandatory. Ubuntu uses ID=ubuntu here. This works:

echo $(sed -n 's/^ID="\?\(.*\)"\?/\1/p' /etc/os-release)

The same is true for the check on VERSION_ID. It's likely to be quoted, but since it's just shell notation, it's not mandatory in all cases. See man os-release for more info.

4306

Yes, that's what I meant. Having an extra fi line is fine by me.

Changes following feedback

Sorry phabricator didn't track my new changes. I think I should have added them as a separate commit.

build_files/build_environment/install_deps.sh
4296

I added the -r flag to remove the need for escaping the special characters ( and ?.

When I tested the provided new regex expression I found that .* also captured the last quote (because it's now optional).

I restricted the capture group to the allowed characters listed in man os-release to avoid this issue.

4306

I replaced is_rpm_based_distro by a simpler and specific opensuse test is_opensuse. This way only opensuse specific codepaths will be impacted by the new changes.

Sybren A. Stüvel (sybren) requested changes to this revision.Jan 18 2021, 12:10 PM

I like the is_opensuse() function, it makes the rest of the code easier to read. There are some other issues, though.

build_files/build_environment/install_deps.sh
4309

This is just a case statement again, disguised as if.

4310

We should not rely on HTTP URLs when HTTPS is available.

4314

In my opinion, this situation should cause the script to stop. It shouldn't return invalid data.

4332

Will this work? If so, add a comment that explains why this is actually a valid value. If it doesn't, handle the situation in a different way that explains the issue to the user in an error message.

This revision now requires changes to proceed.Jan 18 2021, 12:10 PM
build_files/build_environment/install_deps.sh
4309

I said before that I'll use case to keep the patch consistent with regard to using case or if. But since I removed is_rpm_based_distro (and with it the other case occurence) I didn't see why I still had to use it.

Tell me if I should change it.

4314

In theory, and currently, this shouldn't happen. I added this case just to make it clear that the code handles only leap and tumbleweed.

But in case it would happen, I think stopping the script is not ideal.

Adding packman repo is an optional step, and the user can skip it if they want to. Stopping the script here will remove that choice.

The url returned by get_opensuse_packman_repo_url() is shown to the user in a message on line 4462 before adding it to zypper's managed repositories.

If the user sees the value 'UNKNOWN' in the message, they can always skip this configuration step and do it manually (with yast or zypper if they know what is the correct url). Also, in my opinion, showing the value UNKNOWN to the user in the context of this script is acceptable, since the target audience are developers.

Still, maybe instead of stopping the script, the message on line 4462 should be changed to warn the user if this case should ever happen (or/and direct them to some instructions on how to add the packman repo manually. A link to openSUSE's wiki for example).

4332

I added it for clarity, it won't work and it won't happen. If the script reaches rpm_flavour that means either redhat-release exists or is_opensuse() evaluates to true.

Tell me if I should remove it?

changed packman repo url to use https

build_files/build_environment/install_deps.sh
4310

Done.

There are other places where http is used instead of https (like on line 4441).

Tell me If I should change those too in this patch.