#!/bin/sh
# postinst script for condor
#
# 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

configure_condor(){
	#Install init.d links to default runlevels
	update-rc.d condor defaults

	#Debian guarantee that this program is in PATH
	ldconfig

}

start_service(){
	
	# Stop condor service
	# It will fail if condor is not stopped in time limit
	if [ -x "/etc/init.d/condor" ]; then
	  if which invoke-rc.d >/dev/null 2>&1; then
     		invoke-rc.d condor start
     	  else
     		/etc/init.d/condor start
     	  fi
	fi
	
}


change_permission() {
	#Recreate empty dir because it is not part of the package
	mkdir -p /var/run/condor /var/lock/condor /var/log/condor /var/lib/condor/spool /var/lib/condor/execute
	chown -R condor:condor /var/run/condor
	chown -R condor:condor /var/lock/condor
	chown -R condor:condor /var/log/condor
	chown -R condor:condor /var/lib/condor
	chmod 1777 /var/lib/condor/execute
}

case "$1" in
	configure)
		configure_condor
		change_permission
	
		#We don't want to start condor by default
		#So that user can edit condor_config 
		
		#start_service
	;;

	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


