#!/bin/sh
VICTIM=/etc/hosts
SERVER=repository.maemo.org
IPADDRESS=66.33.212.254
LINE="$IPADDRESS $SERVER"
FOUNDDNS=1
export FOUNDDNS SERVER IPADDRESS
if test -d /scratchbox; then
 VICTIM="/scratchbox$VICTIM"
 echo It seems there is a scratchbox environment. 1>&2
 echo trying to change it... 1>&2
fi
if test ! -f $VICTIM; then
 echo Could not find $VICTIM 1>&2
 exit 0
fi
FOUNDDNS=`fgrep "$SERVER" $VICTIM 2>/dev/null`
if test -z "$FOUNDDNS"; then
echo Could not find "$SERVER" in $VICTIM 1>&2
exit 0
fi
if test ! -w $VICTIM; then
 echo Can not write to $VICTIM 1>&2
 echo You will need to execute the following manually: 1>&2
 echo '  FILE=$(fgrep -v "'$LINE'" '$VICTIM')' 1>&2
 echo '  echo "$FILE" > '$VICTIM 1>&2
 exit 1
fi
fgrep "$LINE" $VICTIM > /dev/null 2>/dev/null && FOUNDDNS=
if test ! -z "$FOUNDDNS"; then
 echo Could not find "$LINE" in $VICTIM 1>&2
 echo There was a line "$FOUNDDNS" instead, you will need to manually 1>&2
 echo remove these lines. 1>&2
 exit 1
fi
FILE=$(fgrep -v "$LINE" $VICTIM)
umask 0033
echo "$FILE" > $VICTIM
exit 0
