#!/bin/sh
#
cat <<EOF
# makeperl - Install Perl5 on MiNT systems.
# Copyright (C) 1997 Guido Flohr <gufl0000@stud.uni-sb.de>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

-- Hit RETURN to continue! --
EOF
read

#set -x

# This script contains almost no comments.  It follows the motto
# "If it was hard to write it has to be hard to read..."

trap 'rm -f ./tmp0$$ ./tmp1$$ 2>/dev/null; echo; echo "--> Emergency exit taken"; \
	echo; exit 1' 1 2 3 15

echo "### Checking whether your build environment is sane. ###"
for tool in "grep" "uname" "cp" "mv" "diff" "more" "touch" "sh" ; do
	echo -n "Checking for $tool ... "
	which $tool || missing="$tool $missing"
done

if test -n "$missing"; then
	cat <<EOF
Some programs that I rely on are missing on your system.  Either you have
to fix your PATH environment variable or you have get the missing tools
somewhere.  Maybe even the `which' command is missing on your system.
But if you don't have `which' you probably neither have the other
tools. Get them!

The missing tools were:
EOF
	for tool in $missing; do
		echo "        $tool"
	done
	echo "See you later..."
	exit 1
fi

echo -n "Checking for symbolic links ... "
rm -f ./tmp0$$
echo "" >./tmp0$$
ln -s ./tmp0$$ ./tmp1$$ >/dev/null 2>&1 && LN="ln" || LN="cp"
test "$LN" = "ln" && LN_OPT="-s"
echo "$LN" "$LN_OPT"
rm -f ./tmp1$$ ./tmp1$$

echo -n "Checking for tee ... "
my_tee=`which tee 2>/dev/null`
test "$my_tee" && echo "$my_tee" || echo "no"

# The pwd command that comes with KGMD resp. KEMD is broken.  It uses
# carriage return and linefeed instead of single linefeed as line
# termination no matter what UNIXMODE says.
echo -n "Checking whether your pwd command is broken... "
chmod +x ./pwd.safe 2>/dev/null
UNIXMODE=b"$UNIXMODE" ./pwd.safe >./tmp0$$ 2>/dev/null
my_pwd=`which pwd 2>/dev/null`
test "$my_pwd" && UNIXMODE=b"$UNIXMODE" `which pwd ` >./tmp1$$ 2>/dev/null
UNXIMODE=b"$UNIXMODE" diff ./tmp[01]$$ >/dev/null 2>&1
test $? = "0" && broken_pwd="no" || broken_pwd="yes"
rm -f ./tmp[01]$$
echo $broken_pwd
test $broken_pwd = "no" && broken_pwd=""

echo -n "Checking whether you're using binary mode ... "
echo "x$UNIXMODE" | grep -q '[^r]b' >/dev/null 2>&1
test $? != "1" && bin_mode="yes" || bin_mode="no"
echo $bin_mode
test $bin_mode = "yes" && bin_mode=""

echo -n "Checking whether you're using slashes as path separator ... "
echo "$UNIXMODE" | grep -q '/' >/dev/null 2>&1
test $? != "1" && slash_mode="yes" || slash_mode="no"
echo $slash_mode
test $slash_mode = "yes" && slash_mode=""

echo -n "Checking whether you're using MiNT ... "
uname -s | grep -i "MiNT" >/dev/null 2>&1
test $? != "1" && mint="yes" || mint="no"
echo $mint
test $mint = "yes" && mint=""

echo -n "Checking for LC_ALL ... "
lc_all=$LC_ALL
test "x$lcall" = "xC" && lc_all = ""
test $lc_all && echo $lc_all || echo "no"

echo -n "Checking for LANG ... "
lang=$LANG
test "x$lang" = "xC" && lang = ""
test $lang && echo $lang || echo "no"

echo -n "Evaluating ./config.sh ... "
. ./config.sh || (echo "fatal error: can't read ./config.sh"; exit 1)
echo "done"

