#!/bin/bash

PGPATH=/usr/lib/postgresql/bin
export PATH=$PATH:$PGPATH
export PGUSER=postgres

echo "This version does not know how to update the database."
echo "If you want to upgrade, STOP NOW, and wait for 0.9"
echo -n "Do you want to DESTROY the Barracuda database [y/N] ? "
read YN

if [ "$YN" = "Y" -o "$YN" = "y" ]
then
	echo "Destroying Barracuda database..."
	if psql -ltq | grep '|barracuda[^|]*$'
	then
		destroydb barracuda
		rm -rf ~barracuda
		echo "Deleting barracuda user..."
		userdel barracuda
		echo "Deleting barracuda group..."
		groupdel barracuda
	else
		echo "Database does not exist or other error."
	fi
fi
if [ \( "$1" = "upgrade" -o "$1" = "remove" \) -a -L /usr/doc/barracuda ]; then
  rm -f /usr/doc/barracuda
fi

