#!/bin/sh
# Copyright (c) 2000-2013 Synology Inc. All rights reserved.

source `dirname "$0"`/common

PACKAGE_DIR="/var/packages/$PACKAGE_NAME"
PKG_INDEXDB_PATH="${PACKAGE_DIR}/target/indexdb"
DSM_INDEX_ADD="/usr/syno/bin/pkgindexer_add"
DSM_INDEX_DEL="/usr/syno/bin/pkgindexer_del"

StartDaemons() {
	linkFiles
	if CheckPHPINI $PHP_INI; then
		#upgrade
		ModifyPHPINI $PHP_INI
		restartApache
	fi
	if [ -n "$SYNOPKG_PKG_STATUS" ]; then
		${DSM_INDEX_ADD} ${PKG_APP_PATH}/index.conf ${PKG_INDEXDB_PATH}/appindexdb
	fi
}

StopDaemons() {
	unlinkFiles
	if [ -n "$SYNOPKG_PKG_STATUS" ]; then
		${DSM_INDEX_DEL} ${PKG_APP_PATH}/index.conf ${PKG_INDEXDB_PATH}/appindexdb
	fi
}

case "$1" in
	start)
		StartDaemons
		;;
	stop)
		StopDaemons
		;;
	restart)
		StopDaemons
		sleep 1
		StartDaemons
		;;
	status)
		if [ ! -d "$PACKAGE_DIR" ]; then
			exit_with_broken
		fi
		exit 0
		;;
	log)
		echo ""
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}" >&2
		exit 1
		;;
esac
exit 0

