#!/bin/bash
#
# Skygrant Copyright Christophe Gros 2004 <skylendar@yahoo.com>
#
# This utility is released under the GPL license
#

if ! [ "$USERNAME" = "root" ]; then
	echo $0 must be executed as root !
	exit 1
fi
if [ "$1" = "" ]; then
	echo Usage: $0 \[-d\] ]\<user name\>
	exit
fi

if [ "$1" = "-d" ]; then
	CMD="ALTER GROUP SkyUsers DROP USER $2;"
	su -c "psql -c \"$CMD\" skylendar" postgres > /dev/null 2>&1
	CMD="DROP USER $2;"
	su -c "psql -c \"$CMD\" skylendar" postgres > /dev/null 2>&1
	exit
fi

CMD="CREATE USER $1;"
su -c "psql -c \"$CMD\" skylendar" postgres > /dev/null 2>&1
CMD="ALTER GROUP SkyUsers ADD USER $1;"
su -c "psql -c \"$CMD\" skylendar" postgres > /dev/null 2>&1