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...
}

preserve_perms() {
  NEW="$1"
  OLD="$(dirname $NEW)/$(basename $NEW .new)"
  if [ -e $OLD ]; then
    cp -a $OLD ${NEW}.incoming
    cat $NEW > ${NEW}.incoming
    mv ${NEW}.incoming $NEW
  fi
  config $NEW
}

preserve_perms etc/rc.d/rc.varnishd.new
config etc/varnish/default.vcl.new
( cd usr/lib ; rm -rf libvarnishapi.so.1 )
( cd usr/lib ; ln -sf libvarnishapi.so.1.0.0 libvarnishapi.so.1 )
( cd usr/lib ; rm -rf libvcl.so )
( cd usr/lib ; ln -sf libvcl.so.1.0.0 libvcl.so )
( cd usr/lib ; rm -rf libvcl.so.1 )
( cd usr/lib ; ln -sf libvcl.so.1.0.0 libvcl.so.1 )
( cd usr/lib ; rm -rf libvarnishcompat.so )
( cd usr/lib ; ln -sf libvarnishcompat.so.1.0.0 libvarnishcompat.so )
( cd usr/lib ; rm -rf libvarnishapi.so )
( cd usr/lib ; ln -sf libvarnishapi.so.1.0.0 libvarnishapi.so )
( cd usr/lib ; rm -rf libvarnish.so )
( cd usr/lib ; ln -sf libvarnish.so.1.0.0 libvarnish.so )
( cd usr/lib ; rm -rf libvarnish.so.1 )
( cd usr/lib ; ln -sf libvarnish.so.1.0.0 libvarnish.so.1 )
( cd usr/lib ; rm -rf libvarnishcompat.so.1 )
( cd usr/lib ; ln -sf libvarnishcompat.so.1.0.0 libvarnishcompat.so.1 )
