#!/bin/sh

if [ -n "$PLESK_INSTALLER_DEBUG" -o -n "$PLESK_INSTALLER_VERBOSE" ]; then
	set -x;
fi

root_d="/usr/local/psa"
install_d="$root_d/admin/sbin"
tmpdir="$root_d/var"

prog="`basename $0`"
mu="`echo $prog | awk -F '-' '{print $1}'`"

restorecmd=":"
which restorecon > /dev/null
if [ $? = 0 ]; then
        restorecmd="restorecon"
fi

if which rpm >/dev/null 2>&1; then
        str="`rpm -qa|grep plesk-mail-[pq]c-driver`"
fi
if which dpkg >/dev/null 2>&1; then
        str="`dpkg --get-selections plesk-mail-[pq]c-driver | awk '{if ($2 == \"install\") {print $1}}'`"
fi

case "$str" in
        plesk-mail-pc-driver*) ;;
        *) exit 0 ;;
esac

# replace mailmng
sum_new="`md5sum $tmpdir/postfix-mailqueuemng | cut -d\  -f 1`"
sum_old="`md5sum $install_d/mailqueuemng | cut -d\  -f 1`"
if [ "$sum_old" != "$sum_new" ]; then
	cp -f $tmpdir/postfix-mailqueuemng $install_d/mailqueuemng
	# change permissions
	chown root:root $install_d/mailqueuemng
	chmod 0750 $install_d/mailqueuemng

	$restorecmd $install_d/mailqueuemng
fi

exit 0
