#!/bin/sh
#remove any previous directory
if [ -d ./$1_pack ]
then
	rm -r $1_pack
fi

case "$1" in
	"")
		echo "Usage: ./package <new package name>"
		exit 1
		;;
esac

mkdir $1_pack

if [ -d ./data ]
then
	mkdir $1_pack/data
	cp ./data/*.dat $1_pack/data
else
	echo "Could not find ./data directory.  Failed."
	exit 1
fi

if [ -d ./areas ]
then
        mkdir $1_pack/areas
        cp ./areas/*.area $1_pack/areas
else
	echo "Could not find ./areas directory.  Failed."
        exit 1
fi

if [ -d ./data/help ]
then
	mkdir $1_pack/data/help
	cp ./data/help/*.help $1_pack/data/help
else
	echo "Could not find ./data/help directory, Failed."
	exit 1
fi

if [ -d ./data/info ]
then
        mkdir $1_pack/data/info
        cp ./data/info/*.info $1_pack/data/info
else
        echo "Could not find ./data/info directory, Failed."
        exit 1
fi

if [ -d ./data/bulletins ]
then
        mkdir $1_pack/data/bulletins
        cp ./data/bulletins/*.btn $1_pack/data/bulletins
else
        echo "Could not find ./data/bulletins directory, Failed."
        exit 1
fi

if [ -d ./data/banner ]
then
        mkdir $1_pack/data/banner
        cp ./data/banner/*.banr $1_pack/data/banner
else
        echo "Could not find ./data/banner directory, Failed."
        exit 1
fi

if [ -d ./data/books ]
then
        mkdir $1_pack/data/books
        cp ./data/books/*.book $1_pack/data/books 
else
        echo "Could not find ./data/books directory, Failed."
        exit 1
fi


tar -zcf $1_pack.tar.gz $1_pack
rm -r $1_pack
echo "AIME area package created with filename: $1_pack.tar.gz"
