#!/bin/sh -x

# This shell script creates a Gopher directory structure containing all
# the WAIS sources files kept at quake.think.com. Since the number of
# sources now exceeds 200, the sources are organized alphabetically.
#
# Change the shell variable "to" on line 16 and replace <password> with
# your email address on line 30.
#
# AUTHOR: Andrew_Gilmartin@Brown.Edu
# MODIFIED: 7/6/92

	# Where to place the WAIS files
	# NOTE: First command line argument overrides default

to=${1-"/tmp/moocow"}

	# Create tmp directory to work in

tmp=/tmp/gopher-wais-load

rm -fr ${tmp} 

mkdir ${tmp}
cd ${tmp}

	# Get list of WAIS sources

ftp -n quake.think.com <<!
user anonymous <password>
binary
cd wais
get wais-sources.tar.Z 
bye
!

	# Unpack them

zcat wais-sources.tar.Z | tar -xf -

	# Make all the directories

rm -r ${to}

mkdir ${to}
mkdir ${to}/.cap
for dir in a b c d e f g h i j k l m n o p q r s t u v w x y z
do
	mkdir ${to}/${dir}
done

	# Distribute WAIS sources

cd ${tmp}/wais-sources

for file in `ls`
do
		# Where to put the file?

	case $file in
		A*|a*) dir=a ;;
		B*|b*) dir=b ;;
		C*|c*) dir=c ;;
		D*|d*) dir=d ;;
		E*|e*) dir=e ;;
		F*|f*) dir=f ;;
		G*|g*) dir=g ;;
		H*|h*) dir=h ;;
		I*|i*) dir=i ;;
		J*|j*) dir=j ;;
		K*|k*) dir=k ;;
		L*|l*) dir=l ;;
		M*|m*) dir=m ;;
		N*|n*) dir=n ;;
		O*|o*) dir=o ;;
		P*|p*) dir=p ;;
		Q*|q*) dir=q ;;
		R*|r*) dir=r ;;
		S*|s*) dir=s ;;
		T*|t*) dir=t ;;
		U*|u*) dir=u ;;
		V*|v*) dir=v ;;
		W*|w*) dir=w ;;
		X*|x*) dir=x ;;
		Y*|y*) dir=y ;;
		Z*|z*) dir=z ;;
		*) dir=other ;;
	esac

		# Move the file

	mv $file ${to}/${dir}/
done

	# Create entry for directory of servers 

cp ${to}/d/directory-of-servers.src ${to}/.
cat >${to}/.cap/directory-of-servers.src <<!
Name=Directory of WAIS servers
Numb=1
!
	# Clean up

rm -rf ${tmp}

	# Done

exit 0

