config() {
  NEW="$1"
  OLD="$(dirname $NEW)/$(basename $NEW .new)"
  if [ ! -r $OLD ]; then
    mv $NEW $OLD
  elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
    rm $NEW
  fi
}

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.rabbitmq.new
config etc/rabbitmq/rabbitmq-env.conf.new
( cd usr/bin ; rm -rf rabbitmq-defaults )
( cd usr/bin ; ln -sf ../lib64/erlang/lib/rabbitmq_server-3.8.14/sbin/rabbitmq-defaults rabbitmq-defaults )
( cd usr/bin ; rm -rf rabbitmq-env )
( cd usr/bin ; ln -sf ../lib64/erlang/lib/rabbitmq_server-3.8.14/sbin/rabbitmq-env rabbitmq-env )
( cd usr/bin ; rm -rf rabbitmq-plugins )
( cd usr/bin ; ln -sf ../lib64/erlang/lib/rabbitmq_server-3.8.14/sbin/rabbitmq-plugins rabbitmq-plugins )
( cd usr/bin ; rm -rf rabbitmq-server )
( cd usr/bin ; ln -sf ../lib64/erlang/lib/rabbitmq_server-3.8.14/sbin/rabbitmq-server rabbitmq-server )
( cd usr/bin ; rm -rf rabbitmqctl )
( cd usr/bin ; ln -sf ../lib64/erlang/lib/rabbitmq_server-3.8.14/sbin/rabbitmqctl rabbitmqctl )
