#!/bin/sh

#eval $(env | grep "^SYNOPKG_PKGINST_TEMP_DIR=")

DSM_CONFIG="/etc.defaults/synoinfo.conf"
PACKAGE_LIMIT_KEY="limit_cloudstation"
SUPPORT_PACKAGE_KEY="support_cloudstation"

# restrict model
#SUPPORT_PACKAGE=`get_key_value ${DSM_CONFIG} ${SUPPORT_PACKAGE_KEY}`
#if [ "${SUPPORT_PACKAGE}" != "yes" ]; then
#	exit 1;
#fi

# Upgrade port config file for DSM 6.0 package framework
# The new framework cannot specify the name of the config file
# So we need to rename the old one to the new name
# This cannot write in 'postinst' script, since the web-config worker
#    runs before the 'postinst' script
AGED_PORT_CONFIG_FILE="/usr/local/etc/services.d/cloudstation_port"
NEW_PORT_CONFIG_FILE="/usr/local/etc/services.d/CloudStation.sc"

if [ -f "${AGED_PORT_CONFIG_FILE}" ]; then
	# Note: We do not copy the new one here, since that is the job of
	#       the port-config worker in the new package center framework.
	#       Here we only rename to the correct file name, so the worker
	#       can correctly locate it.
	rm -rf "${NEW_PORT_CONFIG_FILE}" # should not exist
	mv "${AGED_PORT_CONFIG_FILE}" "${NEW_PORT_CONFIG_FILE}"
fi

exit 0
