#!/bin/bash
#
CMD=$(basename $0)

PROGRAM="$PRJ/server/openerp-server"
CONFIG="$PRJ/etc/openerp-server.conf"

has_db=false
config="--config=$CONFIG"
db_user="--db_user=$(kusa-conf openerp.db_user)"
db_password="--db_password=$(kusa-conf openerp.db_password)"

for arg
do
  case $arg in
    --help)		exec $PROGRAM --help ;;
    -d|--database)	has_db=true ;;
    -c|--config)	config= ;;
    -r|--db_user)	db_user= ;;
    -w|--db_password)	db_password= ;;
  esac
done

$has_db || {
	echo "error, you need to pass --database=DBNAME (or -d DBNAME) to command line" >&2
	exit 1
}

echo -e "\nexecuting: $PROGRAM $config $db_user (db_password) $@\n"
set -x
exec $PROGRAM $config $db_user $db_password "$@"
