From dabd7d578c566a1276fc78b7f2b4c638ab7bada5 Mon Sep 17 00:00:00 2001 From: Igor Stegarescu Date: Fri, 10 Jan 2025 15:02:29 +0000 Subject: [PATCH] add function to upgrade major version of database --- addons/full-upgrade/run-upgrade.sh | 1 + addons/functions/database.functions | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/addons/full-upgrade/run-upgrade.sh b/addons/full-upgrade/run-upgrade.sh index 361f2561ba9..a4aee078425 100755 --- a/addons/full-upgrade/run-upgrade.sh +++ b/addons/full-upgrade/run-upgrade.sh @@ -130,6 +130,7 @@ function yum_upgrade_packetfence_package() { set_upgrade_to yum localinstall -y https://www.inverse.ca/downloads/PacketFence/RHEL8/packetfence-release-$UPGRADE_TO.el8.noarch.rpm yum clean all --enablerepo=packetfence + yum_upgrade_mariadb_server if is_enabled $1; then yum update -y --enablerepo=packetfence --exclude=packetfence-upgrade --allowerasing else diff --git a/addons/functions/database.functions b/addons/functions/database.functions index 3cc1f90a20b..f77af157097 100644 --- a/addons/functions/database.functions +++ b/addons/functions/database.functions @@ -254,3 +254,29 @@ function handle_devel_db_schema() { cp /usr/local/pf/db/pf-schema-X.Y.sql /usr/local/pf/db/pf-schema-$restoring_version.sql fi } + +function yum_upgrade_mariadb_server() { + installed=`rpm -q --whatprovides mysql-server 2> /dev/null` + if [ $? -eq 0 -a -n "$installed" ]; then + installed=`echo "$installed"|sed -n 1p` + version=`rpm -q --queryformat='%''{VERSION}' "$installed" 2>&1` +# myversion=$(yum --disablerepo=* --enablerepo=packetfence --quiet list available MariaDB-server | grep -i mariadb-server | awk '{print $2}' 2> /dev/null) + myversion=$(yum '--disablerepo=*' --enablerepo=packetfence --quiet list available --showduplicates MariaDB-server | grep -i mariadb-server | awk '{print $2}' | tail -1 2> /dev/null) + + old_family=`echo $version | sed -n -e 's,^\([1-9][0-9]*\.[0-9][0-9]*\)\..*$,\1,p'` + new_family=`echo $myversion | sed -n -e 's,^\([1-9][0-9]*\.[0-9][0-9]*\)\..*$,\1,p'` + + [ -z "$old_family" ] && old_family="" + [ -z "$new_family" ] && new_family="" + + if [ "$old_family" != "$new_family" ]; then + echo "Upgrade MariaDB-server from ${old_family} to ${new_family}" + systemctl stop packetfence-mariadb.service + rpm -e --nodeps MariaDB-client MariaDB-common MariaDB-server MariaDB-shared + yum install -q -y MariaDB-server --enablerepo=packetfence + systemctl start packetfence-mariadb.service + mariadb-upgrade + fi +fi +} +