#!/usr/bin/perl
#
# $Revision: 1.1 $
# Copyright 2025 Teleflora.
#
# Update BBj to our accepted Revision
#

use strict;
use warnings;
use English;
use Getopt::Long;
use POSIX;

my $HELP = 0;
my $VERSION = 0;
my $BBJ23 = 0;
my $BBJ24 = 0;
my $BBJ25 = 1;
my $BBJDV = 0;
my $SKIPBACKUP = 0;

my $OS = "";
my $ARCH = "";
my $POSDIR = "";
my $MEM = 0;
my $SMEM = 256;
my $XMEM = 0;
my $CHGXMX_XMS = 1;
my $PID = 0;
my $TMP1 = 0;
my $TMP2 = 0;
my $FOUND_ULIMIT = "";
my $CONSOLE_RMI = "";
my $BASIS_IDE = "";

my $AuthNumber = "";
my $AuthNumTest = "";
my $SerialNumber = "";
my $SerialNumTest = "";
my $Host_Name = "";
my $HostNameTest = "";
my $Host_Id = "";
my $HostIdTest = "";
my $Host_Ip = "";
my $LicFile = "";
my $RegFile = "";
my $config_ini = "";
my $ReturnVal = 0;
my $BBJ_JAR = "";
my $BBJ_TAR = "";
my $BBJ_VER = "";
my $BBJ_REV = "";
my $bbjHome = "/usr2/basis";
my $BBJ_INFOFILE = "";
my $JDK_X64 = "";
#my $JDK_X64W = "";
my $JRE_X64W = "";
my $JRE_X64WMSI = "";
my $JDK_X86 = "";
my $JVVR = "";
my $JV21 = "";
my $CLIENTL = "linux";
my $CLIENTW = "windows";
my @JAVA_CURR;
my @JAVA_NEED;
my $JavaInstalled = "1.0.0.0";
my $higherVerInst =0;
my $junk = "";
my $altReturnCode = 0;
my $BBjServAddOpts = "";
my $WaitForBBjProp = 0;
my $CertBLS = "false";
my $ClearConfigFont = "";
my $removeOldJava = "";
my $javaRmDirJar = "";
my $OldJavas = ();
my $UpdateRTI_IniVer = "true";
my $StartSection = "";
my $RTIMaj = 0;
my $RTIMin = 0;
my $RTINew = "";
my $ODBC_JAR = "";
my @classPathEntries = ();
my $classPathEntries = "";
my $newClassPath = "";

my @depricated_jars = qw(16.11/rtitws.jar azure/activation-1.1.jar azure/bcpkix-jdk15on-1.53.jar azure/bcprov-jdk15on-1.53.jar azure/commons-codec-1.10.jar azure/commons-collections4-4.1.jar azure/commons-lang3-3.5.jar azure/gson-2.2.4.jar azure/json-smart-1.3.1.jar azure/mail-1.4.7.jar azure/nimbus-jose-jwt-5.9.jar azure/slf4j-api-1.8.0-alpha2.jar BBjBootstrap.jar Bootstrap.jar.old BBjIndex.jar LocalKeyStore.expired rtitws.20201005.b3.jar rtitws.20240201.b3.16.10.4.j istack-commons-runtime.jar.unused jaxb-api.jar.unused jaxb-impl-2.4.0-b180830.0438.jar.unused jaxb-runtime.jar.unused webstart2120.jar webstart2145.jar webstart2166.jar ClientObjects.jar DemoClientFiles.jar examples.jar FontChooser.jar jfreechart-experimental.jar PDFRenderer.jar swingx.jar TimingFramework.jar BBjFilesystem.jar BBjThinClient.jar BBjUtil.jar SpellCheckerDictionary-am.jar SpellCheckerDictionary-en.jar SpellCheckerDictionary-fr.jar SpellChecker.jar);

# For next version update, vars to change  
#   $removeOldJars  1 to remove (moved out of /usr2/bbx/jars path), 0 to skip
my $removeDepricatedJars = 1;
my $depricated_jars = "";
my $depricated_dir = "";
my $renamed_jar = "";

# Doing update of bbj, put what java version is minimum acceptable of current - BBj version might support version 17 or even an extended 1.8.x, but we have moved forward to java version 21, so version would be 21 or greater
# java version.minorVersion. feature (always x.x.0), maint (may have - _ + and cna have characters after - _ + )
# 

#  If updating windows jre, change windows version in Enterprise Manager
#   replace in basis/cfg   BBj.properties and put copy in /usr2/bbx/config and 
#      jetty/.../jvm/windows
#   if java_win set will put copy in and add to BBj.prop line if blank
my $java_win = "";
my $WinDeployline = "";
my $Url = "https://tposlinux.blob.core.windows.net/rtibbjupdate";

#
my $JAVA_VER = "";
my $JAVA_REL = "";
my $JDIR_LINK = "";
my $BBJ_InstallFile = "";
my $TmpMbsNeeded = "2500";
#my $TmpDir = "/tmp/";
my $TmpDir = "/usr2/install_bbj/";
my $WorkDir = "/usr2/install_bbj/";
my $CreatedTmpDir = "false";
my $DF_JAVA = "";
my $DU_JAVA = "";
my $DF = "";
my $AVAILFS = "";
my $DemoTrueFalse = "false";
my $License_Type = "register";
my @blm_lic;
#   $blm_lic[] split from @blm_lic[] array  [1] contains server address
#   replace BLM_xxxxx with BLS_xxxxx vars
#my $BLM_Address = "";
#my $BLM_Remote = "false";
#my $BLM_Start_Type = "init";
#   add BLS vars  for moving forward
my $BLS_Address = "";
my $BLS_Remote = "false";
my $BLS_Start_Type = "init";
#   $blm_lic[] split from @blm_lic[] array  [1] contains server address

my $BasisProp1 = "";
my $BasisProp2 = "";
my $BasisProp3 = "";
my $BasisProp4 = "";

#  change to wanted version for java/bbj/rti version installed
#  use to check for jars in /usr2/bbx/jars and /usr2/basis/lib
#     now basis jars are in /usr2/basis/.lib
my $MSSQL_JAR_OLD = "mssql-jdbc-7.2.1.jre8.jar";
my $MSSQL_JAR = "mssql-jdbc-11.2.0.jre11.jar";
my $RtiTwsJar = "rtitws.jar"; 
my $RtiTwsJarNeeded = ""; 
my $BBJ_PROGS = ""; # "BBj24SpecProgs.tgz";


# Create a timestamp   
my $TimeStamp = POSIX::strftime("%Y%m%d%H%M%S", localtime(time));

#
# "0" means "do not install"
# "1" means "do install"
# "-1" means "default", which is dictated later on by other factors
# Barring any other factors, "-1" means "do".
#

my %InstallFlags = (
    java => -1,
);

GetOptions(
    "help" => \$HELP,
    "version" => \$VERSION,
    "bbj23" => \$BBJ23,
    "bbj24" => \$BBJ24,
    "bbj25" => \$BBJ25,
    "bbjdv" => \$BBJDV,
   "skipbackup" => \$SKIPBACKUP,
    "java!" => \$InstallFlags{'java'},
      "j21" => \$JV21,

);



# --version
if($VERSION != 0)
{
    print("$0 " . '$Revision: 1.1 $' . "\n");
    exit(0);
}

# --help
if($HELP != 0)
{
    usage();
    exit(0);
}

#if($BBJ23 == 0 and $BBJ24 == 0 and $BBJ25 == 0 and $BBJDV == 0) is this ok?
if($BBJ23 == 0 && $BBJ24 == 0 && $BBJ25 == 0 && $BBJDV == 0)
{
    print("$0 " . "No BBj Version Selected, Exiting \n");
    exit(0);
}
#

# Which Processor are we using?  Should be the same for intel or amd 64 bit now
open(PIPE, "uname -i |");
while(<PIPE>)
{
    if(/i.86/)
    {
        $ARCH = "x86";
    }
    if(/x86_64/)
    {
        $ARCH = "x64";
    }
}
close(PIPE);

# What IP to check blm / bls
open(PIPE, "hostname -i |");
while(<PIPE>)
{
    $Host_Ip = $_;
    chomp $Host_Ip;
}
close(PIPE);

# How much RAM for setting -Xmx and -Xms
open(PIPE, "free -h |");
while(<PIPE>)
{
    if ($_ =~ /^Mem:/)
    {
        $MEM = index ($_, 'G');
        $MEM = substr $_, 6, $MEM-6;
        $MEM = $MEM + 0;
        $XMEM = int ($MEM * 1024 / 2);
    }
}
close(PIPE);

$POSDIR = "/usr2/bbx";


loginfo("Begin $0 ");
loginfo("System has $MEM GB of memory, Architecture: $ARCH ");

open(PIPE, "/usr/java/latest/bin/java --version 2>/dev/null |");
while(<PIPE>)
{
    if ($_ =~ /Environment/)
    {
         $TMP1 = index ($_, 'build');
         $TMP2 = index ($_, ')');
         $JavaInstalled = substr $_, $TMP1+6, ($TMP2-1)-($TMP1+6)+1;
    }
}
close(PIPE);
loginfo("Java version currently installed: $JavaInstalled ");

loginfo("Checking for available disk space");

open(PIPE, "df -Pm /usr2|");
while(<PIPE>)
{
    if ($_ !~ /^Filesystem/)
    {
        my @DF = split(' ', $_ );
        $AVAILFS = $DF[3];
    }
}
close(PIPE);

loginfo("Need $TmpMbsNeeded and have $AVAILFS ");

if ( $AVAILFS >= $TmpMbsNeeded )
{
    loginfo("Ok to load on /usr2 partition in $TmpDir ");
    if ( -d "$TmpDir/")
    {
        loginfo("$TmpDir exists, continuing ");
    } else {
        loginfo("$TmpDir does not exists, creating ");
        mysystem ("mkdir $TmpDir");
        $CreatedTmpDir = "true";
    }
} else {
    loginfo("Not enough space on /usr2 partition, exiting ");
    exit 22;
}


#====  Set up has finished, here's where it does the update processes ======
# We must be root to do these things.
if($EUID == 0)
{

    if($BBJ23 != 0)
    {
        $BBJ_VER = "23";
    }

    if($BBJ24 != 0)
    {
        $BBJ_VER = "24";
    }


    if($BBJ25 != 0)
    {
        $BBJ_VER = "25";
    }

    if($BBJDV != 0)
    {
        $BBJ_VER = "dv";
    }
    
    getInfoFileAndRetrieve();

    if ( $BBJ_VER lt "24" )
    {
        $removeDepricatedJars = 0;
    }
    if ( $removeDepricatedJars != 0 ) 
    {
        if ( ! -d "/usr2/bbx/jars/old/")
        {
            mysystem("mkdir /usr2/bbx/jars/old/");
        }
        foreach $depricated_jars (@depricated_jars) 
        {
            # could/should parse directory name if one and move/remove
            #unlink /usr2/bbx/jars/$depricated_jars;
            # or unlink @depricated_jars; #if add /usr2/bbx/jars to the array assign name as dirname_filename and if dirname is empty, remove dir
            $renamed_jar = $depricated_jars;
            $renamed_jar =~ s+/+_+g;
            $depricated_dir = `dirname $depricated_jars`;
            chomp($depricated_dir);
            if ( $depricated_dir eq "." )
            {
                $depricated_dir = "";
            }
            if ( -e "/usr2/bbx/jar/$depricated_jars" )
            {
                loginfo("Move $depricated_jars to /usr2/bbx/jars/old/$renamed_jar ");
                mysystem("mv /usr2/bbx/jars/$depricated_jars /usr2/bbx/jars/old/$renamed_jar");
                if ( $depricated_dir ne "" )
                {
                    $junk = `ls -A /usr2/bbx/jars/$depricated_dir 2>/dev/null`;
                    chomp($junk);
                    if ( $junk eq "" )
                    {
                        loginfo("Removing $depricated_dir from /usr2/bbx/jars ");
                        mysystem("rmdir /usr2/bbx/jars/$depricated_dir");
                    }
                }
            }
        }
    }

    loginfo("Installing BBj Rev $BBJ_REV Software Dependencies...");

    if ($higherVerInst == 0)
    {
        loginfo("Install java ");
        install_java();
    }
        
    #if("$BBJ_PROGS" ne ""); # moved to after bbj install and changes
    #{
        #install_spec_progs();
    #}

    install_bbj_packages();


}

exit(0);

###################################################
###################################################
###################################################


