Score:0

How to install another rpm as dependency to another rpm?

ng flag

We have built application rpm file using fpm. There we have set python3 as dependency, so it installs automatically before the main rpm.

But it installing 3.7. To replace that with 3.8, we need to check OS version before whether it is centos or awslinux and based on that we need to install specific rpm.

So, I kept these conditional blocks in the preinst script and passed to parameter --before-install.

But, it is getting stuck during rpm installation.

So, when I check with verbose mode. I found that, it is not working with preinst.

The reason, it is ptyhon install not able to apply lock and continr the installation as projectn has already acquired lock on it.

RPM: error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Resource temporarily unavailable)
Error: Could not run transaction.


+ echo 'centos is detected'
centos is detected
+ sudo yum install -yq python38
RPM: error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Resource temporarily unavailable)
Error: Could not run transaction.

Any suggestions you can provide

To be more specific, please find details below.

The tool using for creating rpm: fpm I need to install python3.8 as dependency to out application rpm.

If I set that as dependency using -d python3, it is installing 3.7 version on amazon linux and 3.6 on centos 8. To use 3.8 version, there are few other steps to be performed before installing package.

So, I removed the python3 from dependency section and added in --before-install as shell script.

This is the shell script I kept there.

#!/bin/bash
echo "Starting preinst"

echo "Checking OS Version"


DISTRO=$(cat /etc/*-release | grep -w NAME | cut -d= -f2 | tr -d '"' | tr '[:upper:]' '[:lower:]')

if [[ "$DISTRO" =~ "centos linux" ]]; then
  echo "centos is detected"
  sudo yum install -yq python38
elif [[ "$DISTRO" =~ "amazon linux" ]]; then
  echo "amazon linux detected"
  sudo yum install -yq amazon-linux-extras
  sudo amazon-linux-extras enable python3.8
  sudo yum install -yq python3.8
elif [[ "$DISTRO" =~ "ubuntu" ]]; then
  echo "ubuntu detected"
  sudo apt install pyhton3 -yq
else
  echo "Neither centos nor amazon linux 2"
fi

It is triggering the script but stucking at the python installation from shell script.

RPM: error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Resource temporarily unavailable)
Error: Could not run transaction.


+ echo 'centos is detected'
centos is detected
+ sudo yum install -yq python38
RPM: error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Resource temporarily unavailable)
Error: Could not run transaction.

Any suggestions on how to fix this?

My requirement is to install python3.8 as part of our product rpm also as a dependency.

vidarlo avatar
ar flag
Your problem is that rpm can't aquire a lock. Do you have another `rpm` process running? `ps aux | grep rpm` will tell you
cn flag
You can't create a transaction while making a transaction (installation of RPM). Simply put `Requires: python(abi) = 3.8` if your app requires that specific version. However, for your case, I would go the route of bundling it all together, using something like [pyinstaller](https://pyinstaller.org/en/stable/) then package it without python dependency.
Score:0
cn flag

Installing rpms in another rpm's scripts does not work. Already in an rpm transaction. Further, the dependencies are not in the package metadata, and yum/dnf cannot resolve them. Either of these are a poor user experience.

Multiple distros in one rpm spec is possible with creative use of conditionals. Say you required at least Python 3.8. Borrowing from various rpm packages in CentOS and elsewhere, build dep might look like:

%if 0%{?fedora} || 0%{?rhel} > 8 
BuildRequires: python3-devel
%endif
%if 0%{?amzn} || 0%{?rhel} == 8 || 0%{?suse_version} > 1500
BuildRequires: python38-devel
%endif

Note the weird zero prefixed number thing. This allows for use in expressions even if the variable is not defined.

Continue with Python packaging guidelines for Fedora (or EL) to %install the thing. One tricky thing: for some of these distros Python is /usr/bin/python3 others /usr/bin/python38. May wish to make that a variable.

Amazon extra repo python3.8 is not enabled by default. Enable it for the package build, for example in the repos of the mock tool. Users will also need to enable the repo to install these packages.

Fedora packaging macros will usually generate appropriate dependencies for python modules installed in typical locations like %{python3_sitelib} I don't know offhand what amzn does for this, probably the same. If not, you may need to add manual deps, such as Requires: python(abi) = 3.8

Build the resulting spec file on each unique distro of interest: Fedora, RHEL, Amazon Linux, CentOS Stream, SUSE. While a slightly different package for each is annoying, it results is an easy yum install experience for users.

Debian packages are an exercise for the reader.


Automatic package generators like fpm might not output as clever of packages. Classic tradeoff: quick generator to support multiple distros, versus a human packager who can do something intentional with the quirks of the several distributions.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.