I have a need to identify dependencies of on a CentOS Linux systems. Since I am using yum and dnf, I think that the method presented here also applies to other Linux distributions, like Redhat and Fedora Linux systems.
Why do I have this need? It actually arises from my upgrading a CentOS 7 system to CentOS 8. I follow the steps in the following tecmint article,
How to Upgrade CentOS 7 to CentOS 8 Linux
There are numerous broken dependencies problems when I invoke the command,
dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync
I address this problem by removing the packages that has the unresolved dependencies problem. Here, I only want to remove a package without removing its dependencies, otherwise, the system may be left in a completely unusable state. To remove a package without removing its dependencies, I run,
rpm -Uvh --nodeps PACKAGE_NAME
After I removed several packages, I can finally successfully run the dnf distro-sync
command. After that, I want to install the removed packages. However, I hypothesize that these packages dependencies may not be installed properly. Therefore, I need not only install these removed pacakges but also their dependent pacakges. For this, I need to figure out what the dependent packages are. This turns out to be a one-liner, i.e.,
repoquery --requires --resolve PACKAGE_NAME
I take notes about what pacakges I removed during the upgrade process and reinstall/install all the dependent packages in a shell script, like
#!/bin/bash
packages=(libpq-devel apr annobin)
[ -f install.txt ] && rm install.txt
[ -f reinstall.txt ] && rm reinstall.txt
[ -f pacakge_dep.txt ] && rm package_dep.txt
touch install.txt
touch reinstall.txt
for pkg in ${packages[@]}; do
repoquery -y --requires --resolve ${pkg} > pacakge_dep.txt
cat pacakge_dep.txt | \
while read p; do
rpm -q $p
if [ $? -ne 0 ]; then
echo $p >> install.txt
else
echo $p >> reinstall.txt
fi
done
done
for pkg in ${packages[@]}; do
rpm -q $pkg
if [ $? -ne 0 ]; then
echo $pkg >> install.txt
else
echo $pkg >> reinstall.txt
fi
done
if [ -s install.txt ]; then
dnf install -y $(sort install.txt | uniq)
fi
if [ -s reinstall.txt ]; then
dnf reinstall -y $(sort reinstall.txt | uniq)
fi
You may replace packages
by your list of packages.
No comments:
Post a Comment