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

NGINX_CONF_DIR="/usr/local/etc/nginx/conf.d"
MISC_DIR="/usr/syno"
UDC_DIR="/usr/syno/etc/user.data.conf"
OLD_UDC_CONFIG="${UDC_DIR}/report.config"

LN_BIN="/bin/ln"
RM_BIN="/bin/rm"
CP_BIN="/bin/cp"
KILLALL_BIN="/bin/killall"
REPORT_BIN="/usr/syno/synoreport/synoreport"

CreateHelpAndString()
{
    if [ -n "$SYNOPKG_PKG_STATUS" ]; then
        ${DSM_INDEX_ADD} ${PKG_APP_PATH}/index.conf ${PKG_INDEXDB_PATH}/appindexdb
        ${DSM_INDEX_ADD} ${PKG_APP_PATH}/helptoc.conf ${PKG_INDEXDB_PATH}/helpindexdb
    fi
}
RemoveHelpAndString()
{
	if [ -n "$SYNOPKG_PKG_STATUS" ]; then
        ${DSM_INDEX_DEL} ${PKG_APP_PATH}/index.conf ${PKG_INDEXDB_PATH}/appindexdb
        ${DSM_INDEX_DEL} ${PKG_APP_PATH}/helptoc.conf ${PKG_INDEXDB_PATH}/helpindexdb
    fi
}

RemoveFile()
{
	${RM_BIN} -f ${1}	
}
CopyFile()
{
	${CP_BIN} -f ${PACKAGE_DIR}/target${1}/${2} ${1}
}

CreateLink()
{
	${LN_BIN} -sf ${PACKAGE_DIR}/target${1}/${2} ${1}/${2}
}
RemoveLink()
{
	${RM_BIN} -f ${1}/${2}
}

CopyRewriteRule()
{
	CopyFile ${NGINX_CONF_DIR} dsm.StorageAnalyzer.conf
}
RemoveRewriteRule()
{
	RemoveFile ${NGINX_CONF_DIR} dsm.StorageAnalyzer.conf
}

RemoveTemplateAndBinaryLink()
{
	RemoveLink ${MISC_DIR} synoreport
}
CopyTemplateAndBinaryLink()
{
	${RM_BIN} -rf ${MISC_DIR}/synoreport
	CreateLink ${MISC_DIR} synoreport
}

RemoveOldUDCConfig()
{
	if [ -f "${OLD_UDC_CONFIG}" ]; then
        ${RM_BIN} -f ${OLD_UDC_CONFIG}
    fi
}

HideSchedule()
{
	[ -e "$REPORT_BIN" ] && "$REPORT_BIN" --hide-schedule
}

ShowSchedule()
{
	[ -e "$REPORT_BIN" ] && "$REPORT_BIN" --show-schedule
}

StopSynoreport()
{
	${KILLALL_BIN} -15 synoreport
}
