#!/bin/bash
#  Copyright (c) 2015 Actian Corporation, All Rights Reserved
#
# Name: allow_upgrade.sh
#
# Purpose:
#	Read version.rel and determine if upgrade is allowed to current
#	release from the installed version.
#
# Usage:
#	allow_upgrade
#	   
# Returns:
#	true 	- is allowed.
#	false	- if not.
#
#
#	02-Jul-2015 (hanje04)
#	    Created.
#	08-Jul-2015 (hanje04)
#	    Set defaults for vwinst/vhinst
#	01-Apr-2016 (hanje04) m8245
#	    Prevent upgrade from VH 4.0.1
#	03-Apr-2016 (hanje04) m8253
#	    Block direct upgrade from 4.1.1
#	04-Apr-2016 (hanje04) m8253
#	    Correct typo
#	28-Sep-2021 (frima01) II-5984, b136480
#	    Add Actian Client with short_name Actian.
#	    Block upgrade if product code does not match.
#	29-Sep-2025 (wanfr01) II-19099
#	    Add VectorMPP as new product variant in source/build/install
#	11-May-2026 (shust01) II-20718
#	    Rebranding change: Vector to Analytics Engine
#

short_name=Actian
prod_name="Actian Client"
prod_rel=1.5.0
versrel=${II_SYSTEM?}/ingres/version.rel
upg_ok=true
vwinst=false
vhinst=false
rc=0

# no version.rel assume it's a new install
[ -f ${versrel} ] || exit 0

# check the product
case "$short_name" in
    AnalyticsEngine)
	    inst_id=VW
	    vwinst=true
	    ;;
    Vortex|\
    AnalyticsEngineH)
	    inst_id=VH
	    vhinst=true
	    vwinst=true
	    ;;
    AnalyticsEngineMPP)
	    inst_id=VM
	    vhinst=true
	    vwinst=true
	    ;;
    "Ingres")
	    inst_id=II
	    ;;
    "Actian")
	    inst_id=AC
	    ;;
    *)
	    echo "Unknown product name: ${short_name}"
	    exit 1
	    ;;
esac

cur_rel=`grep "^$inst_id" $versrel | cut -d' ' -f 2`
if $vhinst ; then
    case $cur_rel in
      4.0.1|\
      4.1.1)
	    upg_ok=false
	    ;;
	*)
	    upg_ok=true
	    ;;
    esac
elif $vwinst ; then
    case $cur_rel in
	1.*|\
	2.*|\
	4.1.1)
	    upg_ok=false
	    ;;
    esac
else
    case $cur_rel in
	*)
	    upg_ok=true
	    ;;
    esac
fi

# if cur_rel is empty the products are not compatible
[ "x${cur_rel}" = "x" ] && upg_ok=false

$upg_ok ||
{
    cat << EOF
$prod_name $prod_rel does not support upgrade from:

    `head -1 ${versrel}`

For more information, contact Actian Corporation Technical Support.

EOF
    rc=1
}
exit $rc
