#!/bin/sh
INSTALL_DIR=.
VERSION=2.0
#
#	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 UPSilon $VERSION for UNIX Lite"
  echo "-------------------------------------------"
  echo "1. Linux 2.x"
  echo "2. FreeBSD 2.x"
  echo "3. FreeBSD 3.x"  
  echo "q. Quit."
  echo ""
}

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

    if [ $select = 1 ]
        then
        FILENAME=linux
	OS="LINUX"
        break

    elif [ $select = 2 ]
        then
        FILENAME=bsd-2
	OS="FreeBSD"
        break
    
    elif [ $select = 3 ]
        then
        FILENAME=bsd-3
        OS="FreeBSD"
        break

    elif [ $select = q ]
        then
	echo "Installation not completed!"
	exit 0
    else
        echo "Invalid input."
	echo "Installation not completed!"
	exit 0
    fi
  done
}

{
  if [ -f $INSTALL_DIR/$FILENAME.Z ]
  then
	if [ -d $INSTALL_DIR/upsilon ]; then
		rm -rf upsilon
	fi
	if [ -s $INSTALL_DIR/$FILENAME ]; then
		rm $INSTALL_DIR/$FILENAME
	fi
        echo ""
        echo "Extracting files :"
	if [ $FILENAME = sgi ] || [ $FILENAME = hpux ] || [ $FILENAME = osf ] || [ $FILENAME = ultrix ]; then
        	cat $INSTALL_DIR/$FILENAME.Z | uncompress | tar xvf - 2> /dev/null
	else
        	cat $INSTALL_DIR/$FILENAME.Z | uncompress | tar xvf - 1> /dev/null
	fi
	echo "Program files: OK!"
	cp $INSTALL_DIR/help.Z $INSTALL_DIR/upsilon/  
	cd upsilon
	uncompress help.Z
	if [ $FILENAME = sgi ] || [ $FILENAME = hpux ] || [ $FILENAME = osf ] || [ $FILENAME = ultrix ]; then
		tar xvf help 2> /dev/null
	else
		tar xvf help 1> /dev/null
	fi
	echo "Help files: OK!"
        #tar xvf $INSTALL_DIR/$FILENAME ${OUT}> /dev/null
	cd ..
        if [ $? = 0 ]; then
		cd upsilon
		chmod +x ./install.$FILENAME
		./install.$FILENAME
        else
                echo "Extraction error."
		echo "Installation not Completed!"
                exit 1
        fi
  else
        echo "UPSilon for $OS not found!"
	echo "Installation not Completed!"
        exit 1
  fi
}
