#!/bin/sh


if [ $# -lt 1 ]; then
	echo "Usage: $0 \$PHP_SCRIPT [\$ARGS]"
	exit 1;
fi

php_bin=

allowedPath="/usr/local/psa/admin/bin /opt/psa/admin/bin"
for i in $allowedPath; do
        bin_to_check="${i}/php"
        if [ -x "${bin_to_check}" ]; then 
                php_bin="${bin_to_check}"
                break
        fi
done

if [ -z "${php_bin}" ]; then
		allowedPath="/usr/local/psa/bin /opt/psa/bin"
		
		for i in $allowedPath; do
			bin_to_check="${i}/sw-engine-pleskrun"
			if [ -x "${bin_to_check}" ]; then
				php_bin="${bin_to_check}"
				break
			fi 
		done
fi

if [ -z "${php_bin}" ]; then
	echo 'Unable to locate PHP interpreter for script execution. This script should be run only on a machine with installed Parallels Plesk Panel'
	exit 1
fi

exec "${php_bin}" "$@"
