#!/bin/bash

. /usr/share/preupgrade/common.sh

#END GENERATED SECTION

ADD_ONS=\
"83.pem|HighAvailability|/content/htb/rhel/server/7/\$basearch/highavailability/os 
90.pem|ResilientStorage|/content/htb/rhel/server/7/\$basearch/resilientstorage/os"

PART_RHEL7="92.pem|ScalableFileSystem 85.pem|LoadBalancer"
found=0
found_info=0
cd /etc/pki/product
for addon in $PART_RHEL7
do
    PEM_NAME=`echo $addon | cut -d'|' -f1`
    NAME=`echo $addon | cut -d'|' -f2`
    PEM=`ls -1 *.pem 2>/dev/null`
    echo "$PEM" | grep "$PEM_NAME" > /dev/null
    if [ $? -eq 0 ]; then
        found_info=1
        log_info "The module detects the $NAME Add-On. No action is needed for Red Hat Enterprise Linux 7."
    continue
    fi

done

for addon in $ADD_ONS
do
    PEM_NAME=`echo $addon | cut -d'|' -f1`
    NAME=`echo $addon | cut -d'|' -f2`
    PEM=`ls -1 *.pem 2>/dev/null`
    echo "$PEM" | grep "$PEM_NAME" > /dev/null
    if [ $? -eq 0 ]; then
        found=1
        log_high_risk "The module detects the $NAME Add-On. If you want to do the in-place upgrade, specify the $NAME repository as an argument to the '--addrepo' option in redhat-upgrade-tool."
        continue
    fi

done
if [ $found -eq 1 ]; then
    exit_fail
fi

if [ $found_info -eq 1 ]; then
  exit_informational
fi

exit_pass

