I’m setting up some install scripts (in my case, for a Docker build), and I need to add some repos. I would prefer not to put the version number in the scripts installing packages. Is there a way to do
# Dockerfile
FROM registry.opensuse.org/opensuse/leap:15.5.5
...
RUN sh -e install.sh
...
$releasever isn’t an environment variable, so the behavior is probably going to be a little different. If you were to run the command from the command-line in that manner, bash is going to use variable substitution in the environment to replace the string with what’s in the environment.
So my first instinct is that you’d probably have to escape it to get it added in as a literal string.
Then, of course, there’s getting the variable set to the value you want inside the docker container.
From the zypper man page:
$releasever, $releasever_major, $releasever_minor
Use this variable to refer to the version of your openSUSE or SUSE Linux. The value is obtained from the /product/version XML-node in /etc/products.d/baseproduct.
The base images in registry.opensuse.org (at least the 15.5.5.126 image that I checked; 15.5.5 doesn’t exist) included this file and the default repos configured with $releasever in them.
I’d probably just add the file on a host and then copy it into the image with a COPY directive, rather than using zypper ar - because that won’t work (the URL needs to be valid, but because $releasever isn’t an environment variable, it won’t be adde din that way. Using ar attempts to add the URL as specified.)
So the variable is preserved rather than being replaced with the version.
That said, I would probably still use the file copy method. The fact that it wouldn’t add without an alias name tells me that this might be an unexpected behavior, since using a version number instead of $releasever doesn’t require an alias be specified.
Sorry, I missed that. Of course it should be escaped from the shell. But the string as it is shown is correct (and certainly wanted when all other repo URLs on the system have the same).
And the escaping from the shell should either be done by putting the whole between ' (which is not a bad idea in any case when one wants to forward such long strings which a great variety of different characters to a program through the shell), or use " but then one has to escape $ signs extra because " doesn’t.
I can confirm that using single ' delimiters does work if you remove the escape for the $ in $releasever:
localhost:~> sudo zypper addrepo -f 'https://download.opensuse.org/repositories/devel:tools/$releasever/devel:tools.repo' devel_tools
Adding repository 'devel_tools' ..........................................[done]
Repository 'devel_tools' successfully added
URI : https://download.opensuse.org/repositories/devel:tools/15.6/devel:tools.repo
Enabled : Yes
GPG Check : Yes
Autorefresh : Yes
Priority : 99 (default priority)
Repository priorities are without effect. All enabled repositories share the same priority.
Good callout there. I think I’d still be more likely to use the file method for a Docker container. Then there’s less chance of an error being made in modifying the Dockerfile.