ebbe78
#!/bin/bash
ebbe78
# Script to migrate rpmdb from /var/lib/rpm to new rpmdb path in /usr
ebbe78
ebbe78
# Copyright (C) 2022 Neal Gompa <ngompa@fedoraproject.org>.
ebbe78
#
ebbe78
# Fedora-License-Identifier: GPLv2+
ebbe78
# SPDX-2.0-License-Identifier: GPL-2.0+
ebbe78
# SPDX-3.0-License-Identifier: GPL-2.0-or-later
ebbe78
#
ebbe78
# This program is free software.
ebbe78
# For more information on the license, see COPYING or
ebbe78
# <https://www.gnu.org/licenses/gpl-2.0.en.html>.
ebbe78
# For more information on free software, see
ebbe78
# <https://www.gnu.org/philosophy/free-sw.en.html>.
ebbe78
ebbe78
ebbe78
set -euo pipefail
ebbe78
ebbe78
# Script to migrate the rpmdb to /usr
ebbe78
rpmdb_path="$(rpm --eval '%_dbpath')"
ebbe78
rpmdb_path_old="/var/lib/rpm"
ebbe78
rpmdb_path_new="${rpmdb_path}"
ebbe78
ebbe78
ebbe78
if [ "${rpmdb_path}" = "${rpmdb_path_old}" ]; then
ebbe78
	echo "The rpmdb path is still in /var, exiting!"
ebbe78
	exit 0
ebbe78
fi
ebbe78
ebbe78
if [ -L "${rpmdb_path_old}" ]; then
ebbe78
	echo "The rpmdb has already been migrated, exiting!"
ebbe78
	rm -v "${rpmdb_path_old}/.migratedb"
ebbe78
	exit 0
ebbe78
fi
ebbe78
ebbe78
rpm --verbose --rebuilddb
ebbe78
ebbe78
rm -rfv ${rpmdb_path_old}
ebbe78
ebbe78
ln -srv ${rpmdb_path_new} ${rpmdb_path_old}