zypper addrepo to detect current version of opensuse

In order to get the latest version of the R software, I need to add the repository using a line like this:


sudo zypper addrepo -f http://download.opensuse.org/repositories/devel\:languages\:R\:patched/openSUSE_12.2 "R patched devel"

Where it is important that 12.2 is replaced by the version of OpenSUSE. I would like to make a script that automatically adds this repository for the appropriate, current version of OpenSUSE. I.e. a script that I can run on either version 11.x or 12.x and which will automatically insert the current version into the addrepo line. Is there an easy way to use zypper to add for example the repository above, where 12.2 will equal the running release? Or is there a more natural way of doing this?

You can get the version with something like


grep VERSION /etc/SuSE-release | sed -e 's/VERSION = //'


PC: oS 12.2 x86_64 | i7-2600@3.40GHz | 16GB | KDE 4.8.5 | GeForce GT 420
ThinkPad E320: oS 12.2 x86_64 | i3@2.30GHz | 8GB | KDE 4.9.2 | HD 3000
eCAFE 800: oS 11.4 i586 | AMD Geode LX 800@500MHz | 512MB | lamp server

Do you mean to do this for this special line or in general for all repos you like to add in the future and where the URL may have a complete different structure (dependend on the whim of the repo owner and he may not even have the openSUSE version in any place in that URL).

When it is on this URL only, you can change the part

12.2

with

$(grep VERSION /etc/SuSE-release | sed -e 's/VERSION = //')

This to help you to put Martin’s statement in your statement.

Of course this works similar for URLs where there is “12.2” somewhere inside.