#!/bin/csh
 
# @(#)[Hyper-G] [HGS-C] dbstart	1.10 [activate server] [Gerald Pani]

# 
# <copyright>
# 
# Copyright (c) 1993-1995
# Institute for Information Processing and Computer Supported New Media (IICM),
# Graz University of Technology, Austria.
# 
# </copyright>
  
# <file>
#
# Name:       dbstart
#
# Purpose:    Start of Hyper-G server
#
# Created:       Dec 92    Gerald Pani
#
# Modified:    6 Sep 93    Gerald Pani
# Modified:    3 Mar 94    Gerald Pani
#			+ GOPHHOST
# Modified:   21 Mar 94    Gerald Pani
#			+ GOPHHOST for www
# Modified:    3 Mai 94    Gerald Pani
#			+ check dcserver
# Modified:   21 Oct 94    Gerald Pani 
#			1.05: don't start gateways, if dbserver.control does this
# Modified:   30 Mar 95    Gerald Pani 
#			1.10: give arguments to dbserver.control
#
# Description:
# 
# Start of dbserver.control and docserver.pl
# 
# </file>

# for redirection to logfile
unset noclobber

# read Hyper-G resource file
if (! $?HGRC) then
	source ~/.hgrc
endif

# check the perl interpreter
if ( ! -f /usr/local/bin/perl ) then
	perl -v >& /dev/null
	if ( $status ) then
		echo 'dbstart: Error: can'"'"'t find the Perl interpreter'
		exit 1
	endif
endif

~/bin/scripts/dbserver.control "$argv:q" &

set startWWWGATE = 1
set startGOPHGATE = 1

if ( -f ~/.db.contr.rc ) then
	grep -s '^[^\#]*<WWWPORT>' ~/.db.contr.rc
	if ( ! $status ) then
		set startWWWGATE = 0
	endif
	grep -s '^[^\#]*<GOPHPORT>' ~/.db.contr.rc
	if ( ! $status ) then
		set startGOPHGATE = 0
	endif
endif

if ( ! -f ~/bin/$CPU/dcserver ) then
	~/bin/scripts/docserver.pl &
endif

if ( $startWWWGATE ) then
  if ( -f ~/bin/$CPU/hgbindport) then
    if ($?GOPHHOST) then
      if ( -f ~/bin/$CPU/wwwmaster) then
        sh -c 'hgbindport 80 wwwmaster -r $HGHOST -p 418 -m $GOPHHOST -d $HOME/HTML -l $HOME/wwwlog >> $HOME/wwwerrors 2>&1 &'
      else
        sh -c 'hgbindport 80 wwwgate -r $GOPHHOST -l $HOME/wwwlog >> $HOME/wwwerrors 2>&1 &'
      endif
    else
      if ( -f ~/bin/$CPU/wwwmaster) then
        sh -c 'hgbindport 80 wwwmaster -r $HGHOST -p 418 -d $HOME/HTML -l $HOME/wwwlog >> $HOME/wwwerrors 2>&1 &'
      else
        sh -c 'hgbindport 80 wwwgate -r $HGHOST -l $HOME/wwwlog >> $HOME/wwwerrors 2>&1 &'
      endif
    endif
  endif	
endif


if ( $startGOPHGATE ) then
  if ( -f ~/bin/$CPU/hgbindport) then
    if ($?GOPHHOST) then
      sh -c 'hgbindport 70 gophgate -r $HGHOST -m $GOPHHOST -l $HOME/gopherlog >> $HOME/gopherrors 2>&1 &'
    else
      sh -c 'hgbindport 70 gophgate -r $HGHOST -m $HGHOST -l $HOME/gopherlog >> $HOME/gopherrors 2>&1 &'
    endif
  endif	
endif
