#!/bin/sh
set -e

. /opt/fwu/ipmodule-functions

echo -n "$0 started" > ${FWU_STATUS_FILE}

parse_arguments $1 $2 $3

if [ "${COMMISSION}" != "TRUE" ]; then

	echo "Disable watchdog trigger on every update..."
	rm -f ${WATCHDOG_ENABLE_FILE}

	echo "Disable SSH on every update..."
	rm -f ${SSH_ENABLE_FILE}

	echo "Disable possible shadow templates in userdata..."
	rm -rf /opt/userdata/devicestack/shadow.template

	echo "Removing old KnxStack configuration in /opt/userdata/etc/knxstack"
	rm -f /opt/userdata/etc/knxstack/knxstack.conf

	echo "Removing old IscAppHost configuration in /opt/userdata/etc/iscapphost"
	rm -f /opt/userdata/etc/iscapphost/iscapphostconfig.xml

	echo "Removing old OM config file in /opt/userdata/devicestack/iscOM"
	rm -f /opt/userdata/devicestack/iscOM/*.json
fi

if [ -f /opt/fwu/product-post-script.sh ]; then
	/bin/sh /opt/fwu/product-post-script.sh $1 $2 $3
fi

sync_buffer

echo -n "stopped" > ${FWU_STATUS_FILE}
echo "The post-script has successfully done it's job and will now exit with return code 0."
exit 0