From ebbe78764070455ce59634aab44c99e4184c6a68 Mon Sep 17 00:00:00 2001 From: Neal Gompa Date: Mar 03 2022 05:38:57 +0000 Subject: Migrate rpmdb to /usr/lib/sysimage/rpm See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr --- diff --git a/rpm-4.16.x-rpm_dbpath.patch b/rpm-4.16.x-rpm_dbpath.patch new file mode 100644 index 0000000..ae3189f --- /dev/null +++ b/rpm-4.16.x-rpm_dbpath.patch @@ -0,0 +1,12 @@ +diff '--color=auto' -rup rpm-4.16.1.3-orig/macros.in rpm-4.16.1.3/macros.in +--- rpm-4.16.1.3-orig/macros.in 2020-09-30 03:48:01.216567738 -0400 ++++ rpm-4.16.1.3/macros.in 2022-03-03 00:20:16.830231123 -0500 +@@ -153,7 +153,7 @@ + %_bzip2bin %{__bzip2} + + # The location of the rpm database file(s). +-%_dbpath %{_var}/lib/rpm ++%_dbpath %{_usr}/lib/sysimage/rpm + + # The location of the rpm database file(s) after "rpm --rebuilddb". + %_dbpath_rebuild %{_dbpath} diff --git a/rpm.spec b/rpm.spec index bcd8a8d..fe87fbd 100644 --- a/rpm.spec +++ b/rpm.spec @@ -32,7 +32,7 @@ %global rpmver 4.16.1.3 #global snapver rc1 -%global rel 11 +%global rel 11.1 %global sover 9 %global srcver %{rpmver}%{?snapver:-%{snapver}} @@ -57,6 +57,11 @@ Source1: db-%{bdbver}.tar.gz Source10: rpmdb-rebuild.service +Source20: rpmdb-migrate.service +Source21: rpmdb_migrate + +# Set rpmdb path to /usr/lib/sysimage/rpm +Patch0: rpm-4.16.x-rpm_dbpath.patch # Disable autoconf config.site processing (#962837) Patch1: rpm-4.15.x-siteconfig.patch # In current Fedora, man-pages pkg owns all the localized man directories @@ -161,6 +166,11 @@ BuildRequires: audit-libs-devel BuildRequires: ima-evm-utils-devel >= 1.0 %endif +# For the rpmdb migration scriptlet (#2055033) +Requires(pre): coreutils +Requires(pre): findutils +Requires(pre): sed + %description The RPM Package Manager (RPM) is a powerful command line driven package management system capable of installing, uninstalling, @@ -404,6 +414,10 @@ popd mkdir -p $RPM_BUILD_ROOT%{_unitdir} install -m 644 %{SOURCE10} $RPM_BUILD_ROOT/%{_unitdir} +install -m 644 %{SOURCE20} $RPM_BUILD_ROOT/%{_unitdir} + +mkdir -p $RPM_BUILD_ROOT%{rpmhome} +install -m 755 %{SOURCE21} $RPM_BUILD_ROOT/%{rpmhome} # Save list of packages through cron mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/cron.daily @@ -414,17 +428,17 @@ install -m 644 scripts/rpm.log ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/rpm %if %{with bdb} mkdir -p ${RPM_BUILD_ROOT}%{_tmpfilesdir} -echo "r /var/lib/rpm/__db.*" > ${RPM_BUILD_ROOT}%{_tmpfilesdir}/rpm.conf +echo "r /usr/lib/sysimage/rpm/__db.*" > ${RPM_BUILD_ROOT}%{_tmpfilesdir}/rpm.conf %endif mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rpm mkdir -p $RPM_BUILD_ROOT%{rpmhome}/macros.d -mkdir -p $RPM_BUILD_ROOT/var/lib/rpm +mkdir -p $RPM_BUILD_ROOT/usr/lib/sysimage/rpm # init an empty database for %ghost'ing for all supported backends for be in %{?with_ndb:ndb} %{?with_sqlite:sqlite} %{?with_bdb:bdb}; do ./rpmdb --define "_db_backend ${be}" --dbpath=${PWD}/${be} --initdb - cp -va ${be}/. $RPM_BUILD_ROOT/var/lib/rpm/ + cp -va ${be}/. $RPM_BUILD_ROOT/usr/lib/sysimage/rpm/ done %find_lang rpm @@ -443,16 +457,25 @@ make check TESTSUITEFLAGS=-j%{_smp_build_ncpus} || (cat tests/rpmtests.log; exit make clean %endif -# Handle rpmdb rebuild service on erasure of old to avoid ordering issues -# https://pagure.io/fesco/issue/2382 -%triggerun -- rpm < 4.15.90-0.git14971.10 +%pre +# Symlink all rpmdb files to the new location if we're still using /var/lib/rpm +if [ -d /var/lib/rpm ]; then + mkdir -p /usr/lib/sysimage/rpm + rpmdb_files=$(find /var/lib/rpm -maxdepth 1 -type f | sed 's|^/var/lib/rpm/||g' | sort) + for rpmdb_file in ${rpmdb_files[@]}; do + ln -sfr /var/lib/rpm/${rpmdb_file} /usr/lib/sysimage/rpm/${rpmdb_file} + done +fi + +%triggerun -- rpm < 4.16.1.3-11.1 +# Handle rpmdb migrate service on erasure of old to avoid ordering issues if [ -x /usr/bin/systemctl ]; then - systemctl --no-reload preset rpmdb-rebuild ||: + systemctl --no-reload preset rpmdb-migrate ||: fi %posttrans -if [ -f /var/lib/rpm/Packages ]; then - touch /var/lib/rpm/.rebuilddb +if [ -d /var/lib/rpm ]; then + touch /var/lib/rpm/.migratedb fi %files -f rpm.lang @@ -464,12 +487,13 @@ fi %endif %{_unitdir}/rpmdb-rebuild.service +%{_unitdir}/rpmdb-migrate.service %dir %{_sysconfdir}/rpm -%attr(0755, root, root) %dir /var/lib/rpm -%attr(0644, root, root) %ghost %config(missingok,noreplace) /var/lib/rpm/* -%attr(0644, root, root) %ghost /var/lib/rpm/.*.lock +%attr(0755, root, root) %dir /usr/lib/sysimage/rpm +%attr(0644, root, root) %ghost %config(missingok,noreplace) /usr/lib/sysimage/rpm/* +%attr(0644, root, root) %ghost /usr/lib/sysimage/rpm/.*.lock %{_bindir}/rpm %if %{with libarchive} @@ -611,6 +635,10 @@ fi %doc doc/librpm/html/* %changelog +* Thu Mar 03 2022 Neal Gompa - 4.16.1.3-11.1 +- Migrate rpmdb to /usr/lib/sysimage/rpm + https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr + * Mon Feb 14 2022 Michal Domonkos - 4.16.1.3-11 - Fix IMA signature lengths assumed constant, take III (#2018937) - Fix regression reading rpm v3 and other rare packages (#2037186) diff --git a/rpmdb-migrate.service b/rpmdb-migrate.service new file mode 100644 index 0000000..54a934d --- /dev/null +++ b/rpmdb-migrate.service @@ -0,0 +1,18 @@ +[Unit] +Description=RPM database migration to /usr +ConditionPathExists=/var/lib/rpm/.migratedb + +# This should run before any daemons that may open the rpmdb +DefaultDependencies=no +After=sysinit.target +Before=basic.target shutdown.target +Conflicts=shutdown.target +# In case /var is remote-mounted +RequiresMountsFor=/var + +[Service] +Type=oneshot +ExecStart=/usr/lib/rpm/rpmdb_migrate + +[Install] +WantedBy=basic.target diff --git a/rpmdb-rebuild.service b/rpmdb-rebuild.service index 0580adb..4cd2f33 100644 --- a/rpmdb-rebuild.service +++ b/rpmdb-rebuild.service @@ -1,19 +1,19 @@ [Unit] Description=RPM database rebuild -ConditionPathExists=/var/lib/rpm/.rebuilddb +ConditionPathExists=/usr/lib/sysimage/rpm/.rebuilddb # This should run before any daemons that may open the rpmdb DefaultDependencies=no After=sysinit.target Before=basic.target shutdown.target Conflicts=shutdown.target -# In case /var is remote-mounted -RequiresMountsFor=/var +# In case /usr is remote-mounted +RequiresMountsFor=/usr [Service] Type=oneshot ExecStart=/usr/bin/rpmdb --rebuilddb -ExecStartPost=rm -f /var/lib/rpm/.rebuilddb +ExecStartPost=rm -f /usr/lib/sysimage/rpm/.rebuilddb [Install] WantedBy=basic.target diff --git a/rpmdb_migrate b/rpmdb_migrate new file mode 100644 index 0000000..196744d --- /dev/null +++ b/rpmdb_migrate @@ -0,0 +1,40 @@ +#!/bin/bash +# Script to migrate rpmdb from /var/lib/rpm to new rpmdb path in /usr + +# Copyright (C) 2022 Neal Gompa . +# +# Fedora-License-Identifier: GPLv2+ +# SPDX-2.0-License-Identifier: GPL-2.0+ +# SPDX-3.0-License-Identifier: GPL-2.0-or-later +# +# This program is free software. +# For more information on the license, see COPYING or +# . +# For more information on free software, see +# . + + +set -euo pipefail + +# Script to migrate the rpmdb to /usr +rpmdb_path="$(rpm --eval '%_dbpath')" +rpmdb_path_old="/var/lib/rpm" +rpmdb_path_new="${rpmdb_path}" + + +if [ "${rpmdb_path}" = "${rpmdb_path_old}" ]; then + echo "The rpmdb path is still in /var, exiting!" + exit 0 +fi + +if [ -L "${rpmdb_path_old}" ]; then + echo "The rpmdb has already been migrated, exiting!" + rm -v "${rpmdb_path_old}/.migratedb" + exit 0 +fi + +rpm --verbose --rebuilddb + +rm -rfv ${rpmdb_path_old} + +ln -srv ${rpmdb_path_new} ${rpmdb_path_old}