#!/bin/bash

. ./terminal.config

#binary name, ki ga bomo zagnali
export BIN_FILENAME=/$HOME_DIR/webssh/wssh
#killall service name
killall -s9 wssh

#mehanizem za rotiranje log-file-ov
TERMINAL_NUMBER=$1
if [ -z "$TERMINAL_NUMBER" ];then
        TERMINAL_NUMBER=1
fi
OLD_GAMES_DIR=$OLD_GAMES_DIR"/10.5.10."$TERMINAL_NUMBER
mkdir -p $OLD_GAMES_DIR

declare -x LOG_FILENAME=$OLD_GAMES_DIR"/webssh.log"
export 1>/dev/null 2>/dev/null

#zazenemo binary
echo "RUN_WSSH.SH: Loading libraries from $LIBS_PATH"

#before starting program, we check if a _update file is pending as program update - usefull to update at next reboot
if [ -e $BIN_FILENAME"_update" ]; then
   echo
   echo "    "Updating $BIN_FILENAME with file $BIN_FILENAME"_update"
   echo "    "Old version will be renamed to $BIN_FILENAME"_old"
   echo

   mv -f $BIN_FILENAME $BIN_FILENAME"_old" > /dev/null
   mv -f $BIN_FILENAME"_update" $BIN_FILENAME > /dev/null
   chmod ugo+x $BIN_FILENAME
fi;

$BIN_FILENAME --address='localhost' --port=7878 --origin='https://rocket.imaxagaming.com:9779' --redirect=false --xheaders=false --wpintvl=5 --maxconn=5 --encoding=utf8 2>&1 |tee $LOG_FILENAME

exit 0;

