#!/bin/bash
if [ $# \!= 1 ] ; then
	echo usage: sudo $0 archivefile
	exit
fi
a2home=/usr/local/A2
a2cmd=/usr/local/bin/a2

echo -n "Installation directory for the UnixA2 system [default:${a2home}] :"
read a
if ! [ -z $a ] ; then a2home=$a ; fi

echo -n "Command to invoke UnixA2 [default:${a2cmd}] :"
read a
if ! [ -z $a ] ; then a2cmd=$a ; fi

if [ -f ${a2cmd} ] ; then
	echo "the command \"${a2cmd}\" already exists."
	echo -n "would you like to overwite it [y/n]:"
	read a
	if [ "$a" \!= "y" ] ; then exit 1 ; fi
fi


if ! [ -d ${a2home} ] ; then
	mkdir ${a2home} || exit 1
else
	echo "the directory \"${a2home}\" already exists."
	echo -n "would you like to overwrite the old contents [y/n]"
	read a
	if [ "$a" \!= "y" ] ; then exit 1 ; fi
	rm -rf ${a2home}/*
fi

cat $1 | (cd ${a2home} && tar zxvf -)	

chown -R root ${a2home}
chgrp -R bin  ${a2home}

cat ${a2home}/starta2.templ | \
	sed -e "s,A2_HOME,${a2home}," >${a2home}/starta2.txt

cat ${a2home}/a2.templ | \
	sed -e "s,A2_HOME,${a2home}," >${a2cmd}

chmod +x ${a2cmd}

# <EOF>
