#!/bin/bash
# Last Modified: 2008-26-06 02:56:33
# Tornado Online Backup Version: 5.2.6.0 (Build:8)

# This is a script file to be executed after installation

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

# $1 is the timestamp
TIMESTAMP_CONFIG=$1

JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home

###############################################################################
#       C O F I G U R E         A P P L I C A T I O N        H O M E          #
###############################################################################

echo "Log Time: ${TIMESTAMP_CONFIG}"
echo "Begin Custom Configuration for Tornado Online Backup"

echo "Create user list file at /Applications/Tornado Online Backup/home.txt"
touch "/Applications/Tornado Online Backup/home.txt"
chmod 777 "/Applications/Tornado Online Backup/home.txt"

echo "Create Scheduler IPC foler"
mkdir "/Applications/Tornado Online Backup/ipc"
chmod 777 "/Applications/Tornado Online Backup/ipc"

echo "Create AutoUpdateAgent IPC foler"
mkdir "/Applications/Tornado Online Backup/aua/ipc/xmlchannel"
chmod -R 777 "/Applications/Tornado Online Backup/aua/ipc"

echo "Configure AutoUpdateAgent for Tornado Online Backup"
sh "/Applications/Tornado Online Backup/aua/bin/auas-config.sh"
chmod 777 "/Applications/Tornado Online Backup/aua/builds"

echo "Restore /Applications/Tornado Online Backup folder ownership"
chown -R root:admin "/Applications/Tornado Online Backup"
echo "Restored default ownership root:admin at /Applications/Tornado Online Backup"

echo "Disable uninstall.sh to non sudo-ers"
chmod 700 "/Applications/Tornado Online Backup/bin/uninstall.sh"
echo "Changed file permission to 700 for /Applications/Tornado Online Backup/bin/uninstall.sh"

###############################################################################
#           C O F I G U R E          J A V A            H O M E               #
###############################################################################

ln -sf "${JAVA_HOME}" "/Applications/Tornado Online Backup/jvm"
ln -sf "${JAVA_HOME}" "/Applications/Tornado Online Backup/aua/jvm"

###############################################################################
#      C R E A T E     L I N K      F O R     U S E R     D E S K T O P       #
###############################################################################

# Create Desktop Symbolic Link
find /Users -name Desktop -type d -maxdepth 3 -mindepth 2 | while read DESKTOP_PATH;
do
	if [ ! -e "${DESKTOP_PATH}/Tornado Online Backup" ]; then
		echo "Create Symbolice Link Tornado Online Backup to user desktop path ${DESKTOP_PATH}"
		ln -sf "/Applications/Tornado Online Backup/BackupManager.app" "${DESKTOP_PATH}/Tornado Online Backup"
		echo "Symbolic Link Tornado Online Backup created at user desktop path ${DESKTOP_PATH}"
	fi
done

###############################################################################
#             E N D            O F            C O N F I G U R A T I O N       #
###############################################################################

echo "Finished Custom Configuration for Tornado Online Backup"

exit 0