man1found="no"
instman1dir=`echo "$installman1dir" | sed 's,/man[0-9],,g'`
echo -n "Checking for \`$installman1dir' in \$MANPATH ... "
echo "$MANPATH" | grep -q "$instman1dir" 2>/dev/null && man1found="yes"
echo "$man1found"
test "$man1found" = "yes" || man1prob="yes"

man3found="no"
instman3dir=`echo "$installman3dir" | sed 's,/man[0-9],,g'`
echo -n "Checking for \`$installman3dir' in \$MANPATH ... "
echo "$MANPATH" | grep -q "$instman3dir" 2>/dev/null && man3found="yes"
echo "$man3found"
test "$man3found" = "yes" || man3prob="yes"

echo -n "Checking whether you are superuser ... "
if [ "x$UID" = "x" ]; then
	test "x$LOGNAME" = "root" && super_user="yes" || super_user="no"
else
	test "$UID" = "0" && super_user="yes" || super_user="no"
fi
echo $super_user
test $super_user = "yes" && super_user=""

problems="$broken_pwd$bin_mode$slash_mode$mint$lc_all$lang$super_user$man1prob$man3prob"
test "$problems" && (echo; echo -n "-- You've got problems...") || \
	(echo; echo "Build environment looks fine!")

if test "$problems"; then
	echo " and we will try to fix them. --"
	echo
	problems=""
	if test "$super_user"; then
		cat <<EOF
You are not the superuser.  You should log in as root and then redo this
script.  The installation is very likely to fail if you don't have 
super user rights.
-- Hit RETURN to continue --
EOF
		read
	fi
	if test "$broken_pwd"; then
		cat <<EOF
Your pwd command seems to be broken.  Either you don't have it at all or
it is the version that always adds a carriage return at the end of its
output and perl doesn't like this at all.  Exactly speaking, chdir
won't work because it chops off the last character of pwd's output
and expects to find a valid path name then.  With the garbage carriage
return produced by your pwd this will definitely fail.  Unfortunately
the installation itself requires perl and perl requires a working
pwd.  But we've got good news for you:  Along with this port of 
perl5 comes a brandnew, bugfree version of pwd.  I can install it
for you if you like.  Don't worry:  I will keep a copy of your 
old pwd in case you don't like mine.
EOF
		echo -n "Do you want me to install it now (y/n)? [ y ] "
		read
		case "$REPLY" in
			[nN]*) problems="yes"
			cat <<EOF
OK, you should know what you are doing.  You will probably see
in a couple of minutes that I was right and you can't even install
perl with your broken pwd.
EOF
			;;
			*) test "$super_user" && cat <<EOF 
Hmm, you're not the superuser.  The installation will probably fail...
EOF
				where=`which pwd 2>/dev/null`
				old="$where"
				echo -n "Where do you want me to install my \
pwd? [ $where ] "
				read path
				test "x$path" = "x" && path="$where"
				(test "$old" && mv "$old" "$old".old || true) \
					&& cp ./pwd.safe $path \
					&& chmod 755 $path && broken_pwd=""
				test "x$broken_pwd" = "x" && \
					echo "    installed my pwd as $path and moved your old version to $old.old" \
					|| echo "    installation for pwd failed"
		esac
		echo "-- Hit RETURN to continue --"
		read
	fi
	
	if test "$bin_mode"; then
		problems="yes"
		cat <<EOF
Your UNIXMODE environment variable does not contain the letter "b".  This
will cause most of the programs you use (including the perl you're going
to install) to convert a linefeed character to carriage return/linefeed
when writing to a stream and vice versa when reading.  
The recommended setting for UNIXMODE is "/brUs".  Please fix your
start-up files and make sure that these files get evaluated and that the 
environment they set up gets preserved while running perl.
-- Hit RETURN to continue --
EOF
		read
	fi

	if test "$slash_mode"; then
		problems="yes"
		cat <<EOF
