Skip to content

updateDisplay.sh

Eric E Palmer edited this page Oct 23, 2026 · 1 revision

More involved script for updating SPC Tools. This includes some very user/system based items, so unless you are doing work just like I do, there is stuff in here you don't need.

Highlights

  • It computes all of the images before moving them, which makes loading from a slow internet connection more stable
  • Command line argument lets you specific subdirectories from /data/
  • If more than one version is running, it will provide a warning. Two copies writing to the same directory can cause lots of confusion
  • The system will run for 12 hours and then quit. It keeps this program from running in the background forever.


time=86400                    # week
time=`echo 60*60*12 | bc`     # 12 hours


sub=$1
if [ "$sub" == "" ];
then
   running=`ps ax | grep $0 | grep -v grep | wc -l`
   num=`echo $running - 2 | bc`

   if [ "$num" -gt "0" ];
   then
      echo "################################"
      echo "##### Running in data/ directory"
      echo "There are $num other users of $0.  You may have a conflict"
      ps ax | grep $0 | grep -v grep
      echo "################################"
      running=0
   fi
else
   running=`ps ax | grep $0 | grep -v grep | grep $sub | wc -l`
   sub="$sub/";
fi

start=`date +%s`


if [ "$running" -gt "2" ];
then
   echo "We have a version of $0 $1 already running"
   ps ax | grep $0 | grep -v grep
   exit
fi


path="/Library/Server/Web/Data/Sites/Default/data/$sub"
if [ -e $path ];
then
   path="/Library/Server/Web/Data/Sites/Default/data/$sub"
   echo "  Machine:  Server "
else
   path="/Library/WebServer/Documents/data/$sub"
   echo "  Machine:  Local "
fi
if [ ! -e $path ];
then
   echo $path does not exit
   exit
fi
valid=0;

echo "Using $path"
while [ 1 ]
do
   if [ -e LMRK_DISPLAY1.pgm ];
   then
      valid=1
      convert LMRK_DISPLAY1.pgm landmarks.jpg
      /bin/mv -f $path/landmarks.jpg $path/old-landmarks.jpg
      /bin/mv -f landmarks.jpg $path/landmarks.jpg
   fi

   if [ -e LMRK_DISPLAY1.pgm ];
   then
      valid=1
      convert LMRK_DISPLAY1.pgm autoregister.jpg
      /bin/mv -f $path/autoregister.jpg $path/old-autoregister.jpg
      /bin/mv -f autoregister.jpg $path/autoregister.jpg
   fi

   if [ -e TEMPFILE.pgm ];
   then
      valid=1
      convert TEMPFILE.pgm register.jpg
      /bin/mv -f $path/register.jpg $path/old-register.jpg
      /bin/mv -f register.jpg $path/register.jpg
   fi
   if [ -e TEMPFILE.ppm ];
   then
      valid=1
      convert TEMPFILE.ppm $path/registerC.jpg
   fi

   if [ -e 1.jpg ];
   then
      valid=1
      cp 1.jpg $path/1.jpg
   fi

   sleep 3

   current=`date +%s`
   delta=`echo $current - $start | bc`

   if [ "$delta" -gt "$time" ];
   then
      echo "You've run out of time"
      exit;
   fi

   if [ "$valid" -eq "0" ];
   then
      echo "No valid files -- processing stopping"
      break;
   fi



done


Clone this wiki locally