#!/bin/bash
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
#
# Install the Java Beans needed by the SGD server
#
set -o errexit -o nounset -o pipefail

# Get the install directory parameter from the CLI arguments
if [ $# -ne 1 -o ! -d "$1" ]
then
    echo "Install directory not found." 1>&2
    echo "usage: $0 <install-dir>" 1>&2
    exit 1
fi

INSTDIR="$1"

# Set up the Java environment
source ${INSTDIR}/bin/scripts/install_scripts/set_java_defaults
: ${JAVA_OPTS:=""}
: ${JAVA_SYSTEM_PROPERTIES:="
-Djava.naming.tfn.flavour=disconnected-local-master
"}

# Create the directory that will contain the bean properties
mkdir -p "${INSTDIR}/var/serverconfig/global/beans"

# Install each bean using it's bean installer class
for bean_installer_class in "com.sco.tta.server.config.Install" \
        "com.sco.tta.server.login.ldap.Install" \
        "com.sco.tta.server.login.webauth.Install" \
        "com.sco.tta.server.login.thirdparty.Install" \
        "com.sco.tta.server.login.authenticationtoken.Install" \
        "com.sco.tta.server.login.securid.Install" \
        "com.sco.tta.server.login.freeaccess.Install"
do
    # Install the bean
    echo "Installing ${bean_installer_class}...."
    ${JAVA_BIN}/java ${JAVA_OPTS} -classpath "${DEFAULT_JAVA_CLASSPATH}" \
        ${DEFAULT_JAVA_PROPERTIES} \
        ${JAVA_SYSTEM_PROPERTIES} \
        ${bean_installer_class} \
            INSTALLDIR="${INSTDIR}" \
            --verbose
done
