#!/bin/sh
# postinst script for fookebox

set -e

case "$1" in
	configure)
		# only on new installations and upgrades from pre-0.5.0:
		if [ "$2" = "" ] || \
			dpkg --compare-versions "$2" lt-nl "0.5.0-1" ; then

			# Create database
			python /usr/share/doc/fookebox/examples/create-database.py
			chgrp www-data /var/lib/fookebox/fookebox.sqlite
			chmod 0660 /var/lib/fookebox/fookebox.sqlite

			# Set permissions
			chgrp -R www-data /var/cache/fookebox
			chgrp www-data /var/lib/fookebox
			chgrp www-data /etc/fookebox/apache.conf
			chgrp www-data /etc/fookebox/fookebox.wsgi
			chgrp www-data /etc/fookebox/config.ini
		fi
	;;

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

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

# handle updates from older package versions
if dpkg-maintscript-helper supports rm_conffile ; then
	dpkg-maintscript-helper rm_conffile \
		/etc/fookebox/site.conf.php 0.4.99-1 -- "$@"
	dpkg-maintscript-helper rm_conffile \
		/etc/fookebox/status.conf.php 0.4.99-1 -- "$@"
fi

#DEBHELPER#

exit 0
