#!/usr/bin/perl

system "clear";

print "\n";
$path=$0;
if ( $path =~ /^\// ){
  $gpath=$path;
  $gpath=~ s/\/bin\/.+$//gi;
}else{
  $gpath=$path;$gpath=~ s/\/.+$//gi;
  $a=`cd $gpath;echo \$PWD`;
  chomp($a);$gpath=$a;
  $gpath=~ s/\/bin$//gi;
}



if (!( -f "/etc/hgs2.conf" )){
  print "Missing config file /etc/hgs2.conf ABORTING \n";
  print "run ./setup in the $gpath directory\n";
  exit 1;
}
if (!( -d "$gpath/data" )){
  print "Missing $gpath/data ABORTING \n";
  exit 1;
}
print "Fixing uid on $gpath/data \n\n";
`chown nobody $gpath/data`;

if (!( -d "$gpath/sbin" )){
  print "Missing $gpath/sbin ABORTING \n";
  exit 1;
}
if (!( -f "$gpath/lib/rrdtool/lib/perl/RRDs.pm" )){
  print "Missing RRDTOOL \n";
  print "
You haven't created the link to rrdtool in the lib directory 
this is a must install the rrdtool package from
http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/ 
and create a link in $gpath/lib/ 
example :
cd $gpath/lib/
ln -s /usr/local/rrdtool-<version>        

";
  exit 1;
}

$a=`netstat -ln | grep ":8889" `;

if (!( $a=~ /8889/ )){ 
  print "Server is not running ...\n";
print "
INETD :
Did you add 
grapher2              8889/tcp
to your  /etc/services and
grapher2            stream  tcp     nowait  nobody  /usr/sbin/tcpd  /home/grapher2/sbin/grapher2d
to your /etc/inetd.conf 
don't forget to restart your inetd daemon.
If you do not have tcpwrapper installed then remove /usr/sbin/tcpd from the above line.

XINETD :
Did you add 
grapher2              8889/tcp
to your  /etc/services and created the file grapher2 in /etc/xinetd.d containing
_______________ cut here ____________
# statistics gatherer
service grapher2
{
        flags           = REUSE
        socket_type     = stream
        wait            = no
        user            = nobody
        server          = $gpath/sbin/grapher2d
        log_on_failure  += USERID
        disable         = no
}
_______________ cut here ____________

don't forget to restart xinetd

";

  exit 1;
}



print " I CANT CHECK THIS SO CHECK IT YOURSELF
DON'T forget to add 
ScriptAlias /grapher2  $gpath/cgi
to your httpd.conf and restart apache
http://localhost/grapher2/index
should display something ...
*********************************************
";

print "Looks OK\n";
print "If it still doesn't work let me know !\n";
print "\n";
