#!/bin/sh

cd "${INSTALL_PATH}${FILE_SEPARATOR}syracuse"

echo "Stop and delete service"
$SHELL "${INSTALL_PATH}${FILE_SEPARATOR}syracuse${FILE_SEPARATOR}servicestop.sh"
$SHELL "${INSTALL_PATH}${FILE_SEPARATOR}syracuse${FILE_SEPARATOR}servicedelete.sh"

# Delete content of streamline cache folder 
# List all cache directory should look like that pattern <cacheDir>/<user> and delete the content of that dir 
for f in "${INSTALL_PATH}${FILE_SEPARATOR}syracuse${FILE_SEPARATOR}cache${FILE_SEPARATOR}*"
do
	# remove all content of all folder under cache/user
	rm -rf $f/*
	rm -rf $f/.* # remove file starts with . except "." and ".."

done

if [ -f "SAGE ERP X3 EULA FR".txt ]; then rm -f "SAGE ERP"*.txt; fi
if [ -f "SAGE ERP X3 EULA FR".htm ]; then rm -f "SAGE ERP"*.htm; fi

echo "Mkdir update_backup"
mkdir update_backup
CURR_DATE=`date +%m-%d-%Y_%H-%M-%S`
cp -f "${syracuse.dir.binpath}${FILE_SEPARATOR}nodelocal.js" "update_backup${FILE_SEPARATOR}nodelocal.js.$CURR_DATE"
cp -f "${syracuse.dir.binpath}${FILE_SEPARATOR}nodelocal.js" "update_backup${FILE_SEPARATOR}nodelocal.js"

echo "Deleting ${syracuse.dir.binpath}"
rm -rf  "${syracuse.dir.binpath}/"

rm -rf *.sh
rm -rf *.conf
rm -rf "agent/"
rm -rf *.service

exit 0