#!/usr/bin/perl
# Run an Apps Area script
# Reason: the use of special libdirs and so on in the scripts
# require a bit of setting up.
# The ideal is that only this script needs to change when the counter
# moves.

#print STDERR "runscript executing\n";
$homedir = "/home/apps/db";
$libdir = "/home/counter/lib";
$cmd = join(" ", @ARGV);

chdir($homedir) || die "runscript $cmd: unable to chdir to $homedir\n";
$ENV{'PATH'} = '/local/bin:/bin:/usr/bin:.';    # note that curdir is included..
# reason for /local/bin first is to get right version of make
$ENV{'SHELL'} = '/bin/sh' if defined $ENV{'SHELL'};
$ENV{'IFS'} = ''          if defined $ENV{'IFS'};
$ENV{PERL5LIB} = $libdir;
if ($ENV{PATH_INFO}) {
    # Assume we are a CGI-BIN script
    @parts = split("/", $ENV{PATH_INFO});
    shift @parts if !$parts[0];
    $program = shift(@parts);
    $ENV{PATH_INFO} = join("/", @parts);
    exec("cgi-bin/$program");
    print STDERR "Exec failed for cgi-bin/$program\n"; # if we get here
} else {
    exec(@ARGV);
    print STDERR "Exec failed for @ARGV\n"; # if we get here
}

