#!/bin/bash

exit

CALL_CONTROL="/tmp/.call_control_count.txt"
TO_RUN=0

IS_MOUNTED=`ls /shares/pos/server 2> /dev/null`

if [ "$IS_MOUNTED" = "" ]; then
  echo "Server not mounted, aborting..."
  exit
fi

if [ ! -e "$CALL_CONTROL" ]; then
  echo 1 > $CALL_CONTROL
else
  COUNT=`cat $CALL_CONTROL`

  if [ "$COUNT" != "2" ]; then
    COUNT=`expr $COUNT + 1`
    echo $COUNT > $CALL_CONTROL
  else
    TO_RUN=1
  fi
fi

if [ "$TO_RUN" = "1" ]; then
  rsync --delete -va /shares/pos/ /opt/pos/station/server_backup
  rm -rf $CALL_CONTROL
fi

