#!/bin/sh
#
#  Achtung!!! In den nachfolgenden Zeichenketten darf kein "?" enthalten sein !!!!!!!
#
#    Zeichenkette, die ersetzt werden soll
SRC="http://www.informatik.hu-berlin.de/~bell"
#    Zeichenkette, die eingesetzt werden soll
DST="http://www2.informatik.hu-berlin.de/~bell"
#
SED=/bin/sed
FIND=/usr/bin/find
GREP=/bin/grep
RM=/bin/rm
if [ $# -lt 1 ] ; then
    echo Error: No path
    echo use: $0 "<Path>"
    exit 1
fi
if [ ! -d $1  ] ; then
    echo Error:  $1 is not a directory
    echo use: $0 "<Pfad>"
    exit 1
fi
$RM -f /tmp/tempsubst$$
$FIND $1 -print  > /tmp/tempsubst$$
for i in `cat /tmp/tempsubst$$`
  do
    if [ -f $i ] ; then
      $GREP $SRC $i 1>/dev/null 2>&1
      RET=$?
      if [ $RET -eq 0 ] ; then
         echo $i
         $RM -f  /tmp/SUBSTFILE$$
         $SED s?$SRC?$DST?g $i > /tmp/SUBSTFILE$$
         if [ -s /tmp/SUBSTFILE$$ ] ; then
              cp  /tmp/SUBSTFILE$$ $i
         fi
         $RM -f  /tmp/SUBSTFILE$$
      fi
    fi
done
   
$RM -f /tmp/tempsubst$$
