#!/bin/sh

# Checking the 'aliases' file
if [ ! -f "/usr/syno/mailstation/etc/aliases" ]; then
	cat << EOM
Official package MailStation must be installed!
Please install MailStation and then try again.
EOM
    exit 1
fi

if [ ! -r "/usr/syno/mailstation/etc/aliases" ]; then
	cat << EOM
Postfix alias file is not readable!.
EOM
    exit 2
fi

if [ ! -w "/usr/syno/mailstation/etc/aliases" ]; then
	cat << EOM
Postfix alias file is not writeable!
EOM
    exit 3
fi

# Checking the 'main.cf' file
if [ ! -f "/usr/syno/mailstation/etc/main.cf" ]; then
	cat << EOM
Official package MailStation must be installed!
Please install MailStation and then try again.
EOM
    exit 1
fi

if [ ! -r "/usr/syno/mailstation/etc/main.cf" ]; then
	cat << EOM
Postfix main.cf file is not readable!
EOM
    exit 2
fi

if [ ! -w "/usr/syno/mailstation/etc/main.cf" ]; then
	cat << EOM
Postfix main.cf file is not writeable!
EOM
    exit 3
fi

# Checking the 'sasl_passwd' file, if it is there!
if [ -f "/usr/syno/mailstation/etc/sasl_passwd" ]; then
	if [ ! -r "/usr/syno/mailstation/etc/sasl_passwd" ]; then
		cat << EOM
Postfix sasl_passwd file is not readable!
EOM
		exit 2
	fi

	if [ ! -w "/usr/syno/mailstation/etc/sasl_passwd" ]; then
		cat << EOM
Postfix sasl_passwd file is not writeable!
EOM
		exit 3
	fi
fi

exit 0
