#!/usr/bin/env bash
#
# Copyright (C) 2003 VA Linux Systems Japan, K.K.
#
# LICENSE NOTICE
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#

# $Id: ultrapossum-test,v 1.3 2004/04/02 02:34:28 taru Exp $

set -e

eval `ultrapossum-config init`
trap "eval `ultrapossum-config term`" 0

ERRORFILE=$LOGDIR/ultrapossum-test-error

install -d  $LOGDIR
if test -x "/usr/bin/savelog"; then
  if test -f $ERRORFILE; then
    savelog $ERRORFILE > /dev/null 2> /dev/null
  fi
  cp /dev/null $ERRORFILE
fi

TESTORGANIZATION="test"

if test -f "$SYSCONFDIR/test/test.cf"; then
  . $SYSCONFDIR/test/test.cf
elif test -f "$SYSCONFDIR/test/test.cf.dpkg-new"; then
  # debian support
  . $SYSCONFDIR/test/test.cf.dpkg-new
fi

if test "x$SSH_USER" != "x"; then
  ssh_act="$SSH_USER@"
fi

export ssh_act SSH_USER ULTRAPOSSUM_PATH ROOTCMD TESTORGANIZATION

if test -x "/etc/init.d/ultrapossum-server"; then
  /etc/init.d/ultrapossum-server restart
else
  echo -n "Restarting UltraPossum server... "
  $MODULEDIR/server/startup stop || true
  $MODULEDIR/server/startup start
  echo "done"
fi
$TESTDIR/runtest 2>> $ERRORFILE
