#!/bin/sh
LOGalreadydone=/var/tmp/pressupdate/alreadydone
LOGmatchproblem=/var/tmp/pressupdate/notprocessed

file=$1
if [ ! -f "$file" ]; then
echo "usage: ed.sh <file>"
echo "$file	not found" >> $LOGmatchproblem
exit 1
fi

tmpf1=/tmp/${file}1.%%
tmpf2=/tmp/${file}2.%%
tmpf3=/tmp/${file}3.%%

grep 'add_button03_over.gif' $file > /dev/null
if [ $? -eq 0 ]; then
echo $file >> $LOGalreadydone
else
sed -e \
's#</head>#<script language="JavaScript" src="../../spec-net_script.js"></script>\
</head>#;' \
$file > $tmpf1
if [ $? -ne 0 ]; then
	echo "$file	edit for head" >> $LOGmatchproblem
	exit 1
fi

grep '<body>' $file > /dev/null
if [ $? -ne 0 ]; then
echo "$file	body" >> $LOGmatchproblem
else
	sed -e "s#<body>#<body onLoad=\"MM_preloadImages('../../images/add_button03_over.gif');\">#" $tmpf1 > $tmpf2
	if [ $? -ne 0 ]; then
		echo "$file	edit for body" >> $LOGmatchproblem
		exit 1
  fi

	grep  '">- contact us -</font></a>' $file > /dev/null
	if [ $? -ne 0 ]; then
	echo "$file	contact us" >> $LOGmatchproblem
	else
		sed -e "s#>- contact us -</font></a>#>- contact us -</font></a>\
		</p><p>\
		<a href=\"http://www.spec-net.com.au/addasite.htm\" onMouseOut=\"MM_swapImgRestore();\" onMouseOver=\"MM_swapImage('add_button03','','../../images/add_button03_over.gif',1);\">\
		<img name=\"add_button03\" src=\"../../images/add_button03.gif\" width=\"152\" height=\"22\" border=\"0\" alt=\"\">\
		</a>#" $tmpf2 > $tmpf3
		if [ $? -eq 0 ]; then
	  	cp $tmpf3 $file
	  else
			echo "$file	edit for contact us" >> $LOGmatchproblem
	  fi
	fi
fi
fi

rm $tmpf1 $tmpf2 $tmpf3