Your UNIXMODE environment variable does not contain a forward slash (/).
This will have the effect that most of your programs (including the perl
you're going to install) won't recognize a slash as path separator.
And perl won't like that at all...
The recommended setting for UNIXMODE is "/brUs".  Please fix your
start-up files and make sure that these files get evaluated and that the 
environment they set up gets preserved while running perl.
-- Hit RETURN to continue --
EOF
		read
	fi
	
	if test "$mint"; then
		light_problems="yes"
		cat <<EOF
It seems that you're not running MiNT.  If you've succeeded here that
shouldn't mean too big a problem.  Yet I can't guarantee you that this
version of perl will work without MiNT since I haven't taken too much
care for non-MiNT systems.  
You probably won't be able to run the test suite that comes along
with this distribution.  The basic tests will possibly fail already 
because you can't open /dev/null.
-- Hit RETURN to continue --
EOF
		read
	fi
	
	if test "$lc_all"; then
		light_problems="yes"
		cat <<EOF
Your environment variable LC_ALL is set to \`$LC_ALL'.  This is actually
very fine since it shows that you're aware of NLS features.  Unfortunately
the setlocale function in the MiNTLib is currently a bad joke.  It only
supports the \`C' locale.  It doesn't even recognize \`POSIX' which is
an equivalent to \'C'.
This version of perl will produce a lot of warnings because setting the
locale failed if you stick to your setting of LC_ALL.  Please note
that the test suite will also fail because it compares the expected
output of small perl scripts with the real output.  The warnings about
setlocale will spoil your test results.
However, if you run the test suite from within this script I will 
take care that this doesn't happen...
-- Hit RETURN to continue --
EOF
		read
	fi

	if test "$lang"; then
		light_problems="yes"
		cat <<EOF
Your environment variable LANG is set to \`$LANG'.  This is actually
very fine since it shows that you're aware of NLS features.  Unfortunately
the setlocale function in the MiNTLib is currently a bad joke.  It only
supports the \`C' locale.  It doesn't even recognize \`POSIX' which is
an equivalent to \`C'.
This version of perl will produce a lot of warnings because setting the
locale failed if you stick to your setting of LANG.  Please note
that the test suite will also fail because it compares the expected
output of small perl scripts with the real output.  The warnings about
setlocale will spoil your test results.
However, if you run the test suite from within this script I will 
take care that this doesn't happen...
Note that you can safely use the GNU extension LANGUAGE instead of
LANG.  Internationalized GNU packages will still display their 
messages in your native language and perl won't complain.
-- Hit RETURN to continue --
EOF
		read
	fi
	
	if test "$man1prob" = "yes"; then
		light_problems="yes"
		cat <<EOF

I couldn't find \`$installman1dir' in your \$MANPATH.  
If you want to install the perl manual pages you should add the path 

	\`$instman1dir'
	
to your MANPATH environment variable.  Otherwise you won't have access to
the section 1 of the perl manual pages.

-- Hit RETURN to continue --
EOF
		read
	fi
	if test "$man3prob" = "yes"; then
		light_problems="yes"
		cat <<EOF

I couldn't find \`$installman3dir' in your \$MANPATH.  
If you want to install the perl manual pages you should add the path 

	\`$instman3dir'
	
to your MANPATH environment variable.  Otherwise you won't have access to
the section 3 of the perl manual pages.

-- Hit RETURN to continue --
EOF
		read
	fi
fi

if test "x$problems" != "x"; then
	cat <<EOF
There still seems to be some stuff to do before you can think of installing
perl.  You should fix the deficiencies in your system before proceeding.
EOF
	echo -n "Quit the installation for now? (y/n)? [ yes ] "
	read
	case "$REPLY" in
		[nN]*) 	cat <<EOF
OK, I hope you know what you are doing.
EOF
			;;
		*)	echo "See ya later..."
			exit 1
			;;
	esac
elif test "x$light_problems" != "x"; then
	cat <<EOF
You still have light problems but basically things should work.  But maybe
you want to set up your system first.
EOF
	echo -n "Quit the installation for now? (y/n)? [ no ] "
	read
	case "$REPLY" in
		[yY]*)	echo "Redo the script after you've fixed your problems."
			exit 0
			;;
		*)	cat <<EOF
OK, we'll see if everything works fine.
EOF
			;;
	esac
fi

# Restore signals to default values.
trap 1 2 3 15

# Now do the installation.
cat <<EOF

   ### Starting installation sequence.  ###
EOF
here=`./pwd.safe`
default_answer="a"
while [ "$task" != "quit" ]; do
	cat <<EOF

	(a) run the test suite (lengthy process ...)
	(b) run harness test (also lengthy ...)
	(c) run individual tests
	(d) install perl (considerably quick ...)
	(e) install manual pages (takes a little time ...)
	(f) install html documentation (takes even longer ...)
	(g) show testlog
	(h) show harness test log
	(i) show last individual test log
	(j) show perl compile-time options
	(k) print version number and patchlevel of perl
	(l) show perl installation log
	(m) show manpage installation log
	(n) show html installation log
	(x) clean up distribution
	(!) escape to your shell
	(0) quit (very, very fast)

EOF
	echo -n "What do you want me to do? [ $default_answer ] "
	read
	test "x$REPLY" = "x" && REPLY="$default_answer"
	case "$REPLY" in
		[aA]*)
			test "$mint" && cat <<EOF
It seems that you haven't got MiNT running.  Although perl might work on
your system the test suite will probably fail because you won't pass the
basic test suite.
EOF
			cat <<EOF
Expect the following tests to fail (with MiNT):

	io/pipe.t              at test 9
	io/tell.t              at test 12
	lib/complex.t          at test 84
	lib/io_pipe.t          at test 9
	lib/io_tell.t          at test 12
	op/magic.t             at test 29

See hints/mint.sh for possible reasons for failure.

-- Hit RETURN to continue --
EOF
			read
			if test "$my_tee"; then 
				echo -n \
"Do you want to log the test results (y/n)? [ yes ] "
				read
				case "$REPLY" in
					[nN]*) 	use_tee=""
						;;
					*)	
						use_tee=" 2>&1 | tee $here/testlog"
						cat <<EOF
Test results will be logged in \`$here/testlog'.
EOF
						;;
				esac
			fi
			
			test -x ./t/perl || "$LN" "$LN_OPT" ../perl ./t/perl 2>/dev/null
			com="\
( trap 'echo; echo Action failed due to reception of a fatal signal; echo; exit 1' 1 2 3 9 15; \
cd t && LC_ALL=ignoreme && LANG=ignoreme && unset LC_ALL LANG && \
UNIXMODE=b/$UNIXMODE ./TEST $use_tee )"
			eval "$com"
			default_answer="g"
			cat >./t/tested 2>/dev/null <<EOF
The existence of this file simply indicates that you have run one of the
test suites.
EOF
			;;
		[bB]*)
			test "$mint" && cat <<EOF
It seems that you haven't got MiNT running.  Although perl might work on
your system the test suite will probably fail.
EOF
			cat <<EOF
Expect the following results:

See hints/mint.sh for possible reasons for failure.

Failed Test  Status Wstat Total Fail  Failed  List of failed
------------------------------------------------------------------------------
io/pipe.t                    10    2  20.00%  7, 9
io/tell.t                    13    1   7.69%  12
lib/complex.t               762   13   1.71%  84-85, 248-251, 257, 272-273, 
                                              371, 380, 419-420
lib/io_pipe.t                10    1  10.00%  9
lib/io_tell.t                13    1   7.69%  12
op/magic.t                   30    2   6.67%  29-30
Failed 6/152 test scripts, 96.05% okay. 20/4359 subtests failed, 99.54% okay.

-- Hit RETURN to continue --
EOF
			read
			if test "$my_tee"; then 
				echo -n \
"Do you want to log the test results (y/n)? [ yes ] "
				read
				case "$REPLY" in
					[nN]*) 	use_tee=""
						;;
					*)	
						use_tee="2>&1 | tee $here/htestlog"
						cat <<EOF
Test results will be logged in \`$here/htestlog'.
EOF
						;;
				esac
			fi
			
			echo -n "Enable verbose mode (y/n)? [ yes ] "
			read
			case "$REPLY" in
				[nN]*)	hverbose=""
					;;
				*)	hverbose="-v"
					;;
			esac
			test -x ./t/perl || "$LN" "$LN_OPT" ../perl ./t/perl 2>/dev/null
			com="\
( trap 'echo; echo Action failed due to reception of a fatal signal; echo; exit 1' 1 2 3 9 15; \
cd t && LC_ALL=ignoreme && LANG=ignoreme && unset LC_ALL LANG && \
UNIXMODE=b/$UNIXMODE ./perl -I../lib harness $hverbose $use_tee )"
			eval "$com"
			default_answer="h"
			cat >./t/tested 2>/dev/null <<EOF
The existence of this file simply indicates that you have run one of the
test suites.
EOF
			;;
		[cC]*)  echo -n "Which test: "
			read
			file=
			ext=
			echo "$REPLY" | grep -q '\.t$' && ext="" || ext=".t"
			echo "$REPLY" | grep -q '^/' && abs="yes" || abs="no"
			if test "$abs" = "yes"; then 
				files="$REPLY$ext"
			else
				files="$REPLY$ext t/$REPLY$ext t/*/$REPLY$ext"
			fi
			for try in `ls $files 2>/dev/null`; do
				if test -f "$try"; then
					file="$file $try"
					break
				fi
			done
			if test "x$file" != "x"; then
				default_answer="c"
				if test "$my_tee"; then 
					echo -n \
"Do you want to log the test results (y/n)? [ yes ] "
					read
					case "$REPLY" in
						[nN]*) 	use_tee=""
							;;
						*)	
							use_tee=" 2>&1 | tee $here/itestlog"
							cat <<EOF
Test results will be logged in \`$here/itestlog'.
EOF
							;;
					esac
				fi
				test -x ./t/perl || "$LN" "$LN_OPT" ../perl ./t/perl 2>/dev/null
				com="\
( trap 'echo; echo Action failed due to reception of a fatal signal; echo; exit 1' 1 2 3 9 15; \
LC_ALL=ignoreme && LANG=ignoreme && unset LC_ALL LANG && \
UNIXMODE=b/$UNIXMODE ./perl -I./lib $file $use_tee )"
				echo "Running $file"
				eval "$com"
				default_answer="i"
			else
				cat <<EOF
File \`$REPLY' not found.  I have tried:
$files
EOF
			fi
			;;
		[dD]*)
			do_it="yes"
			if [ ! -a ./t/tested ]; then
				cat <<EOF
Looks like you haven't even tried to run one of the test suites (a) or (b).  
Think you shouldn't install untested software on your system...
EOF
				echo -n "\
Better wait with the installation (y/n)? [ yes ] "
				read
				case "$REPLY" in
					[nN]*)
						;;
					*)
						do_it="no"
						;;						
				esac
				default_answer="a"
			fi
			if [ "$0" -nt "./config.sh" -a "$do_it" = "yes" ]; then
				cat <<EOF
It seems that you haven't edited ./config.sh yet.  Although this file
contains the recommended defaults for the installation you should have
a look at it first to make sure that everythings gets installed where
you want it.  However, for most of the settings in ./config.sh it's
already too late to change things.  You can only change the
installation directories and the extender to possibly installed 
manpages.

To get an overview of directories you should NOT change, choose (j) from
the main menu.  If you still change these directories you have to find
out from the perlrun(3) manpage how to set things up via the environment.

EOF
				echo -n "\
Better wait with the installation (y/n)? [ yes ] "
				read
				case "$REPLY" in
					[nN]*)
						;;
					*)
						do_it="no"
						;;						
				esac
				default_answer="j"
			fi
			if test "$do_it" = "yes"; then
				touch ./config.sh 2>/dev/null
				echo -n "Wait a moment please ... "
				. ./config.sh || do_it="no"
				echo "Thanks"
				if test "$do_it" = "no"; then 
					cat <<EOF
Can't evaluate ./config.sh.
-- Hit RETURN to continue --
EOF
					read
				fi
			fi
			if test "$do_it" = "yes"; then
				cat <<EOF

Warning!!!  Don't ask me why but the installation script will run into an
infinite loop if you install it over an existing installation.  I think
I will better clean up first.  I will recursively remove the following
directories:

	$installarchlib
	$installprivlib
	$installsitearch
	$installsitelib

EOF
				echo -n "\
Do you want me to remove these directories (y/n) [ no ] "
				read
				case "$REPLY" in
					[yY]*)
						cat <<EOF
rm -rf $installarchlib $installprivlib $installsitearch $installsitelib
EOF
						rm -rf "$installarchlib" \
						       "$installprivlib" \
						       "$installsitearch" \
						       "$installsitelib" 2>/dev/null
						ask_again="no"
						;;
					*)
						ask_again="yes"
						;;
				esac				
			fi
			if test "$ask_again" = "yes"; then
				echo -n "\
Proceed with the installation anyhow (y/n)? [ no ] "
				read
				case "$REPLY" in
					[yY]*)
						do_it="yes"
						;;
					*)
						do_it="no"
						;;						
				esac
			fi
			if test "$do_it" = "yes"; then
				touch ./config.sh 2>/dev/null
				if test "$my_tee"; then 
					echo -n \
"Do you want to log the installation process (y/n)? [ yes ] "
					read
					case "$REPLY" in
						[nN]*) 	use_tee=""
							;;
						*)	
							use_tee=" 2>&1 | tee $here/pinstlog"
							cat <<EOF
Test results will be logged in \`$here/pinstlog'.
EOF
							;;
					esac
				fi
				com="\
( trap 'echo; echo Action failed due to reception of a fatal signal; echo; exit 1' 1 2 3 9 15; \
LC_ALL="ignoreme" && LANG="ignoreme" && unset LC_ALL LANG && \
PERLLIB= PERL5LIB= PERL5OPT= UNIXMODE=b/'$UNIXMODE' ./perl -I./lib installperl $use_tee )"
				eval "$com"
				default_answer="l"
				cat <<EOF
-- Hit RETURN to continue --
EOF
				read
			fi
			;;
		[eE]*)
			do_it="yes"
			if test "$0" -nt "./config.sh"; then
				cat <<EOF
It seems that you haven't edited ./config.sh yet.  You should check 
the installation path and the extender of the perl manpages.

EOF
				echo -n "\
Better wait with the installation (y/n)? [ yes ] "
				read
				case "$REPLY" in
					[nN]*)
						;;
					*)
						do_it="no"
						;;						
				esac
			fi
			if test "$do_it" = "yes"; then
				if test "$my_tee"; then 
					echo -n \
"Do you want to log the installation process (y/n)? [ yes ] "
					read
					case "$REPLY" in
						[nN]*) 	use_tee=""
							;;
						*)	use_tee=" 2>&1 | tee $here/minstlog"
							cat <<EOF
Test results will be logged in \`$here/minstlog'.
EOF
							;;
					esac
				fi
				com="\
( trap 'echo; echo Action failed due to reception of a fatal signal; echo; exit 1' 1 2 3 9 15; \
LC_ALL=ignoreme && LANG=ignoreme && unset LC_ALL LANG && \
PERLLIB= PERL5LIB= PERL5OPT= UNIXMODE=b/$UNIXMODE ./perl -I./lib installman $use_tee )"
				eval "$com"
				default_answer="m"
			fi
			;;
		[fF]*)
			echo -n "Where do you want to install the html 
documentation? [ $privlib/html ] "
			read htmldir
			test "x$htmldir" = "x" && htmldir=$privlib/html
			echo -n "\
Do you want to enable verbose mode (y/n) [ yes ]? "
			read hverbose
			case "$hverbose" in 
				[nN]*)
					hverbose=""
					;;
				*)
					hverbose="--verbose"
					;;
			esac
			if test "$my_tee"; then 
				echo -n \
"Do you want to log the installation process (y/n)? [ yes ] "
				read
				case "$REPLY" in
					[nN]*) 	use_tee=""
						;;
					*)	use_tee=" 2>&1 | tee $here/hinstlog"
						cat <<EOF
Test results will be logged in \`$here/hinstlog'.
EOF
						;;
				esac
			fi
			mkdir $htmldir 2>/dev/null
			com="\
( trap 'echo; echo Action failed due to reception of a fatal signal; echo; exit 1' 1 2 3 9 15; \
LC_ALL=ignoreme && LANG=ignoreme && unset LC_ALL LANG && \
PERLLIB= PERL5LIB= PERL5OPT= UNIXMODE=b/$UNIXMODE ./perl -I./lib \
installhtml \
--podroot=. --podpath=. --recurse --htmldir=$htmldir --htmlroot=$htmldir \
--splithead=pod/perlipc --splititem=pod/perlfunc \
--libpods=perlfunc:perlguts:perlvar:perlrun:perlop $hverbose $use_tee )"
			eval "$com"
			default_answer="n"
			;;
		[gG]*)
			if test -r $here/testlog; then
				more $here/testlog
				cat <<EOF
-- Hit RETURN to continue --
EOF
				read
			else
				cat <<EOF
You have to run the test suite (a) first!
EOF
				default_answer="a"
			fi
			;;
		[hH]*)
			if test -r $here/htestlog; then
				more $here/htestlog
				cat <<EOF
-- Hit RETURN to continue --
EOF
				read
			else
				cat <<EOF
You have to run the harness test suite (b) first!
EOF
				default_answer="b"
			fi
			;;
		[iI]*)
			if test -r $here/itestlog; then
				more $here/itestlog
				cat <<EOF
-- Hit RETURN to continue --
EOF
				read
			else
				cat <<EOF
You have to run an individual test (c) first!
EOF
				default_answer="c"
			fi
			;;
		[jJ]*)
			./perl -I./lib -V | more
				cat <<EOF
-- Hit RETURN to continue --
EOF
			read
			default_answer="quit"
			;;
		[kK]*)
			./perl -v
				cat <<EOF
-- Hit RETURN to continue --
EOF
			read
			;;
		[lL]*)
			if test -r $here/pinstlog; then
				more $here/pinstlog
				cat <<EOF
-- Hit RETURN to continue --
EOF
				read
			else
				cat <<EOF
You have to install perl (d) first!
EOF
				default_answer="d"
			fi
			;;
		[mM]*)
			if test -r $here/minstlog; then
				more $here/minstlog
				cat <<EOF
-- Hit RETURN to continue --
EOF
				read
			else
				cat <<EOF
You have to install the perl manpages (e) first!
EOF
				default_answer="e"
			fi
			;;
		[nN]*)
			if test -r $here/hinstlog; then
				more $here/hinstlog
				cat <<EOF
-- Hit RETURN to continue --
EOF
				read
			else
				cat <<EOF
You have to install the perl html documentation (e) first!
EOF
				default_answer="e"
			fi
			;;
		[xX]*)
			cat <<EOF
This menu entry is mainly intended for the maintainer of this script.  It
will remove some files and will put the distribution into a state like 
you've never run this script before.

To do so I will update the timestamp of $0 and remove
	
	$here/testlog
	$here/hinstlog
	$here/htestlog
	$here/itestlog
	$here/minstlog
	$here/pinstlog
	$here/t/tested
	$here/t/perl  (Don't worry, it's a link or a copy...)
	$here/t/tmp/*
	$here/t/tmp[0-9]*

EOF
			echo -n "Do you really want to do this (y/n)? [ no ] "
			read
			case "$REPLY" in
				[yY]*) 	do_it="yes"
					;;
				*)	
					do_it="no"
					;;
			esac
			if test "$do_it" = "yes"; then
				echo -n "Wait a moment please ... "
				rm -rf $here/testlog $here/hinstlog $here/htestlog \
					$here/itestlog $here/minstlog $here/pinstlog \
					$here/t/tested $here/t/perl $here/t/tmp/* $here/t/tmp[0-9]* \
					2>/dev/null
				touch "$0"
				echo "Thanks"
				default_answer="a"
			fi
			;;
		!*)
			echo "Type \`exit' to return here!"
			sh
			;;
		0*)
			task="quit"
			;;
		[qQ]*)
			task="quit"
			;;
		[qQ][uU]*)
			task="quit"
			;;
		[qQ][uU][iI]*)
			task="quit"
			;;
		[qQ][uU][iI][tT]*)
			task="quit"
			;;
		*)
			echo "Invalid answer!"
			;;
	esac
done

echo "Bye!"
