#!/bin/sh 

# Message our PPID to the parent so we can wait for it.
# SFPREPROCESS_DOWNLOAD
echo "PID: $$"

# SFPREPROCESS_GENERIC
KS_BIN_DIR="$1"
INSTALL_DIR="$2"

if [ ! -e "$KS_BIN_DIR/ksdiff" ]; then
	echo "The ksdiff tool could not be located inside Kaleidoscope"
	exit 1
fi

# Remove KS1 KSDiff files if they exist.
rm -f $INSTALL_DIR/ksdiff-svnwrapper
rm -f $INSTALL_DIR/ksdiff-wrapper

echo "Installing ksdiff in $INSTALL_DIR..."

# creates INSTALL_DIR if it doesn't exist, doesn't overwrite it if it does exist.
if (/bin/mkdir -p "$INSTALL_DIR" && /usr/bin/install "$KS_BIN_DIR/ksdiff" "$INSTALL_DIR/ksdiff"); then
	# Success, everything installed fine
	echo "ksdiff was successfully installed in $INSTALL_DIR"
	exit 0
fi


echo "ksdiff could not be installed"
exit 4
