#!/bin/sh
#
# This Unix shell script will update the downloaded WETICS files
# to reflect your local installation.
#
# You must pass two arguments to the script:
#
# updateWetics <ServerInternetAddress> <WeticsHomePageURL>
#
# such as
#
# updateWetics www.ece.utexas.edu http://www.ece.utexas.edu/~bevans/wetics
#
# Version: @(#)updateWetics	1.15	01/31/98
# Author: Brian L. Evans

if [ $# -ne 2 ]
then
  echo 'Usage: updateWetics <ServerInternetAddress> <WeticsHomePageURL>'
  echo 'Both arguments must use the same Internet address'
  exit 1
fi

ipAddress=$1
newURL=$2

# Make sure that the ipAddress and newURL use the same symbolic address
checkAddress=`echo "$newURL" | sed "s+$ipAddress++"`
if [ "$checkAddress" = "$newURL" ]
then
  echo 'Usage: updateWetics <ServerInternetAddress> <WeticsHomePageURL>'
  echo 'Both arguments must use the same Internet address'
  exit 1
fi

# Replace signal.ece.utexas.edu with the Internet address from the user
# Replace http://signal.ece.utexas.edu/~arifler/wetics with new URL address

updateFiles="$HOME/public_html/wetics/applets/classes/SimButtons.java \
	     $HOME/public_html/wetics/index.html"

oldURL="http://signal.ece.utexas.edu/~arifler/wetics"

sedCommandFile=/tmp/updateWeticsSed_$$
echo "s+$oldURL+$newURL+" > $sedCommandFile
echo "s+\"signal.ece.utexas.edu\"+\"$ipAddress\"+" >> $sedCommandFile

for i in $updateFiles 
do
  echo "Updated $i"

  # Allow the script to be run multiple times
  if [ ! -f $i~ ]
  then
    echo "Saving a copy of $i to $i~"
    cp $i $i~
  fi

  chmod +w $i
  rm $i
  sed -f $sedCommandFile $i~ > $i
done

rm $sedCommandFile

# Run Java on the updated files

echo "Recompiling affected Java files in the applet directory"
echo "$HOME/public_html/wetics/applets/classes"
cd $HOME/public_html/wetics/applets/classes; make install
echo "If the Java compiler reported an error, then you are probably not"
echo "using version 1.0.2 of the Java compiler."