sub usage
{
    print(<< "EOF");
$0 Usage:

$0 --version
$0 --help
$0 --bbj23       Installs BBj 23
$0 --bbj24       Installs BBj 24
$0 --bbj25       Installs BBj 25
$0 --bbjdv       Installs BBj, Latest Development or Barista/Demos build we have 
$0 --skipbackup       Skip removing basis.old and coping current to basis.old (for restart to save time)
$0 --java / --nojava  Do / Do not install Java (latest for BBj). Defaults to --java.
$0 --j21          If BBj Ver >= 24, check/install JDK21, else default is JDK17; if BBj Ver = 21 flag ignored, JDK11 used

EOF

}


#
# Install BBj version
#
sub install_bbj_packages
{
    my $line = "";

    # Install BBj

    loginfo("Stopping RTI Programs.....");
    mysystem("/sbin/service rti stop");
    mysystem("/usr2/bbx/bin/killem");
    loginfo("Stopping BBj Services.....");
    mysystem ("$POSDIR/bin/bbjservice.pl --stop");
    if ( -d "/usr2/basis/blm" )
    {
        loginfo("Stopping Basis License Manager.....");
        mysystem ("/sbin/service blm stop");
    }
    if ( -d "/usr2/basis/bls" )
    {
        loginfo("Stopping Basis License Service.....");
        mysystem ("/sbin/service bls stop");
    }

    if(-d "/usr2/basis")
    {
        if($SKIPBACKUP == 0)
        {
            loginfo("Removing current /usr2/basis-old ");
            mysystem("rm -rf /usr2/basis-old");
            if ( "$BBJ_VER" gt "23" )
            {
                loginfo("Renaming current /usr2/basis/ to /usr2/basis-old/...");
                mysystem("mv /usr2/basis /usr2/basis-old");
                if($ReturnVal != 0)
                {
                    logerror("Terminating update_bbj with return code $ReturnVal.");
                    exit($ReturnVal);
                }
            } else {
                loginfo("Copying current /usr2/basis/ to /usr2/basis-old/...");
                mysystem("cp -pr /usr2/basis /usr2/basis-old");
                if($ReturnVal != 0)
                {
                    logerror("Terminating update_bbj with return code $ReturnVal.");
                    exit($ReturnVal);
                }
            }
        } else {
            loginfo("Skip remove of and backup to /usr2/basis-old ");
        }
    } else {
        loginfo("/usr2/basis/ did not previously exist...");
    }

    loginfo("Installing BBj v" . $BBJ_REV . "...");
    if($BBJ_TAR ne "" && ! -e "${TmpDir}$BBJ_TAR.gz" && ! -e "${TmpDir}$BBJ_TAR" && ! -e "${TmpDir}$BBJ_JAR" )
    {
        loginfo("File should already be downloaded.  Exiting ");
        #loginfo("Retrieving $BBJ_TAR.gz to ${TmpDir}$BBJ_TAR.gz ");
        #mysystem("wget --proxy=off --cache=off --progress=dot:mega -o ${TmpDir}$BBJ_TAR.gz $Url/$BBJ_TAR.gz");
        if(! -e "${TmpDir}$BBJ_TAR.gz")
        {
            logerror("Could not download file $Url/$BBJ_TAR.gz");
            exit(1);
        }
    }
#####
#Basis license Info  BLM or BLS
####
    if (-e "/usr2/basis-old/cfg/blsclient.conf")
    {
        # license.bls, certificate.bls, BLS.properties, Register.properties
        # blsserver.conf, blsclient.conf
        # /root/bbj/ install.log, Install.properties, Register.properties

        loginfo("Checking for License Manager Local or Remote in bls .....");
        $RegFile = "/usr2/basis-old/cfg/Register.properties";
        $BLS_Address = `grep -i "^\\s\*host" /usr2/basis-old/cfg/blsclient.conf 2>/dev/null`;
        chomp $BLS_Address;
        if ($BLS_Address ne "")
        {
            $BLS_Address =~ s/\"//g;
            $BLS_Address =~ s/ //g;
            $BLS_Address =~ s+\s*host\s*[:=]\s*++g;
        }
        if ($BLS_Address =~ /localhost/i || $BLS_Address =~ /127.0.0.1/i || $BLS_Address =~ /$Host_Ip/i || $BLS_Address =~ /$Host_Id/i )
        {
            $BLS_Address = "";
        }
    }


    loginfo("Checking for License Manager Local or Remote in blm .....");
    if (-e "/usr2/basis-old/basis.lic" && ! -e "/usr2/basis-old/cfg/blsclient.conf")
    {
        $RegFile = "/usr2/basis-old/blm/Register.properties";
        loginfo("Checking basis.lic file");
        open (BBJLIC, "</usr2/basis-old/basis.lic");
        while (<BBJLIC>)
        {
            if ($BLS_Address eq "")
            {
                if ($_ =~ /^server[ ]{1,}.{1,}/i )
                {
                    loginfo("found server line: $_ ");
                    @blm_lic = split(' ', $_);
                    $BLS_Address = $blm_lic[1];
                    if ($BLS_Address =~ /localhost/i || $BLS_Address =~ /127.0.0.1/i || $BLS_Address =~ /$Host_Ip/i || $BLS_Address =~ /$Host_Id/i )
                    {
                        $BLS_Address = "";
                    }
                }    
            }
        }
        close BBJLIC;
        if ("$BLS_Address" ne "")
        {
            $BLS_Remote = "true";
            $License_Type = "bls";
            $BLS_Start_Type = "manual";
            loginfo("Remote bls server at $BLS_Address and BLS_Remote is $BLS_Remote ");
        }
    }

    loginfo("Getting AuthNumber for Basis License......");
    if (! -e "$RegFile")
    {
        loginfo("No Register.properties file exists...");
    } else {
        $AuthNumTest = `grep -i AuthNum\= $RegFile 2>/dev/null`;
        chomp $AuthNumTest;
        if ($AuthNumTest ne "")
        {
            my @AuthNum=split(/\=/, $AuthNumTest);
            if ( $#AuthNum > 0 )
            {
                $AuthNumber=$AuthNum[$#AuthNum];
            }
        }
        if ( "$AuthNumber" eq "AuthNum" )
        {
            $AuthNumber = "";
        }
        if ( "$AuthNumber" eq "" && "$BLS_Remote" ne "true" )
        { 
            loginfo("AuthNumber is blank and BLS_Remote is not true, set DEMOLIC to true ");
            $DemoTrueFalse = "true";
        }
        loginfo("Request Demo License: $DemoTrueFalse ");
        loginfo("AuthNumber = $AuthNumber");

        loginfo("Getting Serial Number..... ");    
        $SerialNumTest = `grep SerialNum\= $RegFile 2>/dev/null`;
        chomp $SerialNumTest;
        if ($SerialNumTest ne "")
        {
            my @SerialNum=split(/\=/, $SerialNumTest);
            if ($#SerialNum > 0 )
            {
                $SerialNumber=$SerialNum[$#SerialNum];
            }
        }
        if ( "$SerialNumber" eq "SerialNum" )
        {
            $SerialNumber = "";
        }
        loginfo("Serial Number = $SerialNumber");
    
        loginfo("Getting HostName .....");
        $HostNameTest = `grep HostName $RegFile 2>/dev/null`;
        chomp $HostNameTest;
        my @HostName=split(/\=/, $HostNameTest);
        if ($#HostName > 0)
        {
            $Host_Name=$HostName[$#HostName];
        }
        loginfo("Host Name = $Host_Name");
        
        loginfo("Getting Composite.....");
        $HostIdTest = `grep HostID $RegFile 2>/dev/null`;
        chomp $HostIdTest;
        my @HostId=split(/ID\=/, $HostIdTest);
        if ($#HostId > 0 )
        {
            $Host_Id=$HostId[$#HostId];
            if ( length($Host_Id) <= 30 )
            {
                $Host_Id = "";
            }
        }
        loginfo("Host ID = $Host_Id");
    }

    if ( -e "/tmp/certificate.bls.remote" )
    {
        $CertBLS = "true";
    }
    if ( $AuthNumber eq "" && $SerialNumber eq "" && $CertBLS ne "true" )
    {
        $DemoTrueFalse = "true";
        $BLS_Address = "localhost";
        $BLS_Remote = "false";
        $BLS_Start_Type = "init";
        $SerialNumber = "BBX000001";
        $AuthNumber = "9999999999";

        loginfo("Setting AuthNumber and SerialNumber to Request Demo License");
    }
    
    my $bbjinstallsettings = " ################################################################################
# BASIS Installation and Configuration Wizard options
# 
# 
# A forward slash or two back slashes should be used when specifying directories or files
# Passwords will be encrypted when recorded.
# 
# 
################################################################################
# Wizard Settings
# 
# The following variables set whether or not to run various BASIS
# installation and configuration wizards after the installation of the software.
# Setting a value to [interactive] will cause the specified wizard to be run
# interactively. Setting a value to [silent] will cause the specified wizard to
# be run silently. Setting a value to [progress] will cause the specified wizard to
# be run with a progress bar. Setting a value to [off] will prevent that wizard from being run.
# The UAC wizard will only be run on Windows machines in which UAC is enabled. The
# license selection and finish wizards can not be run silently.
# 
# The following value can be [interactive] [silent] [progress]. The default is [interactive].
INSTALL_WIZARD=silent
# The following values can be [off] [interactive] [silent] [progress]. The default is [off].

UAC_WIZARD=off
LICENSE_SELECTION_WIZARD=silent
LICENSE_REGISTER_WIZARD=silent
LICENSE_INSTALL_WIZARD=silent
BLS_CFG_STARTUP_WIZARD=silent
BLS_START_STOP_WIZARD=silent
BLS_DESIGNATION_WIZARD=off
BBJ_CFG_STARTUP_WIZARD=silent
BBJ_START_STOP_WIZARD=silent
EM_WIZARD=off
FINISH_WIZARD=silent
# 
################################################################################
# Global Wizard Detail Settings
# 
# The following value can be [en] [nl] [fr] [de] [it] [es] [sv].
# The default is the current locale language.
LANGUAGE=en
# The splash image can be a png or jpg and can be found in the installable jar or on disk. By default the BASIS splash image will be used.
# The following value can be [none] which will skip the splash window. A GUI environment is needed to display the splash window.
SPLASH_IMAGE=
# 
################################################################################
# Install Wizard Detail Settings
# 
# The following value can be [true] [false]. Default is [false].
INSTALL_LICENSE_AGREE=true
# Specifies the installation target directory on Window OS. If not specified the default c:/Program Files/basis directory will be used.
INSTALL_TARGET_DIRECTORY_WIN=
# Specifies the installation target directory on non-Window OS. If not specified the /opt/basis directory will be used on Mac, on all other OS the /usr/local/basis directory will be used.
INSTALL_TARGET_DIRECTORY_NON_WIN=/usr2/basis
# Specifies the java directory on Windows OS. If not specified or the specified directory does not exist the java directory will be set via hints.
INSTALL_JAVA_DIRECTORY_WIN=<REPLACEMEREPLACEME>
# Specifies the java directory on non-Windows OS. If not specified or the specified directory does not exist the java directory will be set via hints.
INSTALL_JAVA_DIRECTORY_NON_WIN=/usr/java/latest
# Specifies the comma separated features to install. If the feature is a parent
# of other features then all of its children features will be installed. The following features are available: ThinClient,BBjServices,BASIS Products,Enhanced HTML Controls,BBj,PRO5,Utilities,Barista,Admin Tools,JDBC,BASIS License Service,Additional Developer Tools,AddonSoftware,BASIS Product Suite,Demos
INSTALL_CUSTOM_FEATURES=BBj,JDBC,BASIS License Service
# The following properties can be specified to run a BBj program at the installation finish. The variable \$InstallDir can be used in values that contain a path to be relative to the BBj installation directory.
INSTALL_BBEXEC_PROGRAM=
INSTALL_BBEXEC_CONFIG=
INSTALL_BBEXEC_WORKING_DIR=
INSTALL_BBEXEC_TERMINAL=
INSTALL_BBEXEC_USER=
# The following value can be [true] [false]. Default is [false].
INSTALL_BBEXEC_QUIET=
INSTALL_BBEXEC_APP_NAME=
INSTALL_BBEXEC_APP_USER_NAME=
INSTALL_BBEXEC_CLASSPATH_NAME=
# The following value can be [true] [false]. Default is [false].
INSTALL_BBEXEC_SECURE=
INSTALL_BBEXEC_LOCAL_PORT=
INSTALL_BBEXEC_REMOTE_PORT=
INSTALL_BBEXEC_ARGS=
# The following value can be [true] [false]. Default is [false].
INSTALL_BBEXEC_SYNC=
# The following value default is 6, a wait of 30 seconds will be performed between retries, for a total default retry time of 3 minutes.
INSTALL_BBEXEC_NUM_RETRIES=
# The following value can be [true] [false]. Default is [false].
INSTALL_BBEXEC_SHOW_PROGRESS=
# The following value can be [true] [false]. Default is [false].
INSTALL_BBEXEC_ALLOW_CANCEL=
INSTALL_BBEXEC_PROGRESS_TITLE=
INSTALL_BBEXEC_PROGRESS_TEXT=
INSTALL_BBEXEC_FAILURE_TITLE=
INSTALL_BBEXEC_FAILURE_TEXT=
# 
################################################################################
# UAC Wizard Detail Settings
# 
# The following value can be [true] [false]. Default is [false].
UAC_ELEVATE=
# 
################################################################################
# License Selection Wizard Detail Settings
# 
# The license regsistration, install, and brand wizards will
# be automatically added, depending on the user selection.
# The following value can be [register] [install] [blm]. Default is [register]
LICENSE_SELECTION_OPTION=$License_Type
# 
################################################################################
# License Registration Wizard Detail Settings
# 
# The following value can be [true] [false]
LICENSE_REGISTER_DEMOLIC=$DemoTrueFalse
LICENSE_REGISTER_COMPANYNAME=Teleflora
LICENSE_REGISTER_FIRSTNAME=JJ
LICENSE_REGISTER_LASTNAME=Blankenship
LICENSE_REGISTER_EMAIL=jblankenship\@teleflora.com
LICENSE_REGISTER_FAX=
LICENSE_REGISTER_PHONE=800.621.8324
# The following values can be left empty, so that they will be dynamically populated
LICENSE_REGISTER_HOSTNAME=
LICENSE_REGISTER_HOSTID=
# The following are only used when LICENSE_REGISTER_DEMOLIC=[false]
LICENSE_REGISTER_SERIALNUM=$SerialNumber 
LICENSE_REGISTER_AUTHNUM=$AuthNumber
# The following are only used when LICENSE_REGISTER_DEMOLIC=[true]
LICENSE_REGISTER_DEMOUSERCOUNT=
LICENSE_REGISTER_DEMOSERIALNUM=BBX000001
LICENSE_REGISTER_DEMOAUTHNUM=9999999999
# The following value can be [auto] [web] [email] [phone] [other]. Default is [auto]
LICENSE_REGISTER_REGMETHOD=auto
# The following value can be [web] [email]. Default is [web]. This setting is not
# used if LICENSE_REGISTER_REGMETHOD=[auto]
LICENSE_REGISTER_DELMETHOD=
# The following value can be [true] [false]. Default is [true].
LICENSE_REGISTER_COUNTRYUSACANADA=true
# The following value can be [true] [false]. Default is [false].
LICENSE_REGISTER_WANTINFO=false
# The following value can be [true] [false]. Default is [false].
LICENSE_REGISTER_NOTEBOOK=false
# The following value is only used when LICENSE_REGMETHOD=[phone].
# Specify path and file name, a ASCII text file will be generated by the wizard.
LICENSE_REGISTER_PHONEFILE=
# The following value is only used when LICENSE_REGMETHOD=[other].
# Specify path and file name, a ASCII text file will be generated by the wizard.
LICENSE_REGISTER_OTHERFILE=
# 
################################################################################
# License Install Wizard Detail Settings
# 
# The following value can be [true] [false]. Default is [false].
LICENSE_INSTALL_ENTERLICINFO=false
# The following is only used when LICENSE_INSTALL_ENTERLICINFO=[false].
# Specify the location of an existing license file.
LICENSE_INSTALL_LICENSEFILE=
# 
################################################################################
# BLS Designation Wizard Detail Settings
#
# The following value can be [true] [false]. Default is [false].
BLS_DESIGNATION_CUSTOM=
BLS_DESIGNATION_SERVERNAME=
BLS_DESIGNATION_CERTIFICATE_FILE=
#
################################################################################
# BLS Configuration Startup Wizard Detail Settings
#
# The following properties are for the Windows OS
# The following value can be [service] [login] [manual]. Default is [service].
BLS_CFG_STARTUP_TYPE_WIN=
# The following value can be [auto] [manual] [disabled]
BLS_CFG_STARTUP_SERVICESTARTUPTYPE_WIN=
# The following property is for non-Windows OS
# The following value can be [init] [login]-mac only [manual]. Default is [init]
BLS_CFG_STARTUP_TYPE_NON_WIN=$BLS_Start_Type
BLS_CFG_STARTUP_PASSWORD_NON_WIN=ENCRYPTED:oDzMA2Q2FFo=
#
################################################################################
# BLS Service Wizard Detail Settings
#
# The following value can be [start] [stop] [restart]
BLS_START_STOP_STARTUP=
#
################################################################################
# BBj Configuration Startup Wizard Detail Settings
#
# The following properties are for Windows OS
# The following value can be [service] [login] [manual]. Default is [service].
BBJ_CFG_STARTUP_TYPE_WIN=
BBJ_CFG_STARTUP_USERACCOUNT_WIN=
BBJ_CFG_STARTUP_PASSWORD_WIN=
# The following value is only used when run as a service and can be [auto] [manual] [disabled]
BBJ_CFG_STARTUP_SERVICESTARTUPTYPE_WIN=
# The following properties are for non-Windows OS
# The following value can be [init] [manual]. Default is [init].
BBJ_CFG_STARTUP_TYPE_NON_WIN=init
BBJ_CFG_STARTUP_USERACCOUNT_NON_WIN=root
BBJ_CFG_STARTUP_PASSWORD_NON_WIN=ENCRYPTED:oDzMA2Q2FFo=
# 
################################################################################
# BBj Services Wizard Detail Settings
# 
# The following value can be [start] [stop] [restart]
BBJ_START_STOP_STARTUP=start
# The following values are only used if BBJ_START_STOP_STARTUP=[stop].
# The following default value is [localhost]
BBJ_START_STOP_SERVERNAME=localhost
# The following default value is [2002]
BBJ_START_STOP_ADMINPORT=2002
# The following default value is [admin]
BBJ_START_STOP_USERNAME=
# The following default value is [admin123] only in silent mode
BBJ_START_STOP_USERPASSWORD=ENCRYPTED:oDzMA2Q2FFo=
# The following default value is [false]
BBJ_START_STOP_WAITFORCLIENTS=false
# 
################################################################################
# EM Wizard Detail Settings
# 
EM_CURADMINPASSWORD=
EM_NEWADMINPASSWORD=
EM_SERVERNAME=
EM_ADMINPORT=
";
##EOF
    open(BBJINST, "> ${TmpDir}bbjinstallsettings.txt");
    print BBJINST $bbjinstallsettings;
    close(BBJINST);


    loginfo("Removing existing /usr2/bbx/config/config.ini.....");
    mysystem("rm -r /usr2/bbx/config/config.ini");
    loginfo("Creating new /usr2/bbx/config/config.ini.....");
    $config_ini = "
[RTI14]
DATEFORMAT.1=
DATEFORMAT.2=
RWUSERS=
DATESUFFIX.2=
CREATETABLETYPE=6
DATESUFFIX.1=
DICTIONARY=/usr2/bbx/dict/
DATABASE=RTI14
ROUSERS=
TRUNCATEIFTOOLONG=Y
ADVISORYLOCKING=Y
ADMINUSERS=
DATECOLUMNSSORTED=false
ACCESSPOLICY=ALL
Y2KWINDOW.1=0
DATESUFFIX=
Y2KWINDOW.2=0
CHARSET=
READONLY=N
Y2KWINDOW=0
DATA=/usr2/bbx/bbxd/
DATEFORMAT=
AUTO_ANALYZE_TABLES=false

[RTI]
DATEFORMAT.1=
DATEFORMAT.2=
RWUSERS=
DATESUFFIX.2=
CREATETABLETYPE=6
DATESUFFIX.1=
DICTIONARY=/usr2/bbx/odbc_dict/
DATABASE=RTI
ROUSERS=
TRUNCATEIFTOOLONG=Y
ADVISORYLOCKING=Y
ADMINUSERS=
DATECOLUMNSSORTED=false
ACCESSPOLICY=ALL
Y2KWINDOW.1=0
DATESUFFIX=
Y2KWINDOW.2=0
CHARSET=
READONLY=N
Y2KWINDOW=0
DATA=/usr2/bbx/bbxd/
DATEFORMAT=
AUTO_ANALYZE_TABLES=false";
# end of config_ini define

    open(BBJCFG, "> /usr2/bbx/config/config.ini");
    print BBJCFG $config_ini;
    close(BBJCFG);
    mysystem("chmod 775 /usr2/bbx/config/config.ini"); 
    mysystem("chown tfsupport:rtiadmins /usr2/bbx/config/config.ini"); 
    # have BBJ_TAR (or .gz) file and installsettings file so proceed
    if( (-e "${TmpDir}$BBJ_JAR" || -e "${TmpDir}$BBJ_TAR.gz" || -e "${TmpDir}$BBJ_TAR") &&  (-e "${TmpDir}bbjinstallsettings.txt"))
    {
        if (-d "${WorkDir}")
        {
            loginfo("Directory ${WorkDir} exists.....");
        } else {
            loginfo("Creating ${WorkDir} directory.....");
            mysystem ("mkdir ${WorkDir}");
        }
        if ($BBJ_TAR ne "")
        {
            if (-e "${TmpDir}$BBJ_TAR" && ! -e "${WorkDir}$BBJ_TAR" )
            {
                loginfo("Moving $BBJ_TAR to ${WorkDir} directory.....");
                mysystem ("mv ${TmpDir}$BBJ_TAR ${WorkDir}");
            } else {
                loginfo("Moving $BBJ_TAR.gz to ${WorkDir} directory.....");
                mysystem ("mv ${TmpDir}$BBJ_TAR.gz ${WorkDir}");
            }

            if (-e "${WorkDir}$BBJ_TAR.gz" && ! -e "${WorkDir}$BBJ_TAR")
            {
                loginfo("Gunziping and untar $BBJ_TAR......");
                mysystem("gunzip ${WorkDir}$BBJ_TAR.gz");
                if($ReturnVal != 0)
                {
                    logerror("Terminating update_bbj with return code $ReturnVal.");
                    exit($ReturnVal);
                }
            }
            #  process the BBjxxxx.jar file 
            mysystem ("tar -xvf ${WorkDir}$BBJ_TAR -C ${WorkDir}");
            if($ReturnVal != 0)
            {
                logerror("Terminating update_bbj with return code $ReturnVal.");
                exit($ReturnVal);
            }
            loginfo("Untaring $BBJ_TAR.......");
            loginfo("Installing $BBJ_TAR......");
        }

        #mysystem ("mv ${TmpDir}bbjinstallsettings.txt ${WorkDir}"); 

        if (-e "${TmpDir}$BBJ_JAR" && ! -e "${WorkDir}$BBJ_JAR")
        {
            loginfo("Moving $BBJ_JAR to ${WorkDir} directory.....");
            mysystem ("mv ${TmpDir}$BBJ_JAR ${WorkDir}");
        }
        loginfo("Installing $BBJ_JAR.......");
        mysystem("/usr/java/latest/bin/java -jar ${WorkDir}$BBJ_InstallFile -p ${WorkDir}bbjinstallsettings.txt");
        if($ReturnVal != 0)
        {
            logerror("Terminating update_bbj with return code $ReturnVal.");
            exit($ReturnVal);
        }
        loginfo("Completed $BBJ_JAR Installation......");

        loginfo("Create Gui Util Program ");
        BBj_Setup_util();
        sleep (2);
        loginfo("Running Gui Util ");
        BBj_Setup_run();
        sleep (2);

        loginfo("Basis starts BBj after Jar installation, makes BBJ.prop chgs");
        loginfo("Listing BBj.properties for reference");
        mysystem("ls -Gg /usr2/basis/cfg/BBj.properties");
        loginfo("Sleeping 120 seconds then stop BBj before changing BBj.properties ");
        sleep (120);
        loginfo("Stopping bbj ");
        mysystem("/sbin/service bbj stop");
        sleep (10);
        loginfo("Listing BBj.properties after BBj stopped for reference");
        mysystem("ls -Gg /usr2/basis/cfg/BBj.properties");

        #loginfo("Removing /var/www/lib/ files.....");
        loginfo("Webstart access is no longer accepted. Removing all files in /var/www/ relating to BBj.");
        mysystem("rm -r /var/www/lib/* 2>/dev/null");
        loginfo("removing /var/www/jnlp/ files.....");
        mysystem("rm -r /var/www/jnlp/* 2>/dev/null");
        loginfo("removing /var/www/cgi-bin/ files.....");
        mysystem("rm -r /var/www/cgi-bin/* 2>/dev/null");
        # if not already present, get latest (mssql-jdbc-11.2.0.jre11.jar) from cloud storage (RTI_MONITOR needs it to write to outside database
        if ( -e "/usr2/bbx/jars/$MSSQL_JAR" )
        {
            loginfo("The $MSSQL_JAR file already in /usr2/bbx/jars, skipping");
        } else {
            loginfo("Downloading $MSSQL_JAR from cloud storage...");
            mysystem("wget --proxy=off --cache=off --progress=dot:mega -o ${WorkDir}$MSSQL_JAR $Url/$MSSQL_JAR");    
            loginfo("Done downloading $MSSQL_JAR ...");
            mysystem("cp ${WorkDir}$MSSQL_JAR /usr2/bbx/jars/$MSSQL_JAR");
            loginfo("Copied $MSSQL_JAR /usr2/bbx/jars/ ");
        }

        # If rtitws.jar included, rename and replace the one in /usr2/bbx/jars 
        if ( -e "${WorkDir}rtitws.jar" )
        {
            loginfo("Copying rtitws.jar to backups and replacing ...");
            mysystem("cp -pr /usr2/bbx/jars/rtitws.jar /usr2/bbx/backups/rtitws.jar." . $TimeStamp);
            mysystem("cp ${WorkDir}rtitws.jar /usr2/bbx/jars/rtitws.jar"); 
        }
        #
        # loginfo("Copy new jnlp.pl to /var/www/cgi-bin/ .....");
        #mysystem("cp -pr ${WorkDir}bin/jnlp.pl /var/www/cgi-bin/");
        #mysystem("chmod 775 /var/www/cgi-bin/jnlp.pl");

        mysystem("cp /usr2/basis/cfg/BBj.properties /usr2/basis/cfg/BBj.properties.work");
        open BBJPROP, "</usr2/basis/cfg/BBj.properties.work";
        open BBJPROPOUT, ">/usr2/basis/cfg/BBj.properties.tmp";     
        while (<BBJPROP>)
        {
            if ($_ =~ /com.basis.appdeployment.jre.defaultWindows/ && $java_win ne "" )
            {
                if ($_ !~ m/$java_win/)
                {
                    $_ =~ s/com.basis.appdeployment.jre.defaultWindows\=\s+$/com.basis.appdeployment.jre.defaultWindows\=${java_win}\n/;
                }
            }
        
            if ($_ =~ /^basis.java.args.BBjServices/)
            {
                $BBjServAddOpts = "";
                if ($_ !~ m/\-server/)
                {
                    $_ =~ s/basis.java.args.BBjServices\=/basis.java.args.BBjServices\=\-server /;
                }
                my $countCheck = 0;
                $countCheck = () = $_ =~ /\-Dfile.encoding\\=ISO\-8859\-1/g;
                if ($countCheck > 1 )
                {
                    $_ =~ s/\-Dfile.encoding\\=ISO\-8859\-1//g;
                }
                $countCheck = 0;
                if ($_ !~ m/\-Dfile.encoding\\=ISO\-8859\-1/)
                {
                    $BBjServAddOpts .= " \-Dfile.encoding\\=ISO\-8859\-1";
                }

                $_ =~ s/\ -XX\\:\+PrintGCTimeStamps//g;
                $_ =~ s/\ -XX\\:\+PrintGCDateStamps//g;
                $_ =~ s/\ -XX\\:\+PrintGCApplicationConcurrentTime//g;
                $_ =~ s/\ -XX\\:\+PrintGCApplicationStoppedTime//g;
                $_ =~ s/\-XX\\:\+UseConcMarkSweepGC \-/\-XX\\:\+UseG1GC \-/g;
                $_ =~ s/\-XX\\:\+CMSIncrementalMode /\-XX\\:MaxGCPauseMillis\\=500 /g;
                $_ =~ s/\-XX\\:CMSIncrementSafetyFactor\\=20 //g;
                $_ =~ s/\-XX\\:CMSInitiatingOccupancyFraction\\=70 //g;

                if ($CHGXMX_XMS != 0)
                {
                    if ($_ =~ m/\-Xms/ )
                    {
                        $_ =~ s/\-Xms\d*m/\-Xms${SMEM}m/g;
                    } else {
                        $_ =~ s/BBjServices\=/BBjServices\=\-Xms${SMEM}m /;
                    }
                    if ($_ =~ m/\-Xmx/ )
                    {
                        $_ =~ s/\-Xmx\d*m/\-Xmx${XMEM}m/g;
                    } else {
                        $_ =~ s/\-Xms${SMEM}m/\-Xms${SMEM}m \-Xmx${XMEM}m /;
                    }
                }
                if ($_ !~ m/\-XX\\:MaxGCPauseMillis\\=500/)
                {
                    $BBjServAddOpts .= " \-XX\\:MaxGCPauseMillis\\=500";
                }
                if ($_ !~ m/\-Djxbrowser.ipc.external\\=true/)
                {
                    $BBjServAddOpts .= " \-Djxbrowser.ipc.external\\=true";
                }
                if ($_ !~ m/\-Djxbrowser.browser.type\\=LIGHTWEIGHT/)
                    {
                    $BBjServAddOpts .= " \-Djxbrowser.browser.type\\=LIGHTWEIGHT";
                }
                if ($_ !~ m/\-XX\\:\+UseStringDeduplication/)
                {
                    $BBjServAddOpts .= " \-XX\\:\+UseStringDeduplication";
                }
        
                if ($_ !~ m/\-Xlog.*gc/ && m/BBjServices_gc/ && m/tags,uptime,level/ )
                {
                    $BBjServAddOpts .= " \-Xlog\\:gc*\\:file\\=/usr2/basis/log/BBjServices_gc.log\\:tags,uptime,level\\:filecount\\=10,filesize\\=25m";
                }
        
                if ( $BBjServAddOpts ne "" )
                {
                    $_ =~ s/\-server /\-server $BBjServAddOpts /;
                    $BBjServAddOpts = "";
                }
                $_ =~ s/  */ /g;
            
            }
            # end of BBjServices java args line
        
            $_ =~ s/com.basis.user.useFork\=true/com.basis.user.useFork\=false/g;
        
            if ($_ =~ m/^basis.java.jvm.Default/)
            {
                if ($_ !~ m/\/usr\/java\/latest\/bin\/java/)
                {
                    $_ =~ s/usr\/java\/..*\/bin\/java/usr\/java\/latest\/bin\/java/g;
                }
            }
        
            if ($_ =~ m/^com.basis.jetty.host\=[A-Za-z]/)
            {
                $_ =~ s/com.basis.jetty.host\=..*/com.basis.jetty.host\=${Host_Ip}/;
            }
       
            $_ =~ s/com.basis.server.admin.1.useSSL\=false/com.basis.server.admin.1.useSSL\=true/g;
            $_ =~ s/com.basis.bbj.comm.ProxyManagerServer.start\=false/com.basis.bbj.comm.ProxyManagerServer.start\=true/g;
            $_ =~ s/com.basis.bbj.comm.ThinClientProxyServer.start\=false/com.basis.bbj.comm.ThinClientProxyServer.start\=true/g;
            $_ =~ s/com.basis.bbj.comm.ThinClientServer.start\=false/com.basis.bbj.comm.ThinClientServer.start\=true/g;
            $_ =~ s/basis.java.args.Default\=\-client/basis.java.args.Default\=\-XX\\:MaxPermSize\\=128m \-client/g;
            $_ =~ s/basis.java.args.ProxyMgrServer\=\-client \-XX\\:CompileCommandFile/basis.java.args.ProxyMgrServer\=\-XX\\:MaxPermSize\=128m \-client \-XX\\:CompileCommandFile/g;

            if ($_ =~ /basis.java.classpath/ && "$BBJ_VER" ge "24" )
            {
                # should only be found if converting prev BBj.properties
                # don't include in new file was removed in bbj 19 or 21
                next;
            }

            if ($_ =~ /basis.classpath.test/ )
            {
                next;
            }

            # bbj version is 24 or higher, adjust classpath
            #  classpath now supports * instead of individual jar names
            #  remove jar entries for /usr2/basis/lib, /usr2/bbx/jars/azure,
            #  /usr2/bbx/jars and replace azure dir entry with
            #  azure-messaging-service, add * entry for bbx/jars and
            #  bbx/azure-messaging-service
            if ($_ =~ /basis.classpath.bbj_default/)
            {
                if ( "$BBJ_VER" lt "24" )
                { 
                    if ($_ !~ /\/usr2\/bbx\/jars\/rtitws.jar/ )
                    {
                        $_ =~ s/$/\\:\/usr2\/bbx\/jars\/rtitws.jar/;
                    }
                    if ($_ !~ /\/usr2\/bbx\/jars\/rtienhance.jar/ )
                    {
                        $_ =~ s/$/\\:\/usr2\/bbx\/jars\/rtienhance.jar/;
                    }
                    if ($_ !~ /\/usr2\/bbx\/jars\/mssql-jdbc-11.2.0.jre11.jar/ )
                    {
                        $_ =~ s/$/\\:\/usr2\/bbx\/jars\/mssql-jdbc-11.2.0.jre11.jar/;
                    }
                    if ($_ !~ /\/usr2\/bbx\/jars\/commons-csv-1.9.0.jar/ )
                    {
                        $_ =~ s/$/\\:\/usr2\/bbx\/jars\/commons-csv-1.9.0.jar/;
                    }
                } else {
                    # bbj 24 on allows * instead of individual jars
                    # replace azure folder with azure-messaging-servicebus

                    chomp($_);
                    @classPathEntries = split(/\\:/);
                    $newClassPath = "";

                    foreach $classPathEntries (@classPathEntries)
                    {
                        chomp($classPathEntries);
                        if ( $classPathEntries =~ m^//^ )
                        {
                            $classPathEntries =~ s^//^/^g;
                        }

                        if ( $classPathEntries =~ m^/usr2/basis/lib/^ )
                        {
                            next;
                        }

                        if ( $classPathEntries =~ m^/usr2/bbx/jars/azure/[-._[:alnum:]]+([-._[:alnum:]]*)*\.jar$^ && m^/usr2/bbx/jars/azure/\*^ )
                        {
                            next;
                        }

                        if ( $classPathEntries =~ m^/usr2/bbx/jars/azure/\*^ )
                        {
                            next;
                        }

                        if ( $classPathEntries =~ m^/usr2/bbx/jars/[-._[:alnum:]]+([-._[:alnum:]]*)*\.jar$^ )
                        {
                            next;
                        }

                        if ( "$classPathEntries" ne "" )
                        {
                            # build new classpath line
                            if ( "$newClassPath" eq "" )
                            {
                                $newClassPath = $classPathEntries;
                            } else {
                                $newClassPath = $newClassPath . "\\:" . $classPathEntries;
                            }
                        }

                    };# end of foreach loop

                };# end of check for version < bbj24

                $_ = $newClassPath;

                if ($_ !~ m/\/usr2\/bbx\/jars\/azure-messaging-servicebus\//  )
                {
                    $_ =~ s^\(bbj_internal\)^\(bbj_internal\)\\:/usr2/bbx/jars/azure-messaging-servicebus/\*^;
                }

                if ( $_ !~ m/\/usr2\/bbx\/jars\/\*/ )
                {
                    $_ =~ s^\(bbj_internal\)^\(bbj_internal\)\\:/usr2/bbx/jars/\*^;
                }

                if (-e "/usr2/OSAS/progRM/update.jar" || -d "/usr2/OSAS/progRM/" )
                {
                    if ($_ !~ /\/usr2\/OSAS\/progRM\/update.jar/)
                    {
                        $_ =~ s/$/\\:\/usr2\/OSAS\/progRM\/update.jar/;
                    }
                }
                if (-e "/usr2/OSAS/progRM/barcode4j.jar" || -d "/usr2/OSAS/progRM" )
                {
                    if ($_ !~ /\/usr2\/OSAS\/progRM\/barcode4j.jar/)
                    {
                        $_ =~ s/$/\\:\/usr2\/OSAS\/progRM\/barcode4j.jar/;
                    }
                }
                $_ = $_ . "\n";
            };# end of basis.classpath.bbj_default line processing

            #if ($_ =~ m/basis.classpath.addon=\(addon_internal\)/)
            #{
                #$BasisProp1 = "true";
            #}
            #if ($_ =~ m/basis.classpath.barista=\(barista_internal\)/)
            #{
                #$BasisProp2 = "true";
            #}
            #if ($_ =~ m/basis.classpath.basisdemos=\(basisdemos_internal\)/)
            #{
                #$BasisProp3 = "true";
            #}
            #if ($_ =~ m/basis.classpath.webservices.bus=\(bbj_inside\)\\:\/usr2\/basis\/cache\/webservices\/BUS\/obj\//)
            #{
                #$BasisProp4 = "true";
            #}

            if ($_ =~ m/bbjservices.ulimit.filedescriptors/)
            {
                $FOUND_ULIMIT = "true";
            }
            if ($_ =~ m/com.basis.bbj.console.rmi/)
            {
                $CONSOLE_RMI = "true";
            }
            if ($_ =~ m/basis.java.args.BasisIDE/)
            {
                $BASIS_IDE = "true";
            }
    
            print BBJPROPOUT $_;
        }
    
        #if ($BasisProp1 ne "true")
        #{
            #print BBJPROPOUT "basis.classpath.addon=(addon_internal)\n";
        #}
        #if ($BasisProp2 ne "true")
        #{
            #print BBJPROPOUT "basis.classpath.barista=(barista_internal)\n";
        #}
        #if ($BasisProp3 ne "true")
        #{
            #print BBJPROPOUT "basis.classpath.basisdemos=(basisdemos_internal)\n";
        #}
        #if ($BasisProp4 ne "true")
        #{
            #print BBJPROPOUT "basis.classpath.webservices.bus=(bbj_inside)\\:/usr2/basis/cache/webservices/BUS/obj/\n";
        #}
        if ($FOUND_ULIMIT ne "true")
        {
            print BBJPROPOUT "bbjservices.ulimit.filedescriptors=16384\n";
        }
        #if ($CONSOLE_RMI ne "true")
        #{
        #    print BBJPROPOUT "com.basis.bbj.console.rmi=false\n";
        #}
        if ($BASIS_IDE ne "true")
        {
            print BBJPROPOUT "basis.java.args.BasisIDE=\-XX\\:CompileCommandFile\\=/usr2/basis/cfg/.hotspot_compiler \-XX\\:MaxPermSize\\=160m\n";
        }
        
        close BBJPROP;
        close BBJPROPOUT;
        
        mysystem("cp /usr2/basis/cfg/BBj.properties.tmp /usr2/basis/cfg/BBj.properties.rti");
        mysystem("mv /usr2/basis/cfg/BBj.properties /usr2/basis/cfg/BBj.properties.bak");
        mysystem("mv /usr2/basis/cfg/BBj.properties.tmp /usr2/basis/cfg/BBj.properties");
        mysystem("chmod 644 /usr2/basis/cfg/BBj.properties");


        # after bbj22, font= on pdf print lines prevents it creating the file
        #  so remove the font= setting
        if ( "$ClearConfigFont" eq "true" )
        {
            my $ConfigFontLines = `grep -ic \"font=\\".*\\"\" /usr2/bbx/config/config.bbx 2>/dev/null`;
            if ( $ConfigFontLines > 0 )
            {
                loginfo("Adjusting config.bbx lines with font on them");
                mysystem("cp -p /usr2/bbx/config/config.bbx /usr2/bbx/config/config.bbx.tmpbak");
                open BBJPROP, "</usr2/bbx/config/config.bbx";
                open BBJPROPOUT, ">/usr2/bbx/config/config.new";
                while (<BBJPROP>)
                {
                    if ($_ =~ /[ ,]pdf/i && /font=\".*\"/i && $_ !~ /^#/ )
                    {
                        print BBJPROPOUT "#" . $_;
                        if ( $_ =~ /font=\".*\",/i )
                        {
                            $_ =~ s/font=\".*\",//i;
                        } else {
                            $_ =~ s/,font=\".*\"//i;
                        }
                    }
                    print BBJPROPOUT $_;
                }
                close(BBJPROP);
                close(BBJPROPOUT);
                mysystem("mv /usr2/bbx/config/config.new /usr2/bbx/config/config.bbx");
                mysystem("chmod --reference=/usr2/bbx/config/config.bbx.tmpbak /usr2/bbx/config/config.bbx");
                mysystem("chown --reference=/usr2/bbx/config/config.bbx.tmpbak /usr2/bbx/config/config.bbx");

            }
        }

        loginfo("Checking GC Logrotate setting in bbjservices ...");
        $ReturnVal=mysystem("grep doRotateGCLog\=0 /usr2/basis/bin/bbjservices >/dev/null 2>/dev/null");
        if($ReturnVal != 0)
        {
            open BBJPROP, "</usr2/basis/bin/bbjservices";
            open BBJPROPOUT, ">/usr2/basis/bin/bbjservices.tmp";
            while (<BBJPROP>)
            {
                print BBJPROPOUT $_;
                if ($_ =~ / Start Custom Definitions \(DO NOT REMOVE THIS LINE\) /)
                {
                    print BBJPROPOUT "doRotateGCLog=0\n";
                }
            }
            close BBJPROP;
            close BBJPROPOUT;
    
            loginfo("Disabled doRotateGCLog for bbj, java now does it ");
            mysystem("mv /usr2/basis/bin/bbjservices /usr2/basis/bin/bbjservices.bak");
            mysystem("mv /usr2/basis/bin/bbjservices.tmp /usr2/basis/bin/bbjservices");
            mysystem("chmod 644 /usr2/basis/bin/bbjservices");

        } # end doRotateGCLog change processing

        # Adding /usr2/bbx/bin to the /usr2/basis/bin/.envsetup file 
        $ReturnVal=mysystem ("grep \"/usr2/bbx/bin\"/ /usr2/basis/bin/.envsetup >/dev/null 2>/dev/null");
        if($ReturnVal != 0)
        {
            loginfo("Add /usr2/bbx/bin to the Basis env setup PATH.");
            mysystem("cp -p /usr2/basis/bin/.envsetup /usr2/basis/bin/.envsetup.bak");
            open ENVOLD, "< /usr2/basis/bin/.envsetup.bak";
            open ENVNEW, "> /usr2/basis/bin/.envsetup";
            while(<ENVOLD>)
            {
                my $line = $_;
                if ($line =~ m/^PATH=/)
                {
                    $line = "PATH=\"\$PATH:\${home}/bin:\${home}/.lib:/usr2/bbx/bin/\"\n";
                }
                print ENVNEW $line;
            }
            close ENVNEW;
            close ENVOLD;

            mysystem("chmod 775 /usr2/basis/bin/.envsetup");
        }

        ### ?? not sure if should  skip copy of useraccts.json from bbx/config 
        #loginfo("Backup the basis/cfg copy of useraccts.json and copy RTI's");
        #mysystem("cp -p /usr2/basis/cfg/useraccts.json /usr2/basis/cfg/useraccts.json.installed >/dev/null 2>/dev/null");
        #mysystem("cp -p /usr2/bbx/config/useraccts.json /usr2/basis/cfg/ >/dev/null 2>/dev/null");

        ###   copy the TaskGroups.xml and .run from basis-old/cfg              
        if ( -e "/usr2/basis-old/cfg/TaskGroups.xml" )
        {
            if ( -e "/usr2/basis/cfg/TaskGroups.xml" )
            {
                loginfo("Backup the basis/cfg copy of TaskGroups.xml ");
                mysystem("cp -p /usr2/basis/cfg/TaskGroups.xml /usr2/basis/cfg/TaskGroups.xml.bak >/dev/null 2>/dev/null");
            }
            loginfo("Restore TaskGroups.xml from basis-old ");
            mysystem("cp -p /usr2/basis-old/cfg/TaskGroups.xml /usr2/basis/cfg/TaskGroups.xml >/dev/null 2>/dev/null");

            if ( -e "/usr2/basis/cfg/TaskGroups.run" )
            {
                loginfo("Backup the basis/cfg copy of TaskGroups.run ");
                mysystem("cp -p /usr2/basis/cfg/TaskGroups.run /usr2/basis/cfg/TaskGroups.run.bak >/dev/null 2>/dev/null");
            }
            if ( -e "/usr2/basis-old/cfg/TaskGroups.run" )
            {
                loginfo("Restore TaskGroups.run from basis-old ");
                mysystem("cp -p /usr2/basis-old/cfg/TaskGroups.run /usr2/basis/cfg/TaskGroups.run >/dev/null 2>/dev/null");
            }    
        }

        #mysystem("cp -p /usr2/bbx/config/useraccts.json /usr2/basis/cfg/ >/dev/null 2>/dev/null");
        #if ( "$BLS_Remote" eq "true")
        #{
        #    loginfo("Restoring basis.lic for remote license...");
        #    mysystem("cp -p /usr2/basis/basis.lic /usr2/basis/basis_lic_install");
        #    mysystem("cp -p /usr2/basis-old/basis.lic /usr2/basis/basis.lic");
        #}

        loginfo("Remote license BLS_Remote:$BLS_Remote ");
        if ( "$BLS_Remote" eq "true" )
        {
             if( -e "/tmp/certificate.bls.remote" )
             {
                   if ( -e "/usr2/basis/cfg/certificate.bls" )
                   {
                        mysystem("cp /usr2/basis/cfg/certificate.bls /usr2/basis/cfg/certificate.bls.bak");
                   }
                   mysystem("mv /tmp/certificate.bls.remote /usr2/basis/cfg/certificate.bls.remote");
                   mysystem("cp /usr2/basis/cfg/certificate.bls.remote /usr2/basis/cfg/certificate.bls");
             }
        
             mysystem("cp /usr2/basis/cfg/blsclient.conf /usr2/basis/cfg/blsclient.conf.bak");
             open TMP, "</usr2/basis/cfg/blsclient.conf.bak";
             open TMP2, ">/usr2/basis/cfg/blsclient.conf";
             while (<TMP>)
             {
                  if ( $_ =~ m/localhost/ )
                  {
                       $_ =~ s/localhost/${BLS_Address}/;
                  }
                  print TMP2 $_;
             }
             close(TMP);
             close(TMP2);
        }
        
    loginfo("Removing blm reference from bbj.service files");
    $junk = `grep -i wants.blm.service /etc/systemd/system/bbj.service 2>/dev/null`;
    if ( $junk ne "" )
    {
         mysystem("cp /etc/systemd/system/bbj.service /etc/systemd/system/bbj.service.bak");
         open TMP, "</etc/systemd/system/bbj.service.bak";
         open TMP2, ">/etc/systemd/system/bbj.service";
         while (<TMP>)
         {
              if ( $_ !~ m/wants=blm.service/i )
              {
                  print TMP2 $_;
              }
         }
         close(TMP);
         close(TMP2);
         mysystem("rm -rf /etc/systemd/system/bbj.service.bak");
    }
    $junk =  `grep -i wants.blm.service /usr/lib/systemd/system/bbj.service 2>/dev/null`;
    if ( $junk ne "" )
    {
         mysystem("cp /usr/lib/systemd/system/bbj.service /usr/lib/systemd/system/bbj.service.bak");
         open TMP, "</usr/lib/systemd/system/bbj.service.bak";
         open TMP2, ">/usr/lib/systemd/system/bbj.service";
         while (<TMP>)
         {
              if ( $_ !~ m/wants=blm.service/i )
              {
                  print TMP2 $_;
              }
         }
         close(TMP);
         close(TMP2);
         mysystem("rm -rf /usr/lib/systemd/system/bbj.service.bak");
    }

    if ( "$UpdateRTI_IniVer" eq "true" )
    {
        $StartSection = "";
        $RTIMaj = 0;
        $RTIMin = 0;
        $RTINew = "";

        loginfo("Back up RTI.ini to RTI.ini.bakBBjUpd");
        mysystem("cp -p /usr2/bbx/bbxd/RTI.ini /usr2/bbx/bbxd/RTI.ini.bakBBjUpd");
        open TMP1, "</usr2/bbx/bbxd/RTI.ini.bakBBjUpd";
        open TMP2, ">/usr2/bbx/bbxd/RTI.ini";
        while (<TMP1>)
        {
            loginfo($_);
            if ( $_ =~ /^[Startup]/i )
            {
                $StartSection = "true";
            } else {
                if ( $_ =~ /^[.\*]/ )
                {
                    $StartSection = "false";
                }
            }
        
            if ( "$StartSection" eq "true")
            {
                if ( $_ =~ /^version=/i )
                {
                    loginfo("In RTI.ini, version line found: $_ ");
                    my @RTI_VER = split(/[=.]/, $_ );
                    $RTIMaj = $RTI_VER[1];
                    $RTIMin = $RTI_VER[2];
                    #$RTIMin = $RTIMin + 1;
                    #if ( $RTIMaj == 16 && $RTIMin <= 16 )
                    #{
                    #    $RTIMin = 16;
                    #}
                    #$RTINew = $RTIMaj . "." . $RTIMin;
                    $RTINew = "16.16"; # Fix version to 16.16
                    $_ =~ s/^[Vv][Ee][Rr][Ss][Ii][Oo][Nn]=..*/VERSION=${RTINew}/;
                    loginfo("Adjusting RTI.ini Version Line To $_ ");
                }
                if ( $_ =~ /^patch=/i )
                {
                     loginfo("RTI.ini Patch Line, $_ will be cleared");
                     $_ =~ s/^[Pp][Aa][Tt][Cc][Hh]=..*/PATCH=/;
                }
            }
            print TMP2 $_;
         }
        close TMP1;
        close TMP2;
    }


    if("$BBJ_PROGS" ne "")
    {
        install_spec_progs();
    }

    loginfo("Removing Installation Files........");
    mysystem("rm ${TmpDir}${BBJ_INFOFILE}");
    if ( -e "/usr2/bbx/config/${JRE_X64W}" && -e "${TmpDir}${JRE_X64W}" )
    {
        mysystem("rm ${TmpDir}${JRE_X64W}");
    }
    mysystem("rm -fr ${WorkDir}");
    if (-d "/usr2/tmp/" && "${TmpDir}" eq "/usr2/tmp/" && "$CreatedTmpDir" eq "true")
    {
        mysystem("rm -fr /usr2/tmp/");
    }
    mysystem("rm -rf ${TmpDir}${BBJ_JAR} 2>/dev/null");
    mysystem("rm -rf ${WorkDir}${BBJ_JAR} 2>/dev/null");

    if ( "$removeOldJava" eq "true" )
    {
        my @OldJavas = `ls -1 /usr/java |egrep -v "latest|default|$JDIR_LINK|$JAVA_VER|$JDK_X64"`;
        foreach $javaRmDirJar (@OldJavas)
        {
            chomp($javaRmDirJar);
            loginfo("Removing old /usr/java items: $javaRmDirJar ");
            mysystem ("rm -Rf /usr/java/$javaRmDirJar ");
        }
    }

    # bbj should already be down for copying files into place
    #loginfo("Stopping BBj Services.....");
    #mysystem("$POSDIR/bin/bbjservice.pl --stop");
    #sleep (2);

    if ( "$BLS_Remote" eq "true" && $DemoTrueFalse ne "true")
    {
        loginfo("BLS running on $BLS_Address, stopping locally");
        mysystem("/sbin/service bls stop");
        if ( $ReturnVal != 0 )
        {
            mysystem("/usr2/basis/bls/bin/basislicenseservice stop");
        }
       sleep (2);
    }

    loginfo("Restarting BBj Services.....");
    mysystem("/usr2/basis/bin/bbjservices start");
    sleep (15);

    loginfo("Done with update BBj version.....");

    #loginfo("Skip Starting RTI Programs.....");
    loginfo("Starting RTI Programs.....");
    #mysystem("/sbin/service rti start");
    mysystem("/usr2/bbx/bin/startbbx");
    loginfo("Restart Complete......Finished!");
    }
}

#
#


#### Create temp bbj program to set admin pw and RTI, RTI14 DB entries
sub BBj_Setup_util
{

    my $setPwDB = "SETERR ERRTRAP; SETESC ESCTRAP
REM 3 \$Revision: 1.1 \$
REM 10,1 setPwDB - Change EM password if necessary, add RTI, RTI14 dbs to sql
REM Copyright 2025 Teleflora
REM All Rights Reserved
BEGIN
use com.basis.api.admin.BBjAdminBase
LET LOG_MESS\$=\"Checking for correct EM password, change if necessary \"
GOSUB WRITE_LOG_MESS
LET USER_ID\$=\"admin\",PASSWORD\$=\"admin123\",NEW_PASSWORD\$=\"t3l3fl0ra\"
declare BBjAdminBase admin!
admin!=BBjAPI().getAdmin(USER_ID\$,NEW_PASSWORD\$,ERR=adminNull)
adminNull:
if admin!=null()
  declare BBjAdminBase admin!
  admin!=BBjAPI().getAdmin(USER_ID\$,PASSWORD\$)
  LET LOG_MESS\$=\"Changing Default EM Password \"
  GOSUB WRITE_LOG_MESS
  admin!.changePassword(USER_ID\$,NEW_PASSWORD\$)
fi

LET LOG_MESS\$=\"Adding Users odbc, rti, and tfsupport \"
GOSUB WRITE_LOG_MESS
admin!.addUser(\"odbc\",\"odbc99\",err=*next)
admin!.addUser(\"rti\",\"\",err=*next)
admin!.addUser(\"tfsupport\",\"\",err=*next)

LET LOG_MESS\$=\"Adding RTI and RTI14 Databases for SQL \"
GOSUB WRITE_LOG_MESS
SQLOPEN(1, mode=\"user=\"+USER_ID\$+\",password=\"+NEW_PASSWORD\$)\"BBJSYS\"
SQLPREP(1)\"create database 'RTI' '/usr2/bbx/bbxd/' '/usr2/bbx/odbc_dict/'\"
SQLEXEC(1,ERR=*next)
SQLPREP(1)\"create database 'RTI14' '/usr2/bbx/bbxd/' '/usr2/bbx/dict/'\"
SQLEXEC(1,ERR=*next)
SQLCLOSE(1)

GOTO EXIT_PGM
STOP

ESCTRAP:
ESCAPE

ERRTRAP:
EXIT_ERROR=ERR
LOG_MESS\$=\"An error \"+STR(EXIT_ERROR)+\" occurred in program <\"+PGM(-2)+\"> at line \"+STR(TCB(5))
GOSUB WRITE_LOG_MESS
GOTO ERROR_EXIT_PGM

WRITE_LOG_MESS: REM 20000,5
DATE_FILE_NAME\$=DATE(0:\"%Hz:%mz:%sz\")
REM A=SCALL(\"echo \"\"\"+DATE_FILE_NAME\$+\" \"+LOG_MESS\$+\"\"\"\")
PRINT DATE_FILE_NAME\$+\" \"+LOG_MESS\$; REM screen appended to patchLog
RETURN

EXIT_PGM: REM 63000,5
REM GOSUB CLOSE_FILES
DONE_WITH_EXIT_PGM: REM 65000,5
RELEASE

ERROR_EXIT_PGM:
RELEASE EXIT_ERROR
REM 65533,1

END
";
    open(BBJDTA, "> ${TmpDir}setPwDB");
    print BBJDTA $setPwDB;
    close(BBJDTA);


    my $deployRTI = "SETERR ERRTRAP; SETESC ESCTRAP
REM 3 \$Revision: 1.1 \$
REM 10,1 deployRTI - Create DesktopApp with BBjAdminAppDeployment methods

REM Copyright 2025 Teleflora
REM All Rights Reserved

BEGIN

use com.basis.api.admin.BBjAdminBase
use com.basis.api.admin.BBjAdminFactory
use com.basis.api.admin.BBjAdminAppDeploymentConfiguration
use com.basis.api.admin.BBjAdminAppDeploymentApplication
use com.basis.api.admin.BBjAdminAppDeploymentResource
use com.basis.api.admin.BBjAdminJRE
use com.basis.api.admin.BBjAdminList
use java.net.InetAddress

PRE_INIT: REM 50,5

PROGRAM_INIT: REM 300,5

MAIN_PROCESS: REM 1000,5

rem -- Issue 8619: Change Host Name for GUI Desktop App
INSTALL_DESKTOP_APP:
LET LOG_MESS\$=\"Install GUI Desktop App \"
GOSUB WRITE_LOG_MESS

declare InetAddress adminHost!
declare BBjNumber adminPort!
declare boolean adminUseSSL!
declare BBjNumber adminTimeOut!
declare BBjString adminUser!
declare BBjString adminPwd!
declare BBjString jreName!
declare BBjString jrePath!
declare BBjString appPng!
declare BBjString appName!
declare BBjString appProgram!
declare BBjString appBBxConfig!
declare BBjString appWorkingDirectory!
declare BBjString appUser!
declare BBjString appHostOverride!
declare BBjString appShortcutName!
declare BBjString appShortcutDesc!
declare boolean appQuiet!
declare boolean appBUIEnabled!
declare boolean appDWCEnabled!
declare boolean appEXEEnabled!
declare boolean appStdAloneJVM!
declare BBjString appInf!
declare BBjString appTerminal!
declare boolean appSecureUseDefault!
declare boolean appSecureTcc!
declare BBjString bbjver!
declare boolean appDisplayLoadImage!
declare boolean appDisplayLoadText!
declare boolean appDisplayRunMessage!


bbjver!=rev(5)
adminHost!=InetAddress.getLocalHost()
adminUser!=\"admin\"
adminPort!=2002
adminUseSSL!=BBjAPI.TRUE
adminTimeOut!=5000
adminPwd!=\"t3l3fl0ra\"
jreName!=\"${JRE_X64W}\"
jrePath!=\"/usr2/bbx/config/\"+jreName!
appPng!=\"/usr2/bbx/images/rti.png\"
appName!=\"RTI\"
appProgram!=\"/usr2/bbx/gui/mdi_login.gui\"
appBBxConfig!=\"/usr2/bbx/config/config.bbx\"
appWorkingDirectory!=\"/usr2/bbx/\"
appUser!=\"rti\"
appHostOverride!=InetAddress.getLocalHost().getHostAddress()
appShortcutName!=\"RTI_GUI\"
appShortcutDesc!=\"RTI Graphical Menu\"
appQuiet!=BBjAPI.TRUE
appBUIEnabled!=BBjAPI.FALSE
appDWCEnabled!=BBjAPI.FALSE
appEXEEnabled!=BBjAPI.TRUE
appStdAloneJVM!=BBjAPI.TRUE
appInf!=\"rti\"; rem was replaced by the StandAlone_JVM setting in bbj24
appTerminal!=\"T400\"
appSecureUseDefault!=BBjAPI.FALSE
appSecureTcc!=BBjAPI.TRUE
appDisplayLoadImage!=BBjAPI.FALSE
appDisplayLoadText!=BBjAPI.FALSE
appDisplayRunText!=BBjAPI.FALSE


rem Get Admin Instance
declare BBjAdminBase admin!
admin! = BBjAdminFactory.getBBjAdmin(adminHost!, adminPort!, adminUseSSL!, adminTimeOut! ,adminUser!, adminPwd!)
rem admin! = BBjAdminFactory.getBBjAdmin(adminUser!, adminPwd!)

rem Add a JRE for Application
rem Windows 64 bit only
admin!.getWebAppServer().addJRE(jrePath!, BBjAdminJRE.OS_WINDOWS)
admin!.commit(err=*next);rem Errors if JRE already exists

rem Get Deployment Config
declare BBjAdminAppDeploymentConfiguration config!
config! = admin!.getRemoteConfiguration()
config!.removeApplication(appName!);rem Remove Existing Application Entry
config!.commit(err=*next);rem Errors if Application doesn't exist

rem Create a resource entry for a shortcut icon
declare BBjAdminAppDeploymentResource resource!
resource! = config!.createResource()
resource!.setString(BBjAdminAppDeploymentResource.SOURCE_FILE_NAME, appPng!)
config!.getResources().add(resource!)
config!.commit(err=*next);rem Errors if resource exists.

REM Create the application
declare BBjAdminAppDeploymentApplication app!
app! = config!.createApplication()
app!.setString(BBjAdminAppDeploymentApplication.NAME, appName!)
app!.setString(BBjAdminAppDeploymentApplication.PROGRAM, appProgram!)
app!.setString(BBjAdminAppDeploymentApplication.CONFIG_FILE, appBBxConfig!)
app!.setString(BBjAdminAppDeploymentApplication.WORKING_DIRECTORY, appWorkingDirectory!)
app!.setString(BBjAdminAppDeploymentApplication.INTERPRETER_USER, appUser!)
app!.setString(BBjAdminAppDeploymentApplication.HOST_OVERRIDE, appHostOverride!)
app!.setString(BBjAdminAppDeploymentApplication.SHORTCUT_NAME, appShortcutName!)
app!.setString(BBjAdminAppDeploymentApplication.SHORTCUT_DESCRIPTION, appShortcutDesc!)
app!.setBoolean(BBjAdminAppDeploymentApplication.QUIET, appQuiet!)
app!.setBoolean(BBjAdminAppDeploymentApplication.BUI_ENABLED, appBUIEnabled!)
app!.setBoolean(BBjAdminAppDeploymentApplication.DWC_ENABLED, appDWCEnabled!)
app!.setBoolean(BBjAdminAppDeploymentApplication.EXE_ENABLED, appEXEEnabled!)
app!.setString(BBjAdminAppDeploymentApplication.DESKTOP_TERMINAL, appTerminal!)
app!.setBoolean(BBjAdminAppDeploymentApplication.SECURE_DESKTOP_USE_DEFAULT, appSecureUseDefault!)
app!.setBoolean(BBjAdminAppDeploymentApplication.SECURE_DESKTOP, appSecureTcc!)
app!.setString(BBjAdminAppDeploymentApplication.WINDOWS_JVM, jreName!)
if bbjver! < \"24\" 
    app!.setString(BBjAdminAppDeploymentApplication.INF, appInf!)
else
    app!.setBoolean(BBjAdminAppDeploymentApplication.STANDALONE_JVM, appStdAloneJVM!)
fi
app!.setString(BBjAdminAppDeploymentApplication.SHORTCUT_ICON_RESOURCE_ID, resource!.getString(BBjAdminAppDeploymentResource.RESOURCE_ID))
app!.setBoolean(BBjAdminAppDeploymentApplication.DISPLAY_LOAD_IMAGE, appDisplayLoadImage!)
app!.setBoolean(BBjAdminAppDeploymentApplication.DISPLAY_LOAD_TEXT, appDisplayLoadText!)
app!.setBoolean(BBjAdminAppDeploymentApplication.DISPLAY_RUN_MESSAGE, appDisplayRunText!)

app!.commit(err=INSTALL_DESKTOP_APP_ERR)
goto DONE_WITH_DESKTOPAPP
INSTALL_DESKTOP_APP_ERR:  
LET LOG_MESS\$=\"GUI Desktop App Installation Failed (\"+errmes(-1)+\") \"
GOSUB WRITE_LOG_MESS


DONE_WITH_DESKTOPAPP: REM 10000

GOTO EXIT_PGM

WRITE_LOG_MESS: REM 20000,5
DATE_FILE_NAME\$=DATE(0:\"%Hz:%mz:%sz\")
REM A=SCALL(\"echo \"\"\"+DATE_FILE_NAME\$+\" \"+LOG_MESS\$+\"\"\"\")
PRINT DATE_FILE_NAME\$+\" \"+LOG_MESS\$; REM screen appended to patchLog
RETURN

STANDARD_FUNCTION_LIBRARY: REM 40000,5

DEF FNGET_ENV\$(ENV_VAR\$)
INFO_CNT=0,ENV_RTN\$=\"\"
IF POS(\"=\"=ENV_VAR\$)<>LEN(ENV_VAR\$) THEN ENV_VAR\$=CVS(ENV_VAR\$,3)+\"=\"
NEXT_ENV_CHECK:
WHILE INFO_CNT>=0
    INFO_CNT=INFO_CNT+1
    ENV_STR\$=INFO(4,INFO_CNT,ERR=EXIT_GET_ENV)
    SWITCH (POS(ENV_VAR\$=ENV_STR\$)=1)
    CASE 1; REM \"Found it
        ENV_RTN\$=ENV_STR\$(POS(\"=\"=ENV_STR\$)+1)
        INFO_CNT=-1
        BREAK
    CASE DEFAULT; REM \"Not found
        BREAK
    SWEND
    CONTINUE
    EXIT_GET_ENV:
    INFO_CNT=-1
WEND
DONE_WITH_GET_ENV:
RETURN ENV_RTN\$
FNEND

STANDARD_ROUTINE_LIBRARY: REM 50000,5 \"50000-65000

ESCTRAP:
ESCAPE

ERRTRAP:
EXIT_ERROR=ERR
LOG_MESS\$=\"An error \"+STR(EXIT_ERROR)+\" occurred in program <\"+PGM(-2)+\"> at line \"+STR(TCB(5))
GOSUB WRITE_LOG_MESS
GOTO ERROR_EXIT_PGM

CLOSE_FILES: REM 60000,5
CURRENT_CHANNELS\$=CHN
CHANNEL_COUNT=0
WHILE CHANNEL_COUNT<INT(LEN(CURRENT_CHANNELS\$)/2)
    CHANNEL_COUNT=CHANNEL_COUNT+1
    CHANNEL_NUMBER=DEC(CURRENT_CHANNELS\$(CHANNEL_COUNT*2-1,2))
    IF !(POS(BIN(CHANNEL_NUMBER,2)=ORIGINAL_CHANNELS\$,2)) THEN CLOSE (CHANNEL_NUMBER,ERR=*NEXT)
WEND
DONE_WITH_CLOSE_FILES:
RETURN

EXIT_PGM: REM 63000,5
GOSUB CLOSE_FILES
DONE_WITH_EXIT_PGM: REM 65000,5
RELEASE

ERROR_EXIT_PGM:
RELEASE EXIT_ERROR
REM 65533,1
END
";
    open(BBJDTA, "> ${TmpDir}deployRTI");
    print BBJDTA $deployRTI;
    close(BBJDTA);

}

sub BBj_Setup_run
{
    loginfo("See if bls is running ");
    mysystem("ps -ef |grep -i bls |grep -v grep ");
    loginfo("Wait 10 seconds to make sure License server is responding ");
    sleep (10);
    mysystem("BBTERM=IO; export BBTERM; /usr2/basis/bin/bbj -c/usr2/bbx/config/config.bbx ${TmpDir}setPwDB 2>&1 >> $POSDIR/log/gui_deploy.log");
    if ( $ReturnVal == 0 )
    {
        loginfo("BBj Set Up Program Indicates Successful Completion ");
    }

    sleep (5);
    mysystem("BBTERM=IO; export BBTERM; /usr2/basis/bin/bbj -c/usr2/bbx/config/config.bbx ${TmpDir}deployRTI 2>&1 >> $POSDIR/log/gui_deploy.log");
    if ( $ReturnVal == 0 )
    {
        loginfo("BBj GUI App Program Indicates Successful Completion ");
    }
    sleep (5);

    mysystem("rm ${TmpDir}setPwDB");
    mysystem("rm ${TmpDir}deployRTI");
}

#### Install Java
#
#

sub get_and_load_java
{
    my ($java_file) = @_;

    my $java_no_gz_test = $java_file;
    chomp $java_no_gz_test;
    my @java_no_gz=split('.gz', $java_no_gz_test);
    my $java_no_gz=$java_no_gz[$#java_no_gz];

    loginfo("Installing Java...");
    mysystem("cd /usr/java/ && tar -xzf ${TmpDir}$java_file");
    if($ReturnVal != 0)
    {
        logerror("Terminating update_bbj with return code $ReturnVal.");
        exit($ReturnVal);
    }

    mysystem("cd /usr/java/ && rm -r latest");
    mysystem("cd /usr/java/ && ln -s " . $JDIR_LINK . " latest");
    #mysystem("if [ ! -h /usr/bin/java ]; then ln -s /usr/java/latest/bin/java /usr/bin/java; fi");
    if ($ReturnVal != 0)
    {
        logerror("Java install returned non-zero exitstatus: $ReturnVal.");
        exit($ReturnVal);
    }

    # Normally, clean up is a "good thing", but looks like the convention
    # for this script is to leave the Java download file.
    #loginfo("Cleaning Up...");
    
    if (-d "/usr2/tmp/" && "${TmpDir}" eq "/usr2/tmp/")
    {
        open(PIPE, "df -Pm /usr/java|");
        while(<PIPE>)
        {
            if ($_ !~ /^Filesystem/)
            {
                my @DF = split(' ', $_ );
                $AVAILFS = $DF[3];
            }
        }
        close(PIPE);

        open(PIPE,"du -m ${TmpDir}$java_file|");
        while(<PIPE>)
        {
            my @DF = split(' ', $_ );
            $DU_JAVA = $DF[0];
        }

        if ( $AVAILFS > ( $DU_JAVA * 10 ) )
        {
            mysystem("mv $JDK_X64 /usr/java");
        }

        #mysystem("rm -f ${TmpDir}$java_file 2>/dev/null");
    
    }

}


sub install_java
{
    if("$ARCH" eq "x86")
    {
        get_and_load_java($JDK_X86);
    } else {
        get_and_load_java($JDK_X64);
    }
}

sub install_spec_progs
{ 
    #mysystem("wget --proxy=off --cache=off --progress=dot:mega -o ${TmpDir}$BBJ_PROGS $Url/$BBJ_PROGS");
    # if needed, already retrieved to $TmpDir
    my $file = "";
    my $filename = "";
    my @filenm = ();

    if (-e "${TmpDir}$BBJ_PROGS")
    {
        open(PIPE, "tar -tzf ${TmpDir}$BBJ_PROGS |");
        while(<PIPE>)
        {
            $file = $_;
            chomp $file;
            @filenm = split('\/', $file);
            $filename = $filenm[1];
            if ( -e "$POSDIR/$file" )
            {
                loginfo("Copying $filename to backups");
                mysystem("cp -pr $POSDIR/$file $POSDIR/backups/$filename" . "." . $TimeStamp);
            }
            loginfo("Placing $file ");
            mysystem("tar -C $POSDIR -xzf ${TmpDir}$BBJ_PROGS $file");
            mysystem("chown tfsupport:rtiadmins $POSDIR/$file 2>/dev/null");
            mysystem("chmod 555 $POSDIR/$file 2>/dev/null");
        }

        mysystem("rm -rf ${TmpDir}$BBJ_PROGS");
    }
    loginfo("Done with special programs install ");

}

#
#
#### Loginfo  & logerror routines
#
#
sub loginfo
{
    my $message = $_[0];
    my $logtime = strftime("%Y-%m-%d %H:%M:%S", localtime());

    chomp($message);
    open LOGFILE, ">> $POSDIR/log/RTI-Patches.log";
    print LOGFILE "$logtime ($0-$$) <I> $message\r\n";
    close LOGFILE;

    return "";
}


sub logerror
{
    my $message = $_[0];
    my $logtime = strftime("%Y-%m-%d %H:%M:%S", localtime());

    chomp($message);
    open LOGFILE, ">> $POSDIR/log/RTI-Patches.log";
    print LOGFILE "$logtime ($0-$$) <E> $message\r\n";
    close LOGFILE;

    return "";
}

#
# Subroutine to run system commands.  This logs an entry.
#
sub mysystem
{
    my $command = $_[0];
    my $LOG_FILE = "$POSDIR/log/RTI-Patches.log";

    system($command . ">> $LOG_FILE 2>> $LOG_FILE");
    if ($altReturnCode == 1)
    {
        $ReturnVal = ($? >> 8);
    } else {
        $ReturnVal = WEXITSTATUS($?);
    }

    loginfo($command . " Returned $ReturnVal");

    return ($ReturnVal)
}

sub getInfoFileAndRetrieve
{

# first wget file for version with bbjxx .tar, .jar, OpenJDK .tar, .tar.gz,
# .zip file sizes and checksums    bbjXX_infofile.txt or similar
# bbj24_infofile.txt    files to download
# bbj24_update.tar      if BBj...jar needs any other files included
#  size is mainly from BBj...jar  compress won't do much, so it stays as tar
# BBj2421_01-24-2025_0949.jar
# OpenJDK21U-jdk_x64_linux_hotspot_21.0.6_7.tar.gz
#    windows should/can be jre instead of jdk
# OpenJDK21U-jre_x64_windows_hotspot_21.0.6_7.zip
# BBjODBCxx_MM-DD-YYYY_hhmm.jar  xx is latest version up to but not exceeding 
#     the bbj version being installed  
#   
# checksum notes:
# on windows type  certutil -hashfile filename SHA256
# on Linux type    sha256sum filename
#   
# places to check for files already downloaded: 
#     ${TmpDir} (/tmp or /usr2/tmp)  $WorkDir (/usr2/install_bbj)
#    only checing ${TmpDir} for now
    
    $BBJ_INFOFILE = "bbj" . $BBJ_VER . "_infofile.txt";

    $altReturnCode = 1;
    loginfo("Retrieving $BBJ_INFOFILE to ${TmpDir}$BBJ_INFOFILE ");
    mysystem("wget --proxy=off --cache=off --progress=dot:mega -O ${TmpDir}$BBJ_INFOFILE $Url/$BBJ_INFOFILE");
    mysystem("cd ${TmpDir}; curl -Ls ${Url}/${BBJ_INFOFILE}.sha256.txt |sha256sum -c --status");

    if ( $ReturnVal == 0 )
    {
        loginfo("Download of $BBJ_INFOFILE success\n");
    } else {
        logerror("Download of $BBJ_INFOFILE failed - exiting\n");
        exit 4;
    }

##  after reading filenames from infofile, can retrieve with wget or curl
###    there will also be a filename.sha256.txt file to compare and validate
###    file download was complete and correct

    open (INFO, "< ${TmpDir}${BBJ_INFOFILE}");
    while (<INFO>)
    {

        if ($_ =~ /bbj${BBJ_VER}update.tar.gz$/)
        {
             $BBJ_TAR = $_;
             chomp $BBJ_TAR;
        }

        if ($_ =~ /bbj${BBJ_VER}update.tar$/ && $_ !~ /bbj${BBJ_VER}update.tar.gz$/ )
        {
             $BBJ_TAR = $_;
             chomp $BBJ_TAR;
        }

        if ($_ =~ /BBj${BBJ_VER}SpecProgs.tar.gz$/ || $_ =~ /BBj${BBJ_VER}SpecProgs.tgz$/ )
        {
             $BBJ_PROGS = $_;
             chomp $BBJ_PROGS;
        }

        if ($_ =~ /BBj${BBJ_VER}..*\.jar$/ || $_ =~ /BBjBaristaDemos..*\.jar/ || $_ =~ /BBjBaristaAddonDemos..*\.jar/ )
        {
             $BBJ_JAR = $_;
             chomp $BBJ_JAR;
             if ($BBJ_JAR =~ /Demos/ )
             {
                 $TMP1 = index ($BBJ_JAR, 'Demos');
                 if ($TMP1 != 0)
                 {
                     $TMP1=$TMP1 + 5;
                     $BBJ_VER = substr $BBJ_JAR, $TMP1, 2;
                     $BBJ_REV = substr $BBJ_JAR, $TMP1+2, 2;
                     $BBJ_REV = $BBJ_VER . "." . $BBJ_REV;
                 }
             }

             if ($BBJ_JAR !~ /Demos/ )
             {
                     $BBJ_VER = substr $BBJ_JAR, 3, 2;
                     $BBJ_REV = substr $BBJ_JAR, 5, 2;
                     $BBJ_REV = $BBJ_VER . "." . $BBJ_REV;
             }

             $BBJ_InstallFile = $BBJ_JAR;
        }

        if ($_ =~ /openjdk..*linux_hotspot..*tar.gz/i)
        {
             $JDK_X64 = $_;
             chomp $JDK_X64;
             $TMP1 = index ($JDK_X64, 'hotspot_');
             $TMP2 = index ($JDK_X64, '.tar');
             if ($TMP1 != 0 && $TMP2 > $TMP1)
             {
                 $TMP1=$TMP1 + 8;
                 $JAVA_VER = substr $JDK_X64, $TMP1, $TMP2-$TMP1;
             }
             $TMP1 = index($JDK_X64, 'JDK');
             if ($TMP1 > 1)
             {
                 $TMP1 += 3;
             }
             $TMP2 = index($JDK_X64, '-');
             $JAVA_REL = substr $JDK_X64, $TMP1, $TMP2-$TMP1;
             $JDIR_LINK = $JAVA_VER;
             $JDIR_LINK =~ s/_/\+/g;
             $JDIR_LINK = "jdk-" . $JDIR_LINK;
        }
        if ($_ =~ /openjdk..*windows_hotspot..*.zip/i)
        {
             $JRE_X64W = $_;
             chomp $JRE_X64W;
             # windows java should be same version as linux, so don't parse it
        }
        if ($_ =~ /openjdk..*windows_hotspot..*.msi/i || $_ =~ /microsoft-jdk..*windows..*.msi/i )
        {
             $JRE_X64WMSI = $_;
             chomp $JRE_X64WMSI;
        }
        if ($_ =~ /BBjODBC..*jar/ )
        {
            $ODBC_JAR = $_;
            chomp $ODBC_JAR;
        }
    }
    close(INFO);

    @JAVA_CURR = split( /[+._-]/, $JavaInstalled);
    @JAVA_NEED = split( /[+._-]/, $JAVA_VER );

    $higherVerInst = 1;
    my $loopCt = 0;
    for ($loopCt = 0; $loopCt <=3 ; $loopCt++)
    {
        if ( $JAVA_CURR[$loopCt] < $JAVA_NEED[$loopCt] )
        {
            $higherVerInst = 0;
            last;
        }
    }

    loginfo("Java Version Installed: $JavaInstalled ");
    loginfo("Java Version Needed - JAVA_VER $JAVA_VER ");

    if ($higherVerInst != 0)
    {
       loginfo ("Higher Version of java already installed, skipping ");
    } else {
       loginfo ("Need to install higher version of java ");
    }

    loginfo("java install file JDK_X64: $JDK_X64 ");
    loginfo("java release JAVA_REL: $JAVA_REL ");
    loginfo("java windows install file JRE_X64W: $JRE_X64W ");
    loginfo("Link JDIR_LINK: $JDIR_LINK ");
    loginfo("BBj Major version BBJ_VER: $BBJ_VER ");
    loginfo("BBj complete version BBJ_REV: $BBJ_REV ");
    loginfo("BBj install tar file BBJ_TAR: $BBJ_TAR ");
    loginfo("BBj install jar file BBJ_InstallFile $BBJ_InstallFile ");
    loginfo("BBj special prog file for version $BBJ_VER BBJ_PROGS $BBJ_PROGS ");
    if ( $ODBC_JAR ne "" )
    {
        loginfo("ODBC Jar included: $ODBC_JAR");
    } else {
        loginfo("No ODBC Jar included");
    }
    if ( $JRE_X64WMSI ne "" )
    {
        loginfo("JRE MSI Installer included: $JRE_X64WMSI");
    } else {
        loginfo("No JRE MSI File included");
    }

    if ($BBJ_TAR ne "" )
    {
        loginfo("Checking if $BBJ_TAR already present ");
        if ( -e "${TmpDir}${BBJ_TAR}" )
        {
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${BBJ_TAR}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("$BBJ_TAR is present and complete\n");
            }
        } else {
            loginfo("Retrieving $BBJ_TAR to ${TmpDir}$BBJ_TAR ");
            mysystem("wget --proxy=off --cache=off --progress=dot:mega -O ${TmpDir}$BBJ_TAR $Url/$BBJ_TAR");
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${BBJ_TAR}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("Download of $BBJ_TAR success\n");
            } else {
                logerror("Download of $BBJ_TAR failed - exiting\n");
                exit 4;
            }
        }
    }

    if ($BBJ_JAR ne "")
    {
        loginfo("Checking if $BBJ_JAR already present ");
        if ( -e "${TmpDir}${BBJ_JAR}" )
        {
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${BBJ_JAR}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("$BBJ_JAR is present and complete\n");
            }
        } else {
            loginfo("Retrieving $BBJ_JAR to ${TmpDir}$BBJ_JAR ");
            mysystem("wget --proxy=off --cache=off --progress=dot:mega -O ${TmpDir}$BBJ_JAR $Url/$BBJ_JAR");
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${BBJ_JAR}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("Download of $BBJ_JAR success\n");
            } else {
                logerror("Download of $BBJ_JAR failed - exiting\n");
                exit 4;
            }
        }
    }

    if ($BBJ_PROGS ne "" )
    {
        loginfo("Checking if $BBJ_PROGS already present ");
        if ( -e "${TmpDir}${BBJ_PROGS}" )
        {
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${BBJ_PROGS}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("$BBJ_PROGS is present and complete\n");
            }
        } else {
            loginfo("Retrieving $BBJ_PROGS to ${TmpDir}$BBJ_PROGS ");
            mysystem("wget --proxy=off --cache=off --progress=dot:mega -O ${TmpDir}$BBJ_PROGS $Url/$BBJ_PROGS");
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${BBJ_PROGS}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("Download of $BBJ_PROGS success\n");
            } else {
                logerror("Download of $BBJ_PROGS failed - exiting\n");
                exit 4;
            }
        }
    }

    if ($JDK_X64 ne "" && $higherVerInst == 0)
    {
        loginfo("Checking if $JDK_X64 already present ");
        if ( -e "${TmpDir}${JDK_X64}" )
        {
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${JDK_X64}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("$JDK_X64 is present and complete\n");
            }
        } else {
            loginfo("Retrieving $JDK_X64 to ${TmpDir}$JDK_X64 ");
            mysystem("wget --proxy=off --cache=off --progress=dot:mega -O ${TmpDir}$JDK_X64 $Url/$JDK_X64");
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${JDK_X64}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("Download of $JDK_X64 success\n");
            } else {
                logerror("Download of $JDK_X64 failed - exiting\n");
                exit 4;
            }
        }
    }
 
    if ( $ODBC_JAR ne "" || $JRE_X64WMSI ne "" )
    {
        if ( ! -d "/usr2/bbx/odbc_dict/odbc_install" )
        {
            loginfo("Creating odbc_install directory");
            mysystem("mkdir /usr2/bbx/odbc_dict/odbc_install");
        }
    }

    $java_win = $JRE_X64W;
    if ($JRE_X64W ne "" && ! -e "/usr2/bbx/config/$JRE_X64W" )
    {
        loginfo("Checking if $JRE_X64W already present ");
        if ( -e "${TmpDir}${JRE_X64W}" )
        {
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${JRE_X64W}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("$JRE_X64W is present and complete\n");
            }
        } else {
            loginfo("Retrieving $JRE_X64W to ${TmpDir}$JRE_X64W ");
            mysystem("wget --proxy=off --cache=off --progress=dot:mega -O ${TmpDir}$JRE_X64W $Url/$JRE_X64W");
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${JRE_X64W}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("Download of $JRE_X64W success\n");
            } else {
                logerror("Download of $JRE_X64W failed - exiting\n");
                exit 4;
            }
        }
        if ( $java_win ne "" && ! -e "/usr2/bbx/config/$java_win" )
        {
                loginfo("Moving Windows JRE needed for App Deployment....");
                mysystem("mv ${TmpDir}${JRE_X64W} /usr2/bbx/config/");
        }

    }

    if ($ODBC_JAR ne "" )
    {
        loginfo("Checking if $ODBC_JAR already present ");
        if ( -e "${TmpDir}${ODBC_JAR}" )
        {
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${ODBC_JAR}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("$ODBC_JAR is present and complete\n");
            }
        } else {
            loginfo("Retrieving $ODBC_JAR to ${TmpDir}$ODBC_JAR ");
            mysystem("wget --proxy=off --cache=off --progress=dot:mega -O ${TmpDir}$ODBC_JAR $Url/$ODBC_JAR");
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${ODBC_JAR}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("Download of $ODBC_JAR success\n");
            } else {
                logerror("Download of $ODBC_JAR failed - exiting\n");
                exit 4;
            }
        }
        if ( ! -e "/usr2/bbx/odbc_dict/odbc_install/$ODBC_JAR" )
        {
                loginfo("Moving Windows ODBC Drivers to odbc_install direcory");
                mysystem("mv ${TmpDir}${ODBC_JAR} /usr2/bbx/odbc_dict/odbc_install/");
        }

    }

    if ($JRE_X64WMSI ne "" )
    {
        loginfo("Checking if $JRE_X64WMSI already present ");
        if ( -e "${TmpDir}${JRE_X64WMSI}" )
        {
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${JRE_X64WMSI}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("$JRE_X64WMSI is present and complete\n");
            }
        } else {
            loginfo("Retrieving $JRE_X64WMSI to ${TmpDir}$JRE_X64WMSI ");
            mysystem("wget --proxy=off --cache=off --progress=dot:mega -O ${TmpDir}$JRE_X64WMSI $Url/$JRE_X64WMSI");
            mysystem("cd ${TmpDir}; curl -Ls ${Url}/${JRE_X64WMSI}.sha256.txt |sha256sum -c --status");
            if ( $ReturnVal == 0 )
            {
                loginfo("Download of $JRE_X64WMSI success\n");
            } else {
                logerror("Download of $JRE_X64WMSI failed - exiting\n");
                exit 4;
            }
        }
        if ( ! -e "/usr2/bbx/odbc_dict/odbc_install/$JRE_X64WMSI" )
        {
                loginfo("Moving Windows MSI Installer to odbc_install direcory");
                mysystem("mv ${TmpDir}${JRE_X64WMSI} /usr2/bbx/odbc_dict/odbc_install/");
        }

    }

    $altReturnCode = 0;
    return "";
}
