#!/bin/sh
# When you upgrade a package, the Package Center program calls this script after installing the new one.

# Volume where package is installed
PKG_VOLUME=$SYNOPKG_PKGDEST_VOL
# Target directory where the P5 package is installed.
INSTALL_DIR=$SYNOPKG_PKGDEST
# Package name
PACKAGE_NAME=$SYNOPKG_PKGNAME

# The backup directory
BACKUP_DIR=$SYNOPKG_TEMP_UPGRADE_FOLDER
#BACKUP_DIR="$PKG_VOLUME/@p5_backup"

# Diretories to copy back
CONFIG_DIR="$BACKUP_DIR/config"
LOG_DIR="$BACKUP_DIR/log"


if [ -d "$BACKUP_DIR" ]; then
	# Copy configuration and log folders back to place
	exit_msg=$( cp -fR $CONFIG_DIR $LOG_DIR $INSTALL_DIR )
	exit_stat=${?}
	if [ "$exit_stat" -ne "0" ]; then
   		echo "Error occured during restoring configuration files! Please try again!" > $SYNOPKG_TEMP_LOGFILE
   		exit 1
	else
   		echo "$PACKAGE_NAME is sucessfully updated." > $SYNOPKG_TEMP_LOGFILE
	fi
fi
exit 0
