#!/bin/bash
if [ $# \!= 1 ] ; then
	echo usage: $0 archivefile
	exit
fi
aosdir=/usr/aos
aoscmd=/usr/bin/aos

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

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

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


if ! [ -d ${aosdir} ] ; then
	mkdir ${aosdir} || exit 1
else
	echo "the directory \"${aosdir}\" 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 ${aosdir}/*
fi

cat $1 | gunzip | (cd ${aosdir} && tar xvf -)	

chown -R root ${aosdir}
chgrp -R sys ${aosdir}

cat ${aosdir}/system/aos.templ | \
	sed -e "s,AOS_HOME,${aosdir}," >${aoscmd}

chmod +x ${aoscmd}

# <EOF>
