#!/bin/bash

if test -f ../LICENSE
	then
	echo "Please read the following license carefully...";sleep 5
	less ../LICENSE
else
	echo "Please change into the install directory on the CD-ROM to install"
	kill -9 0
fi

echo -n "Do you accept the terms of this license? (y/n)";read yn
case $yn in
	y) echo "License accepted - installation proceeding";;
	*) echo "Thank you";kill -9 0;;
esac

echo -n "Which directory should I install to (better start and end with a '/')?"
read dir
case $dir in
	/*/) echo "OK...";;
	*) echo "I told you to start and end with a '/'";exit;;
esac
if test -d $dir
	then
	echo -n "Install directory $dir exists - Should I overwrite it? (y/n)"
else
	echo -n "No $dir directory exists. Should I create one? (y/n)"
fi
read ok
case $ok in
	[yY]*) echo -n "By your command...";;
	*) echo "I better stop now then...";exit;;
esac
if test -d $dir
	then
	echo
else
	mkdir $dir && echo "Directory created..."
fi

echo "Enter your registration key";read key
echo "$key" > $dir/registration

if test -f $dir/registration
	then
	cat $dir/registration | while read a b
		do
		z=`bin/label $a`
		if test Z$z != Z$b
			then
			echo "Invalid Registration File! Please register properly before installation"
			kill -9 0
		fi
		done
	echo "Welcome to the ForensiX installer"
else
	echo "Please place your registration file in the `pwd` directory."
	kill -9 0
fi

echo -n "Installing..."
cp -a ./* $dir
echo -n "Configuring..."

for d in $dir ${dir}IP ${dir}bin ${dir}help
	do
	cd $d
	echo -n "$d"
	for a in *
		do
		if test ! -d "$a"
			then
			echo -n "."
			cp -a "$a" /tmp/zz
			cat /tmp/zz |  sed "s:/ForensiX/:$dir:g" > "$a"
		fi
		done
	done
echo "Done."
