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

# $1 is the PKG path
PKG_HOME=$1

###############################################################################
#       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"

###############################################################################
#       D E F I N E         F R A M E W O R K       P R O C E D U R E         #
###############################################################################

TIMESTAMP_LOG="`date "+%y%m%d%H%M%S"`"
CONFIG_LOG="/Applications/obsr.pkg-config-${TIMESTAMP_LOG}.log"

# Config Applicaiton Home: /Applications/AhsayOBS and AhsayRPS
sh "${PKG_HOME}/Contents/Resources/custom-config" "${TIMESTAMP_LOG}" >> "${CONFIG_LOG}"

sh "${PKG_HOME}/Contents/Resources/custom-startup" >> "${CONFIG_LOG}"

if [ ! -e "${APP_HOME}/logs" ]; then
    mkdir "${APP_HOME}/logs"
fi

if [ ! -e "${APP_HOME}/logs/installer" ]; then
    mkdir "${APP_HOME}/logs/installer"
fi

cd /Applications

mv  ./*.log "${APP_HOME}/logs/installer"


cd "${APP_HOME}"

#Sleep 10 seconds before server start up
sleep 10

open "Admin Server.app" &