#!/bin/bash

#DESC Installs RTI 16.15.4 and all deps.

cd /tmp
[ ! -f /tmp/RTI-16.18.5-Linux.iso ] && wget -q http://rhel8repo.centralus.cloudapp.azure.com/support/RTI-16.18.5-Linux.iso.gz
#[ ! -f /tmp/multiserver.pwd ] && wget -q http://rtihardware.homelinux.com/t1800/multiserver.pwd
[ ! -f /tmp/update_bbj_25.pl ] && wget -q http://rhel8repo.centralus.cloudapp.azure.com/ostools-1.17/rh9/update_bbj_25.pl && chmod +x /tmp/update_bbj_25.pl
[ ! -f /tmp/tfsupport-authorized_keys ] && wget -q http://rtihardware.homelinux.com/t1800/tfsupport-authorized_keys
[ ! -f /tmp/twofactor-20090723.tar ] && wget -q http://rtihardware.homelinux.com/t1800/twofactor-20090723.tar
[ ! -f /etc/profile.d/term.sh ] && echo "unicode_stop" >/etc/profile.d/term.sh && chmod +x /etc/profile.d/term.sh

echo "Installing bbj...."
./update_bbj_25.pl --java --bbj25

echo "Adding multiserver.pwd fix....."
cp -f /tmp/multiserver.pwd /usr2/bbx/config/

echo "Installing RTI...."
[ ! -f ./RTI-16.18.5-Linux.iso ] && gunzip xvfz ./RTI-16.18.5-Linux.iso.gz
mount -o loop /tmp/RTI-16.18.5-Linux.iso /mnt
cd /mnt
./install_rti-16.18.5.pl --nobbxt /usr2/bbx
cd /tmp
umount /mnt

/usr2/ostools/bin/rtiuser.pl --update tfsupport
/usr2/ostools/bin/rtiuser.pl --update rti
/usr2/ostools/bin/rtiuser.pl --update odbc

echo "Installing tfsupport authorized keys...."
[ ! -d /home/tfsupport/.ssh ] && mkdir /home/tfsupport/.ssh
chmod 700 /home/tfsupport/.ssh
chown tfsupport:rti /home/tfsupport/.ssh
tar xvf /tmp/twofactor-20090723.tar
cp /tmp/tfsupport-authorized_keys /home/tfsupport/.ssh/authorized_keys
chmod 700 /home/tfsupport/.ssh/authorized_keys
chown tfsupport:root /home/tfsupport/.ssh/authorized_keys

echo "Creating term.sh...."
if [[ ! -e /etc/profile.d/term.sh ]]; then
cat << xxxEOFxxx > /etc/profile.d/term.sh
unicode_stop
xxxEOFxxx
fi

exit $?
