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