#!/bin/bash

#DESC Enable RTI Real time. (had to be  disabled by realtime_disable)

# check to see if disabled.
[ -f /usr2/bbx/config/.rton ] && echo "Real time already enabled." && exit 1
[ ! -f /usr2/bbx/config/.rtoff ] && echo "Real time not disabled by this process." && exit 2

# uncomment out jobs.
sed -i 's/^#//g' /usr2/bbx/config/rtiBackgr

# uncomment out cron jobs.
for file in `ls /etc/cron.d`
do 
sed -i 's/^#//g' /etc/cron.d/$file
done

# uncommenting out any jobs in users crontab.
for file in `ls /var/spool/cron`
do
[ "$file" != "nightly-backup" ] && sed -i 's/^#//g' /var/spool/cron/$file
done

# uncomment out items in dove.ini
sed -i 's/^#//g' /usr2/bbx/config/dove.ini

# move back doverserver.pl
mv /usr2/bbx/bin/doveserver.pl.rtoff /usr2/bbx/bin/doveserver.pl

# restore tcc links.
mv /usr2/bbx/bin/tcc.orig /usr2/bbx/bin/tcc
mv /usr2/bbx/bin/tcc_tws.orig /usr2/bbx/bin/tcc_tws

# start services.
systemctl start bls
systemctl start bbj
systemctl start rti

# enable on startup.
systemctl enable bls
systemctl enable bbj
systemctl enable rti

# tell this process the status.
rm -f /usr2/bbx/config/.rtoff
touch /usr2/bbx/config/.rton

echo "Real time enabled."

exit 0
