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

_briefme()
{
#
# README starts here
#

more <<-TOHERE

	This is the top level directory for the 68xx assemblers
	and utilities.  The programs made from this package are
	used to generate Motorola 68xx microcomputer instructions
	for programming the MC6800 chip family. This chip family
	is usually used in embedded computer applications. The output
	files can be sent to an eprom or chip programmer device that
	accepts Motorola S records or binary images.

	The raw public domain sources were originally from the Motorola
	BBS and has been ported, packaged, and made available by
	Migrant Computing Services for the benefit of the Linux community.

	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.utl
	2) validate or modify makefile defines for your system tools
	3) execute make
	4) cd to ..../src.asm
	5) validate or modify makefile defines for your system tools
	6) execute make
	7) cd to ..../tests
	8) execute make
	9) if the tests pass, you are ready to use and install the
		 files ..../bin/as* to a system directory.


	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.asm/	source code to assembler
	src.utl/	source code to utilities
	inc/		local include directory
	bin/		container for package targets
	tests/		test area for package executables
	agents/		contains utilities for package agents
	doc/		holds technical sorts of documents
	legal/		holds legal sorts of documents

TOHERE

#
# README ends here
#

}




# 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

	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=archive

	if (_getyn "Move $ARCNAME to directory $ARCPLACE?")
	then
		if [ ! -d  $ARCPLACE ]
		then
			mkdir $ARCPLACE
		fi
		if [ ! -d $ARCPLACE ]
		then
			echo Could not create $ARCPLACE directory
			return
		fi
		mv $ARCNAME $ARCPLACE
	fi

}

#
# 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
