#!/bin/csh

#234567890123456789012345678901234567
if ($?HOME) then
else
	echo "Consistency error"
	echo "HOME envar not set"
	exit
endif

cat <<EOF
-installhlpp build 15-

Welcome to the installhlpp script.
This program will try to install the
HyperLink Parsing Proxy for you.

(C)2001 Cameron Kaiser

Press RETURN/ENTER to continue.
Press CTRL-C to abort.
EOF
head -1
echo "Checking for Perl 5 ..."
set perl=`which perl`
set cycle=0
top:
set version=`$perl -e 'print substr($], 0, 1)'`
echo "$perl"
if ($version < 5) then
        if ($cycle == 0) then
                set perl = `which perl5`
                set cycle=1
                goto top
        endif
        if ($cycle == 1) then
                cat <<EOD

FAILED!
Can't find Perl 5.0 or higher.

Your system needs to have Perl 5.0
or higher installed to support HLPP.
Ask your system administrator.
Installation ABORTED.
EOD
                exit
        endif
endif

echo "Checking for Lynx ..."
set lynx=`which lynx`
if (`echo $lynx | grep -c 'alias'` != 1) then
	if (! -x "$lynx") then
		cat <<EOM

FAILED!
Lynx not found.

Lynx is needed to download from
Computer Workshops' server.
Ask your system administrator.
Installation ABORTED.
EOM
        	exit
	endif
else
	set lynx='lynx'
endif
echo "$lynx"
echo "#\!$perl -s" >! ~/hlpp
echo "Downloading hlpp ..."
$lynx -source ftp://ftp.armory.com/pub/user/spectre/UNIX/hlpp >> ~/hlpp
set size=`$perl -e 'print (-s "$ARGV[0]/hlpp")' $HOME`
echo "File size: $size bytes"
if ($size < 30) then
        rm -f ~/hlpp
        cat <<EOP

FAILED!
hlpp did not transfer.

This is probably due to network
congestion. Please retry later.
Installation ABORTED.
EOP
        exit
endif
chmod 700 ~/hlpp
cat <<EOQ

SUCCESSFUL!

To run the proxy, type

./hlpp

in your home directory.

hlpp will now run a self-test.
The installation has FINISHED.
Press RETURN/ENTER for the test.
EOQ
head -1
~/hlpp -test

