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
}

config etc/glusterfs/eventsconfig.json.new
config etc/glusterfs/glusterd.vol.new
config etc/glusterfs/group-gluster-block.new
config etc/glusterfs/group-metadata-cache.new
config etc/glusterfs/group-nl-cache.new
config etc/glusterfs/group-virt.example.new
config etc/glusterfs/gsyncd.conf.new
config etc/glusterfs/logger.conf.example.new
config etc/logrotate.d/glusterfs-georep.new
config etc/logrotate.d/glusterfs.new
preserve_perms etc/rc.d/rc.glusterd.new
( cd usr/lib/glusterfs/4.1.0/xlator/cluster ; rm -rf disperse.so )
( cd usr/lib/glusterfs/4.1.0/xlator/cluster ; ln -sf ec.so disperse.so )
( cd usr/lib/glusterfs/4.1.0/xlator/cluster ; rm -rf distribute.so )
( cd usr/lib/glusterfs/4.1.0/xlator/cluster ; ln -sf dht.so distribute.so )
( cd usr/lib/glusterfs/4.1.0/xlator/cluster ; rm -rf replicate.so )
( cd usr/lib/glusterfs/4.1.0/xlator/cluster ; ln -sf afr.so replicate.so )
( cd usr/lib/glusterfs/4.1.0/xlator/features ; rm -rf access-control.so )
( cd usr/lib/glusterfs/4.1.0/xlator/features ; ln -sf ../system/posix-acl.so access-control.so )
( cd usr/lib/glusterfs/4.1.0/xlator/features ; rm -rf posix-locks.so )
( cd usr/lib/glusterfs/4.1.0/xlator/features ; ln -sf locks.so posix-locks.so )
( cd usr/lib/glusterfs/4.1.0/xlator/performance ; rm -rf stat-prefetch.so )
( cd usr/lib/glusterfs/4.1.0/xlator/performance ; ln -sf ./md-cache.so stat-prefetch.so )
( cd usr/lib ; rm -rf libgfapi.so )
( cd usr/lib ; ln -sf libgfapi.so.0.0.0 libgfapi.so )
( cd usr/lib ; rm -rf libgfapi.so.0 )
( cd usr/lib ; ln -sf libgfapi.so.0.0.0 libgfapi.so.0 )
( cd usr/lib ; rm -rf libgfchangelog.so )
( cd usr/lib ; ln -sf libgfchangelog.so.0.0.1 libgfchangelog.so )
( cd usr/lib ; rm -rf libgfchangelog.so.0 )
( cd usr/lib ; ln -sf libgfchangelog.so.0.0.1 libgfchangelog.so.0 )
( cd usr/lib ; rm -rf libgfdb.so )
( cd usr/lib ; ln -sf libgfdb.so.0.0.1 libgfdb.so )
( cd usr/lib ; rm -rf libgfdb.so.0 )
( cd usr/lib ; ln -sf libgfdb.so.0.0.1 libgfdb.so.0 )
( cd usr/lib ; rm -rf libgfrpc.so )
( cd usr/lib ; ln -sf libgfrpc.so.0.0.1 libgfrpc.so )
( cd usr/lib ; rm -rf libgfrpc.so.0 )
( cd usr/lib ; ln -sf libgfrpc.so.0.0.1 libgfrpc.so.0 )
( cd usr/lib ; rm -rf libgfxdr.so )
( cd usr/lib ; ln -sf libgfxdr.so.0.0.1 libgfxdr.so )
( cd usr/lib ; rm -rf libgfxdr.so.0 )
( cd usr/lib ; ln -sf libgfxdr.so.0.0.1 libgfxdr.so.0 )
( cd usr/lib ; rm -rf libglusterfs.so )
( cd usr/lib ; ln -sf libglusterfs.so.0.0.1 libglusterfs.so )
( cd usr/lib ; rm -rf libglusterfs.so.0 )
( cd usr/lib ; ln -sf libglusterfs.so.0.0.1 libglusterfs.so.0 )
( cd usr/sbin ; rm -rf gfind_missing_files )
( cd usr/sbin ; ln -sf /usr/libexec/glusterfs/gfind_missing_files/gfind_missing_files.sh gfind_missing_files )
( cd usr/sbin ; rm -rf gluster-eventsapi )
( cd usr/sbin ; ln -sf /usr/libexec/glusterfs/peer_eventsapi.py gluster-eventsapi )
( cd usr/sbin ; rm -rf gluster-georep-sshkey )
( cd usr/sbin ; ln -sf /usr/libexec/glusterfs/peer_georep-sshkey.py gluster-georep-sshkey )
( cd usr/sbin ; rm -rf gluster-mountbroker )
( cd usr/sbin ; ln -sf /usr/libexec/glusterfs/peer_mountbroker.py gluster-mountbroker )
( cd usr/sbin ; rm -rf glusterd )
( cd usr/sbin ; ln -sf glusterfsd glusterd )
( cd usr/sbin ; rm -rf glustereventsd )
( cd usr/sbin ; ln -sf /usr/libexec/glusterfs/events/glustereventsd.py glustereventsd )
( cd usr/sbin ; rm -rf glusterfs )
( cd usr/sbin ; ln -sf glusterfsd glusterfs )
( cd var/lib/glusterd/hooks/1/delete/post ; rm -rf S57glusterfind-delete-post )
( cd var/lib/glusterd/hooks/1/delete/post ; ln -sf /usr/libexec/glusterfs/glusterfind/S57glusterfind-delete-post.py S57glusterfind-delete-post )
