#!/bin/bash

set -e

exec > /var/log/agent_init.log
exec 2>&1

##################################################################
#- Initialize bunnyshell agent                                   #
##################################################################

root_dir='/opt/bunnyshell'
exec_name='bunnyshell'

mkdir -p ${root_dir}
cd ${root_dir}
if test -f ${exec_name}; then
	mv ${exec_name} ${exec_name}_old
fi

if ! test -f "${root_dir}/bunnyshell.conf"; then
	echo "
SERVER_HOST=\"$2\"
MODULES_PATH=\"$2\"
" > "${root_dir}/bunnyshell.conf"
fi

cp agent/${exec_name} .

restart_schedule_time=10

echo "sleep ${restart_schedule_time}; service bunnyshell restart" | at now
