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

# customized items of package
if [ -z "$SYNOPKG_PKGNAME" ]; then
        # prior DSM 3.2, start script will be run without environment variable
        #  at boot time, thus we need a workaround to gather name and version info
        PACKAGE_NAME="iTunesServer"
        PACKAGE_VER=`get_key_value "/var/packages/${PACKAGE_NAME}/INFO" "version"`
else
        PACKAGE_NAME=$SYNOPKG_PKGNAME
        PACKAGE_VER=$SYNOPKG_PKGVER
        PACKAGE_DEST=$SYNOPKG_PKGDEST
fi


PACKAGE_DIR="/var/packages/iTunesServer"
PKG_STATUS=$SYNOPKG_PKG_STATUS
SERVICETOOL="/usr/syno/bin/servicetool"

remove_old_port_config()
{
       # remove port-forwarding config file
       ${SERVICETOOL} --remove-configure-file --package synoitunes_port
}

change_config_owner()
{
	chown -R ${PACKAGE_NAME}:${PACKAGE_NAME} ${PACKAGE_DIR}/etc/
}

remove_old_port_config
change_config_owner

if [ "INSTALL" == "$PKG_STATUS" ]; then
    /usr/syno/bin/synoindex -R media -P ${PACKAGE_NAME} > /dev/null 2>&1
fi

exit 0
