#!/bin/bash
# Ahsay Offsite Backup Server and Replication Server 
# Version: 5.5.1.0

# This is a script file to be executed before installation (if installation path exist)
# This will clean up the previous version's garbage

###############################################################################
#       D E F I N E           P A T H       A N D        N A M E S            #
###############################################################################

# $1 is the PKG path
PKG_HOME=$1

# $2 is the timestamp
TIMESTAMP_CLEANUP=$2

###############################################################################
#       D E F I N E          D E P L O Y M E N T       C O N S T A N T S      #
###############################################################################

# Define APP_NAME for current installation
APP_NAME="Ahsay Offsite Backup Server and Replication Server"

# Define APP_HOME for current installation
APP_HOME="/Applications/AhsayOBS and AhsayRPS"

# Define SERVICE_NAME for current installation
SERVICE_NAME="AhsayOBS and AhsayRPS"

# Define PKG_NAME for current installation
PKG_NAME="obsr.pkg"


JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
BACKUP_DIR=/tmp/${PKG_NAME}-${TIMESTAMP_CLEANUP}

###############################################################################
#       S H U T D O W N           R E L A T E D          P R O C E S S        #
###############################################################################

echo "Log Time: ${TIMESTAMP_CLEANUP}"
echo "Begin Custom Cleanup for ${APP_NAME}"

sh "${PKG_HOME}/Contents/Resources/taskkill" "${APP_HOME}/java/bin/java"

###############################################################################
#       R E M O V E        A P P L I C A T I O N         C O M P O N E N T    #
###############################################################################

if [ -e "/Library/StartupItems/${SERVICE_NAME}" ]; then
    echo "Remove /Library/StartupItems/${SERVICE_NAME}"
    rm -rf "/Library/StartupItems/${SERVICE_NAME}"
fi   

###############################################################################
#           E N D                   O F                C L E A N - U P        #
###############################################################################

echo "Finished Custom Cleanup for ${APP_NAME}"

exit 0
