#!/bin/sh

#
# (c) Copyright 1992 by Panagiotis Tsirigotis
# All rights reserved.
#

#
# $Id: unpack-src,v 5.6 1993/01/08 01:51:32 panos Exp $
#

script_name=`basename $0`

if test "$script_name" != "$0" -a "./$script_name" != "$0" ; then
	echo This script must be executed from the directory where the tar files are
	exit 1
fi

lib_names="sio misc fsma str pset xlog"

#
# If we have compressed files, uncompress them.
#
if test "`echo *.Z`" != '*.Z' ; then
	echo Uncompressing *.Z
	uncompress *.Z 
fi

#
# Verify that we have all the archives
#
haveall=yes
for i in $lib_names xinetd
do
	if test "`echo $i.*.tar`" = "$i.*.tar" ; then
		if test "$i" = "xinetd" ; then
			echo xinetd is missing
		else
			echo Library $i is missing
		fi
		haveall=
	fi
done
if test ! "$haveall" ; then exit 1 ; fi

for i in libs xinetd
do
	if test ! -d $i ; then
		rm -f $i		# in case it is a file
	else
		echo -n "Directory $i exists; Delete it and proceed ? --> "
		read ans
		if test "$ans" != "yes" -a "$ans" != "y" ; then
			echo "Exiting..."
			exit 1
		fi
		echo -n "Deleting $i ... "
		rm -rf $i
		echo " DONE"
	fi
done

mkdir xinetd libs libs/man libs/include libs/lib

#
# Create the necessary directories and untar the libraries
#
for i in $lib_names
do
	lib_dir=libs/$i
	if test ! -d $lib_dir ; then
		rm -f $lib_dir
	else
		rm -rf $lib_dir
	fi
	mkdir $lib_dir
	lib_name=$i.*.tar
	cp $lib_name $lib_dir
	echo -n "Unpacking $i ..."
	( cd $lib_dir ; tar xf $lib_name )
	echo " DONE"
done

xtar=xinetd.*.tar
cp $xtar xinetd
echo -n "Unpacking xinetd ..."
( cd xinetd ; tar xf $xtar )
echo " DONE"

echo Finished unpacking
echo The tar files have been copied to the directories libs and xinetd.
echo After you have successfully compiled xinetd you may want to delete 
echo them from this directory.

