#!/bin/sh
config() {
  NEW="$1"
  OLD="`dirname $NEW`/`basename $NEW .new`"
  # If there's no config file by that name, mv it over:
  if [ ! -r $OLD ]; then
    mv $NEW $OLD
  elif [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant copy
    rm $NEW
  fi
  # Otherwise, we leave the .new copy for the admin to consider...
}

config /etc/ddclient.conf.new

if [[ $(grep ddclient /etc/rc.d/rc.local |grep -v '#') = "" ]] ; then
	echo "" >> /etc/rc.d/rc.local
	echo "if [ -x /etc/rc.d/rc.ddclient ] ; then" >> /etc/rc.d/rc.local
	echo "  . /etc/rc.d/rc.ddclient start" >> /etc/rc.d/rc.local
	echo "fi" >> /etc/rc.d/rc.local
	echo "" >> /etc/rc.d/rc.local
fi

echo ""
echo "You'll need to edit the /etc/ddclient.conf configuration file"
echo "and make /etc/rc.d/rc.ddclient executable in order to use ddclient."
echo "There are more sample configuration files included with the package."
echo "See the /usr/doc/ddclient-x.x.x directory for more info."
sleep 15
