# This script installs Euphoria mode for xJED
# Humberto Yeverino Jr. - 28 Aug 2000

# Are you the root user?
if [ $USER != root ] ; then
  echo 0: You must run this script as root. ;
  exit ;
fi  

# 1: Verify Directory
# *****

# See if a directory was specified
if [ $1 ] ; then
  if [ -d $1 ] ; then
    if [ -a $1/site.sl ] ; then
      echo 1: Using $1 a the Jed-lib directory. ;
      JPATH=$1 ;
    else
      echo 1: $1 is not the Jed-lib directory. ;
      exit ;
    fi
  else  
    echo 1: $1 is not a directory. ;
    exit ;
  fi  
else    
  # See if the standard JED-LIB directory exists
  if [ -d /usr/lib/jed/lib ] ; then
    echo "1: Jed-lib directory found.";
    JPATH=/usr/lib/jed/lib ;
  else  
    echo "1: The Jed-lib directory was not found," ;
    echo "     either install JED (space.mit.edu/~davis/jed.html) or" ;
    echo "     specify the correct path (./installeu PATH)" ;
    exit ;
  fi
fi  


# 2: Update popups.sl
# *****

# See if popups.sl has Euphoria Mode in the Global menu
if [ $(grep -c "&Euphoria Mode" $JPATH/popups.sl) = 0 ] ; then
  echo 2: Updating popups.sl ;
  cat $JPATH/popups.sl popups.update > tempeu ;
  mv -f tempeu $JPATH/popups.sl ;
else
  echo 2: popups.sl is current. ;
fi


# 3: Update defaults.sl
# *****

# See if defaults.sl exists...
if [ -a $JPATH/defaults.sl ] ; then
  if [ $(grep -c "eumode" $JPATH/defaults.sl) = 0 ] ; then
    echo 3: Updating defaults.sl ;
    cat $JPATH/defaults.sl defaults.sl > tempeu ;
    mv -f tempeu $JPATH/defaults.sl ;
  else
    echo 3: defaults.sl is current. ;
  fi  
else
  echo 3: Creating defaults.sl ;
  cp defaults.sl $JPATH ;
fi  

# 4: Check if Del/BS fix is in defaults.sl (if was current)
# *****

if [ $(grep -c "Fix BS/DEL Problem" $JPATH/defaults.sl) = 0 ] ; then
  echo 4: Adding DEL/BS fix ;
  cat $JPATH/defaults.sl del.fix > tempeu ;
  mv -f tempeu $JPATH/defaults.sl ;
else
  echo 4: DEL/BS already fixed. ;
fi


# 5: Copy eumode.sl
# *****

cp -f eumode.sl $JPATH
echo 5: eumode.sl installed.

echo " Installation complete."
