#!/bin/sh
# config maintainer script for diaspora-installer
 
set -e

# source debconf stuff
. /usr/share/debconf/confmodule

# source dbconfig-common shell library, and call the hook function
if [ -f /usr/share/dbconfig-common/dpkg/config.pgsql ]; then
   . /usr/share/dbconfig-common/dpkg/config.pgsql

   dbc_dbname="diaspora_production"
   dbc_dbuser="diaspora"

   dbc_go diaspora-installer $@
fi

# What is your pod address?
db_input high diaspora-installer/url || true
db_go

# Configure pod address.
db_get diaspora-installer/url
if ! test -f /etc/diaspora.conf
	then 
		echo export SERVERNAME=$RET >> /etc/diaspora.conf
		export SERVERNAME=$RET
		echo export ENVIRONMENT_URL=https://$SERVERNAME >> /etc/diaspora.conf
		export ENVIRONMENT_URL=https://$SERVERNAME
		sed -e "s/SERVERNAME_FIXME/$RET/" -e "s/DIASPORA_SSL_PATH_FIXME/\\/etc\\/diaspora/" -e "s/DIASPORA_ROOT_FIXME/\\/usr\\/share\\/diaspora/" /usr/share/doc/diaspora-installer/nginx.conf.example >/etc/nginx/sites-available/$RET
		ln -fs /etc/nginx/sites-available/$RET /etc/nginx/sites-enabled/
fi

if [ "$RET" = "false" ]; then
    db_go
fi

