#!/bin/sh
INSTALL_DIR=.
VERSION=3.4
#
#	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 Linux Lite"
  echo "-------------------------------------------"
  echo "1. Linux "
  echo "q. Quit."
  echo ""
}

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

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

{
  if [ -f $INSTALL_DIR/$FILENAME.tar.gz ]
  then
	if [ -d $INSTALL_DIR/clientmate ]; then
		rm -rf clientmate 
	fi
	if [ ! -d $INSTALL_DIR/$FILENAME ]; then
	if [ -s $INSTALL_DIR/$FILENAME ]; then
		rm $INSTALL_DIR/$FILENAME
	fi
	fi
        echo ""
        echo "Extracting files :"
       	cat $INSTALL_DIR/$FILENAME.tar.gz  | tar zxv  1> /dev/null
	echo "Program files: OK!"
        if [ $? = 0 ]; then
		cd clientmate 
		chmod +x ./install.$FILENAME
		./install.$FILENAME
        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
}
