#!/bin/bash
# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
#
# This script is run by rpm before the rpm is removed

#
# Exit codes
#
OK=0
FAIL=1

#
# Check we have the necessary arguments.
#

if [ $# -lt 1 -o $# -gt 1 ]
then
    echo "Usage: $0 install_flag"
    exit $FAIL
fi

if [ -z "${INSTDIR}" ]
then
    echo "INSTDIR not set"
    exit $FAIL
fi

INSTALL_FLAG="$1"
UPGRADE="false"

if [ ${INSTALL_FLAG} -ne 0 -a ${INSTALL_FLAG} -ne 1 ]
then
    echo "Invalid install_flag: ${INSTALL_FLAG}"
    exit $FAIL
fi

if [ ${INSTALL_FLAG} -eq 1 ]
then
    UPGRADE="true"
fi

if ! "${UPGRADE}"
then
    # Remove the files that are neither config nor data
    FILES_TO_REMOVE="${INSTDIR}/proxy/var/proxy.status
                     ${INSTDIR}/httpd/httpd-default/conf/extra/gateway/servers/empty.conf"
    rm -f ${FILES_TO_REMOVE}
fi
