#!/bin/sh
# postinst script for fookebox

set -e

case "$1" in
	configure)
		# only on new installations
		if [ "$2" = "" ] ; then
			# Create database
			python /usr/share/fookebox/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

		# set a reasonable session secret
		secret=$( cat /dev/urandom | tr -dc 'a-zA-Z0-9' | \
						fold -w 32 | head -n 1 )
		sed "/^beaker.session.secret/s/ somesecret$/ ${secret}/" \
						-i /etc/fookebox/config.ini
	;;

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

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

#DEBHELPER#

exit 0
