#
# Copyright (c) 1999-2000 Easysoft Ltd. All rights reserved.
#
# This script checks the installer is root
#
# Calling format:
#
# install_check_root long_product_name what_if_not_textfile flag
#
# long_product_name - name of product being installed (may contain spaces)
# what_if_not_textfile - text file to output if not root
# flag - if 1 installer must be root
#        if 0 installer does not have to be root
# returns:
#
# 0 = success
# 1 = invalid command line
# 2 = environment variable not defined
#
# $Id: install_check_root,v 1.1 2000/03/17 16:36:37 martin Exp $
#
# $Log: install_check_root,v $
# Revision 1.1  2000/03/17 16:36:37  martin
# Initial revision
#
#
if [ "$ECHO" = "" ];then
  echo "error - ECHO not defined, expect it to be exported"
  exit 2
fi
#
# Check command line
#
cmdline_error=""
if [ $# -ne 3 ];then
  cmdlinestr="incorrect number of parameters"
  cmdline_error="1"
else
  PRODUCTLONG="$1"
  TEXTFILE="$2"
  FLAGS="$3"
fi
#
# If command line error
#
if [ "$cmdline_error" = "1" ];then
  $ECHO "Invalid command line, $cmdlinestr"
  $ECHO "Usage:"
  $ECHO "install_check_root product textfile flag"
  exit 1
fi
$ECHO
if [ "$FLAGS" = "1" ];then
  $ECHO "This installation requires the installer to be the root user"
fi

uid=`id | awk '{print $1}' | awk -F= '{print $2}' | awk -F\( '{print $1}'`
if [ "$uid" != "0" ];then
  if [ "$FLAGS" = "1" ];then
    $ECHO "and you do not appear to be root"
  fi
  cat "$TEXTFILE"
  if [ "$FLAGS" = "1" ];then
    $ECHO "Do you want to continue with the installation? (y/n) [n]: \c"
    answer="hoho"
    while [ "$answer" != "" -a "$answer" != "n" -a "$answer" != "y" ]
    do
      read answer
      if [ "$answer" = "" ];then
    	answer="n"
      fi
    done
    if [ "$answer" = "n" ];then
      $ECHO "Installation aborted at user request"
      exit 99
    fi
  fi
fi
exit 0