#!/bin/sh
#remove any previous directory

case "$1" in
	"")
		echo "Usage: ./install_package <package name>"
		echo "Do not include _pack.tar.gz in <package name>"
		exit 1
		;;
esac

if tar -zxf $1_pack.tar.gz; then
	echo "Successfully decompressed."
else
	echo "Decompress of package failed.  Does $1_pack.tar.gz exist?"
	exit 0;
fi

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

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

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

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

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

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

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

rm -r $1_pack
echo "Package files successfully integrated into AIME directories."
