#!/bin/sh
#==============================================================================
#  Company:
#      Equinox Payments, LLC
#
#  Product:
#      Application Installer Service
#      Copyright 2011-2018 Equinox Payments, LLC
#
#  \brief
#      Script for automcatic execution of activate script after
#      unit swithed to prod-test mode
#
#==============================================================================

if [ "$1" = "test" ]
then
     /root/sectest/activate.sh --test
     exit $?
fi
if [ "$1" = "start" ]
then

SCRIPT_NAME=$0
/usr/bin/fbv -f -r -c /var/lib/installer/images/toprodtest.png &
RETRY_COUNT=3

# Try multiple times
while [[ $RETRY_COUNT -gt 0 ]]; do 
     /root/sectest/activate.sh 
     RETVAL=$?
     if [[ $RETVAL -eq 0 ]]; then
         # reactivated OK ? Show for that keys must be injected
         /bin/ln -s /home/platform/html/misc/reactivatecompleted.html /home/platform/html/show_once.html
         /bin/rm -f $SCRIPT_NAME
         /bin/sync
         /etc/rc.d/rcS stop
         /sbin/reboot -f
         exit 0
     fi
     RETRY_COUNT=$(($RETRY_COUNT - 1))
done

# reactivated failed? Show form with error message
/bin/ln -s /home/platform/html/misc/reactivationissue.html /home/platform/html/show_once.html
/bin/sync

fi
