Skip to content

Instantly share code, notes, and snippets.

@viliampucik
Created April 23, 2020 14:49
Show Gist options
  • Save viliampucik/ee39aa58ca4b34fff118c8e53ad2c754 to your computer and use it in GitHub Desktop.
Save viliampucik/ee39aa58ca4b34fff118c8e53ad2c754 to your computer and use it in GitHub Desktop.
PoC Handling Obsoletes by dnf
# Run a clean CentOS 8 Docker container
docker run --name dnf-obsoletes-test --rm -it centos:8 bash
# Inside the container install the necessary RPM building tools
dnf install -y rpmdevtools rpm-build redhat-rpm-config createrepo glibc-langpack-en
# Setup the environment
export LANG="en_US.UTF-8"
rpmdev-setuptree
SOURCEDIR="$(rpm --eval '%{_sourcedir}')"
RPMDIR="$(rpm --eval '%{_rpmdir}')"
ARCH="$(rpm --eval '%{_arch}')"
# Create and build obsoleted and successor example RPM packages
cat <<'EOF' > "${SOURCEDIR}/obsoleted-package.spec"
Name: obsoleted-package
Version: 1.0.0
Release: 1
Summary: Package to be obsoleted
License: MIT
%description
%files
EOF
cat <<'EOF' > "${SOURCEDIR}/successor-package.spec"
Name: successor-package
Version: 2.0.0
Release: 1
Summary: Successor package
License: MIT
Obsoletes: obsoleted-package <= 1.0.0
%description
%files
EOF
rpmbuild -bb "${SOURCEDIR}"/*.spec
# Initialize the repo of the example packages
createrepo "${RPMDIR}/${ARCH}"
cat <<EOF > /etc/yum.repos.d/test.repo
[test]
name=test
baseurl=file://${RPMDIR}/${ARCH}
gpgcheck=0
EOF
dnf makecache
# Now, try to install the obsoleted-package
dnf install --downloadonly --nobest obsoleted-package
# However, it tries to install successor-package
#===================================================================================
# Package Architecture Version Repository Size
#===================================================================================
#Installing:
# successor-package x86_64 2.0.0-1 test 5.9 k
#
#Transaction Summary
#===================================================================================
#Install 1 Package
#
#Total size: 5.9 k
#Installed size: 0
#DNF will only download packages for the transaction.
#Is this ok [y/N]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment