#!/bin/bash
# Copyright (C) 2000-2016 Synology Inc. All rights reserved.

SYSCONFDIR="/usr/local/etc/php70"
JOB_NAME="pkg-php70-fpm"
UPSTART_JOB="/etc/init/${JOB_NAME}.conf"

ENVIRONMENT_SETUP()
{
	if [ ! -d "${SYSCONFDIR}" ]; then
		/usr/bin/mkdir "${SYSCONFDIR}"
	fi
	/usr/bin/chmod 755 "${SYSCONFDIR}"
	/usr/bin/chown root:root "${SYSCONFDIR}"

	for d in conf.d fpm.d; do
		if [ ! -d "${SYSCONFDIR}/${d}" ]; then
			/usr/bin/mkdir "${SYSCONFDIR}/${d}"
		fi
		/usr/bin/chmod 755 "${SYSCONFDIR}/${d}"
		/usr/bin/chown root:root "${SYSCONFDIR}/${d}"
	done

	for i in php.ini php-fpm.conf; do
		/usr/bin/rm -f "$SYSCONFDIR/$i"
		/usr/bin/ln -s "$SYNOPKG_PKGDEST/$SYSCONFDIR/$i" "$SYSCONFDIR/$i"
	done

	if [ -L "${SYSCONFDIR}/freetds" ]; then
		/usr/bin/rm "${SYSCONFDIR}/freetds"
	fi

	if [ ! -d "${SYSCONFDIR}/freetds" ]; then
		/usr/bin/mkdir "${SYSCONFDIR}/freetds"
		/usr/bin/cp "${SYNOPKG_PKGDEST}/${SYSCONFDIR}"/freetds/*.conf "${SYSCONFDIR}/freetds/"
	fi

	if [ ! -d "/usr/local/lib/php70/modules" ]; then
		/usr/bin/mkdir -pm755 "/usr/local/lib/php70/modules"
	fi
}
