#!/bin/sh

# Change the eagle distribution path to eagle to reflect your needs
EAGLEPATH="youreaglepath"

# We remove any old lock file ".stopserver" . 
# If this file will be present in the future, the script will exit (see below).
sh -c "rm -f .stopserver"

# We start eagle and after quitting it, generate lock file to exit loop.
# While this is running in background, the script can proceed.
sh -c "($EAGLEPATH/bin/eagle -S $EAGLEPATH/scr/spice3.scr; touch .stopserver) &"

# ... and tries to read the file ".runme" every second.
# As soon as it exists, the script tries to execute each
# line of the contents. Afterwards, it removes the file.
# If the file .stopserver exists, the whole script exits.
# 
while [ true ] ; do
  if test -f ".runme" ; then
    read COMMAND < ".runme"
    sh -c "$COMMAND"
    sh -c "rm .runme"
    fi
  if test -f ".stopserver" ; then
    exit
    fi
  sleep 1
  done
