#!/bin/bash
###################### Include common files #######################
PVA_MN_CORE=1 #0
scriptDir=`dirname "$0"`
. ${scriptDir}/pva-agent-helper.sh || abort "Failed to include ${scriptDir}/pva-agent-helper.sh" 

############################### Go  ##############################
composeDbUpgradeConfig()
{
	PVA_VERSION=`rpm -q --qf "%{version}" pva-release`
	PVA_RELEASE=`rpm -q --qf "%{release}" pva-release`
	echo "Found PVA version ${PVA_VERSION}"
	echo > ${VZLCORE_SQL_DIR}/dbupgradefiles.list

	if [[ $PVA_MN_CORE == 1 ]]; then
		if [ "$PVA_VERSION" = "4.5" ]; then
			echo "mysql_45_46_upgrade.sql" >> ${VZLCORE_SQL_DIR}/dbupgradefiles.list
		fi
		if [ "$PVA_RELEASE" -le "1744" ]; then
			echo "mysql_46_463_upgrade.sql" >> ${VZLCORE_SQL_DIR}/dbupgradefiles.list
		fi
		if [ "$PVA_RELEASE" -le "1913" ]; then
			echo "mysql_463_60_upgrade.sql" >> ${VZLCORE_SQL_DIR}/dbupgradefiles.list
		fi
		if [ "$PVA_RELEASE" -le "2119" ]; then
			echo "mysql_60_601_upgrade.sql" >> ${VZLCORE_SQL_DIR}/dbupgradefiles.list
		fi
		if [ "$PVA_RELEASE" -le "2152" ]; then
			echo "mysql_603_604_upgrade.sql" >> ${VZLCORE_SQL_DIR}/dbupgradefiles.list
		fi
		if [ "$PVA_RELEASE" -le "2784" ]; then
			echo "mysql_6113_6114_upgrade.sql" >> ${VZLCORE_SQL_DIR}/dbupgradefiles.list
		fi
		if [ "$PVA_RELEASE" -le "3048" ]; then
			echo "mysql_6121_6122_upgrade.sql" >> ${VZLCORE_SQL_DIR}/dbupgradefiles.list
		fi
		if [ "$PVA_RELEASE" -le "3112" ]; then
			echo "mysql_6122_6123_upgrade.sql" >> ${VZLCORE_SQL_DIR}/dbupgradefiles.list
		fi
	else
		if [ "$PVA_RELEASE" -le "1600" ]; then
			echo "sqlit_46_463_upgrade.sql" >> ${VZLCORE_SQL_DIR}/dbupgradefiles.list
		fi
	fi
}

echo "------------------------------------------------------------------------------------------------"
date "+%b %e %T PVA preupgrade configuration : start"

# Stop services
composeDbUpgradeConfig

date "+%b %e %T PVA preupgrade configuration : stop"
echo "------------------------------------------------------------------------------------------------"
