:
#!/bin/bash
#
# briefme - top package agent. Copyright (c) 1993 (Gil Nardo)
#	see files in subdir ./legal for legalease

_briefme()
{
#
# README starts here
#

more <<-TOHERE

	This is the top level directory for the nosey package.
	The programs from this package are used to diagnose your
	linux mouse device.

	The README file doubles as both a README and an Bash executable
	package agent -- a program that helps navigate, explain, and
	maintain parts of a software package. { Package Agent (tm) :-) }

	For those who do not have the command shell 'Bash', or have
	trouble using this script, or wish to go straight to using
	the package, here are the manual directions to follow to get
	you going, ASAP.

	1) cd to ..../src
	2) validate or modify makefile defines for your system tools
	3) execute make
	4) execute nosey


	The files located at this level are

	README*		readable bash executable package agent
	briefme*	bash executable package agent

	The subdirectories visible from this level are

	src/		source code to nosey
	bin/		directory for package targets/executables
	doc/		contains things we hope you'll eventually read
	agents/		contains utilities for package agents
	legal/		holds legal sorts of documents
	tmp/		temp dir for manifest checks and misc stuff
	archive/	storage for tar or zipped files

	Note: tmp/ and archive/ are usually not sent with the distribution.

TOHERE

#
# README ends here
#
	echo -n "Press <ENTER>: "
	read yn
}




# Prompt for yes or no answer - returns non-zero for no
_getyn()
{
        while   echo -n "$* (y/n) ">&2
        do      read yn rest
                case $yn in
                [yY])   return 0                      ;;
                [nN])   return 1                      ;;
                *)      echo "Please answer y or n" >&2 ;;
                esac
        done
}

# look for an archive sitting with the README file
_check_archive()
{
	local ARCNAME
	local ARCPLACE
	local PACKPLACE

	PACKPLACE=nosey
	ARCNAME=$1

	if [ ! -f $ARCNAME ]
	then return
	fi

	echo Archive file ${ARCNAME} is available

	case $ARCNAME in

		*.taz)
			if (_getyn "Extract files from gzipped tar?")
			then
				tar -zxvf $ARCNAME
			fi
			;;

		*.tgz | *.tpz)
			if (_getyn "Reverse gzip then extract from tar?")
			then
				gunzip < $ARCNAME | tar -xvf -
			fi
			;;

		*.tar)
			if (_getyn "Extract files from tar?")
			then
				tar xvf $ARCNAME
			fi
			;;

		*)
			echo Dont know how to handle archive file $ARCNAME
			return
			;;
	esac

	ARCPLACE=$PACKPLACE/archive

	if [ ! -d $PACKPLACE ]
	then	return
	fi

	if (_getyn "Move $ARCNAME to directory $ARCPLACE?")
	then
		if [ ! -d  $ARCPLACE ]
		then
			echo Making directory $ARCPLACE
			mkdir $ARCPLACE
		fi
		if [ ! -d $ARCPLACE ]
		then
			echo Could not create $ARCPLACE directory
			return
		fi
		mv $ARCNAME $ARCPLACE
	fi
	if [ -d $PACKPLACE ]
	then
		echo Changing directory to package directory $PACKPLACE
		cd $PACKPLACE;
	fi
	./agents/manifest.bsh
}

#
# main()
#
	QUICKLY=$1

	_briefme

	if [ -z "$BASH_VERSION" ]
	then
		echo "I want to be bash'd!"
		_getyn "Continue running in this shell anyway?" || exit
	fi

	_check_archive `echo *.tgz`

	if [ ! -z "$QUICKLY" ]
	then exit
	fi

	./briefme
