#! /bin/bash
#
# postinst script
# This script executes after unpacking files from that archive and registering the product at the depot.
#
# The following environment variables can be used to obtain information about the current installation:
#   PRODUCT_ID: id of the current product
#   CLIENT_DATA_DIR: directory which contains the installed client data
#

TMP_DIR=${CLIENT_DATA_DIR}/../${PRODUCT_ID}.tmp
if [ ! -d $TMP_DIR ]; then
	echo "Nothing to do!"
	exit 0
fi

if [ -d $TMP_DIR ]; then
	echo 'Restoring previous directories...'
	for dirname in custom; do
		for path in $TMP_DIR/`basename $dirname`; do
			if [ -d $path ]; then
				test -e $CLIENT_DATA_DIR/$dirname && rm -rf $CLIENT_DATA_DIR/$dirname
				echo "   moving $path to $CLIENT_DATA_DIR/$dirname"
				mv $path $CLIENT_DATA_DIR/$dirname || exit 1
			fi
		done
	done
fi

echo "Removing temporary files..."
rm -rf $TMP_DIR
