#!/bin/sh
#
# Script to install tcp_wrappers on a HP machine
# author Stefano Turolla
# ESO - European Southern Observatory
# e-mail: sturolla@eso.org
#

#sub to delete old tcp_wrappers installations
delete_old()
{
	printf "%s" "removing old installation .... "
	rm -f $SBIN/in.tcpd
	rm -f $SBIN/tcpdchk
	rm -f $SBIN/tcpdmatch
	rm -f $SBIN/safe_finger
	rm -f $LIB/libwrap.a
	rm -f $INCLUDE/tcpd.h
	rm -f $MAN/man3/hosts_access.3
	rm -f $MAN/man5/hosts_access.5
	rm -f $MAN/man5/hosts_options.5
	rm -f $MAN/man8/tcpd.8
	rm -f $MAN/man8/tcpdchk.8
	rm -f $MAN/MAN8/tcpdmatch.8
	rm -f $MAN/MAN8/tcpd.8

	printf "%s\n" "done!"
}

# main

clear
PATH=/usr/bin:/bin:/usr/sbin:/usr/ucb
machine=`hostname`
os=`uname -s`
ver=`uname -r`
arch=`uname -m`
user=`whoami`
current_dir=`pwd`
SBIN=/usr/sbin/
MAN=/usr/man/
ETC=/etc/
LIB=/usr/lib/
INCLUDE=/usr/include/
VERSION=7.6

echo "========================================================================================================================"
echo "installation script for tcp_wrappers "
echo "Stefano Turolla - sturolla@eso.org - 22.11.2000"
echo "========================================================================================================================"
if [ $user != "root" ] 
then
	echo "You must be root, sorry..."
	exit 1
fi

if [ $os != "HP-UX" ]  
then
	echo "this script install tcp_wrappers 7.6 for HP-UX machines!"
	exit 1
fi
echo "Installing tcp_wrappers version 7.6 version on machine $machine and os = $os"

echo
tarfile="tcp_wrappers_$VERSION-$os-$ver.tar"

if [ ! -f $tarfile ]
then
	echo "the file $tarfile is missing in the current directory"
	exit 1
fi

# copying tar file in /tmp

printf "%s" "copying tar file in /tmp .... "
cp $tarfile /tmp
printf "%s\n" "done!"

delete_old

printf "%s" "extracting tcp_wrappers distribution.....  "
cd /tmp
tar xf /tmp/$tarfile
cd tcp_wrappers_7.6
printf "%s\n" "done!"

rm -f /tmp/$tarfile

printf "%s" "installing tcp_wrappers .....  "
cp tcpd $SBIN/in.tcpd
cp tcpdchk tcpdmatch safe_finger $SBIN
cp libwrap.a $LIB
cp tcpd.h $INCLUDE
cp hosts_access.3  $MAN/man3/
cp hosts_access.5 hosts_options.5 $MAN/man5/
cp tcpd.8 tcpdchk.8 tcpdmatch.8 $MAN/man8/
cd $current_dir
rm -rf /tmp/tcp_wrappers_7.6
printf "%s\n" "done!"

printf "%s" "/etc/hosts.allow and /etc/hosts.deny files .....  "
touch /etc/hosts.allow
touch /etc/hosts.deny
printf "%s\n" "done!"

echo 
echo "don't forget to configure tcp wrapper putting entries in hosts.allow and hosts.deny"
echo "By default they are empty so nothing is filtered"
echo "For more information see the following man pages"
echo
echo "man -s 8 tcpd"
echo "man -s 8 tcpdchk"
echo "man -s 8 tcpdmatch"
echo "man -s 5 hosts.access" 
echo done

