#!/bin/sh
INSTALL_DIR=.
VERSION=3.3
#
#	Must run this script as root
#
uid=`id | sed 's/^uid=\([0-9][0-9]*\).*$/\1/'`
if [ $uid -ne 0 ]; then
    echo "Not logged in as root."
    exit 1
fi

{
  clear
  echo ""
  echo " Installation of ClientMate $VERSION for FreeBSD Lite"
  echo "-------------------------------------------"
  echo "1. FreeBSD "
  echo "q. Quit."
  echo ""
}

{
  while true
  do
    echo "Please Select One:"
    read select

    if [ $select = 1 ]
        then
        FILENAME=clientmate-v34-FreeBSD
	OS="FreeBSD"
	PROGRAM=clientmate
        break
    else
        echo "Invalid input."
	echo "Installation not completed!"
	exit 0
    fi
  done
}

{
  if [ -f $INSTALL_DIR/$FILENAME.tgz ]
  then
	if [ -d $INSTALL_DIR/$PROGRAM ]; then
		rm -rf $PROGRAM 
	fi
	if [ ! -d $INSTALL_DIR/$FILENAME ]; then
	if [ -s $INSTALL_DIR/$FILENAME ]; then
		rm $INSTALL_DIR/$FILENAME
	fi
	fi
        echo ""
        echo "Extracting files :"
       	tar zxvf $INSTALL_DIR/$FILENAME.tgz 
	echo "Program files: OK!"
        if [ $? = 0 ]; then
		cd $PROGRAM 
		chmod +x ./install.bsd
		./install.bsd
        else
                echo "Extraction error."
		echo "Installation not Completed!"
                exit 1
        fi
  else
        echo "ClientMate for $OS not found!"
	echo "Installation not Completed!"
        exit 1
  fi
}
