#! /bin/sh
PATH=/opt/someApp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Lock the tester to run the cleanup script
# echo AllowUsers robot svc-citeststation>>/etc/ssh/sshd_config
# /etc/init.d/ssh restart

# Set up virtualenv
if [ -d tester_deploy_env ]; then
    rm -rf tester_deploy_env
fi
virtualenv -p python3.6 tester_deploy_env
. tester_deploy_env/bin/activate

# pip install the required packages
pip install -r requirements.txt

# Run Monitor Test
python -m pytest tester_cleanup.py --verbose | tee ~/temp.log
# Unlock the tester if the script is completed

#sed '/AllowUsers robot svc-citeststation/d' /etc/ssh/sshd_config>/tmp/sshd_config_temp
#mv /tmp/sshd_config_temp /etc/ssh/sshd_config

# Add timestamp to Message of the day - ssh login information
sudo sed -i "/Last Successful Cleanup Run :/c\Last Successful Cleanup Run : $(date)" /etc/motd

cd $origin
grep -Eo '::.*(PASSED|ERROR|FAILED)' temp.log | cut -c 3- >> result.log
python tester/push_result.py
rm -r temp.log
rm -r result.log

# Restart the ssh service
# /etc/init.d/ssh restart
