Working with OBS for .rpm Packaging

How many of us have found it -a little bit- bothersome when one of our favourite Linux distributions doesn’t contain a package that we definitely need in our system, whether that’s for professional reasons or just to make our lives a bit easier in the open source world. If that also happened to you then you might consider building the package yourself.

One of the applications I always like adding after a fresh install is pywal . In short pywal works in the following way: Selects a picture of your choice > Generates a color palette with the most dominant colors > Applies those colors system-wide.

Unfortunately for many of us UnixPorn lovers pywal doesn’t have a .rpm package we can install it from. For this reason I’ll be showing you how to easily create an .rpm, using source code and adding it to the official OpenSUSE repositories.

For this a few things will be necessary:

  • An OBS account (Link)
  • py2pack installed (easily installed with: pip3 install py2pack)
  • An application we know is not present in the official repos.

We’ll start by configuring OBS from the command line. The command line tool OSB uses is ‘osc’. To configure our credentials in osc (which will be doing API calls to our account), we can edit the configuration file found under ~/.config/osc/oscrc. Open up the file with vim or your preferred text editor and fill in your username and password.

Once we have that in place, we can follow up with creating our local working directory. In my case I created a directory called ‘osc-home’ in my ~/

mkdir ~/osc-home

With that in place, we can cd into this newly created directory and create our package metadata file and folder structure.

cd osc-home
osc meta pkg -e home:username pywal

We’ll fill in the .xlm file as needed, providing details such as name, title and description. Save your changes and quit the editor.

osc checkout home:username pywal

If the command ran successfully you’ll find your home:username directory when typing ls. Once again cd into home:username/pywal.

Now it’s time for probably some of the most important parts of this process. We’ll be downloading our application using py2pack and generating a .spec file from it. These 2 things are our bread and butter when creating our .rpm.

Running ‘py2pack list’ will provide us with a list of Python applications that are stored in Pypi (Python Package Index). Since the application we want is pywal, we’ll pipe the command and grep for it.

py2pack list | grep pywal

You should see the application coming up as a result. Proceed to fetch it by running ‘py2pack fetch pywal’. Lastly we’ll create the .spec file:

py2pack generate pywal -f python-pywal.spec

With pywal being the name of the application we fetched and python-pywal.spec the name of the spec file we want to create. That’s what the -f argument is used for.

Open up the .spec file created and make sure that there’s nothing missing (or extra). Sometimes certain parameters won’t be set , but different custom options will be given to the user, which you’ll have to manually edit and pick one. In my case the %check section has 3 possible values.

From here all we have left is to push our packages and start the building process.

‘osc add *’ and osc commit will get us almost there. Run both commands , you will be promted with another file containing your changes. Save and quit (if using vim) and then press c to continue. If the command ran you should see an output similar to this

Sending python-pywal.spec
Sending pywal-3.3.0.tar.gz
Transmitting file data . .
Committed revision 1

In regards of building the application, I find it easier and nicer to do it from the GUI itself. Go to your home project in the upper right corner, click on the Repositories tab and Add a distribution. Personally I’ll be building this package for OpenSUSE Tumbleweed only, using both architectures i586 and x86_64. You can select whichever architectures or distributions you prefer. For the sake of this mini guide I’ll go with those mentioned above.

And that’s it. If everything went well and your package passed the building process you should see it marked as ‘succeeded‘ if you go to the Package tab, select the application and see its status in the right corner of your screen.

From here all that’s left is to Submit this Package to one of the devel repositories and hopefully have someone check your work.

With that we reached the end of this short guide. There’s a lot to packaging in general so it’s kinda hard to sum everything up and make it easy to understand. This guide is not intended to explain every single detail there is to building packages but to work as an introduction to some of the basic concepts and flows. There’s things I haven’t mentioned but those can be found in the official documentation from every major Linux distro out there.

Cheers!

Leave a comment

Your email address will not be published. Required fields are marked *