#!/bin/sh
# postinst script for unicore-gateway
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
    configure)
	
	chown unicore:unicore /etc/unicore/gateway/startup.properties
	chmod 640 /etc/unicore/gateway/startup.properties
	
	chown unicore:unicore /etc/unicore/gateway/connections.properties
	chmod 640 /etc/unicore/gateway/connections.properties
	
	chown unicore:unicore /etc/unicore/gateway/security.properties
	chmod 640 /etc/unicore/gateway/security.properties

	chown unicore:unicore /etc/unicore/gateway/gateway.properties
	chmod 640 /etc/unicore/gateway/gateway.properties

 	chown unicore:unicore /etc/unicore/gateway/logging.properties
	chmod 640 /etc/unicore/gateway/logging.properties

        chmod 755 /etc/init.d/unicore-gateway
	chmod 755 /usr/sbin/unicore-gateway-start.sh
	chmod 755 /usr/sbin/unicore-gateway-stop.sh

        chmod 755 /usr/share/doc/unicore/gateway/
	chmod 644 /usr/share/doc/unicore/gateway/*
	
        chmod 755 /usr/share/unicore/gateway/lib
	chmod 644 /usr/share/unicore/gateway/lib/*.jar 
#	chmod 755 /usr/share/unicore/gateway/lib/endorsed
#	chmod 644 /usr/share/unicore/gateway/lib/endorsed/*.jar

	chown unicore:unicore /var/log/unicore
	chmod 755 /var/log/unicore
	chown unicore:unicore /var/log/unicore/gateway
	chmod 755 /var/log/unicore/gateway
	chown unicore:unicore /var/run/unicore
	chmod 755 /var/run/unicore

	chmod 755 /usr/share/unicore/configurator
        chmod 755 /usr/share/unicore/configurator/updater.d
	chmod 644 /usr/share/unicore/configurator/updater.d/gateway.py
	
	if [ -e /sbin/insserv ]
    then
     /sbin/insserv unicore-gateway
    fi 
	;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
