#!/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...
}

# Keep same perms on rc.vde2.new:
if [ -e etc/rc.d/rc.vde2 ]; then
  cp -a etc/rc.d/rc.vde2 etc/rc.d/rc.vde2.new.incoming
  cat etc/rc.d/rc.vde2.new > etc/rc.d/rc.vde2.new.incoming
  mv etc/rc.d/rc.vde2.new.incoming etc/rc.d/rc.vde2.new
fi

config etc/vde2/vdecmd.new
config etc/vde2/libvdemgmt/sendcmd.rc.new
config etc/vde2/libvdemgmt/openmachine.rc.new
config etc/vde2/libvdemgmt/closemachine.rc.new
config etc/vde2/libvdemgmt/asyncrecv.rc.new
config etc/rc.d/rc.vde2.new
( cd usr/man/man1 ; rm -rf vdeqemu.1.gz )
( cd usr/man/man1 ; ln -sf vdeq.1.gz vdeqemu.1.gz )
( cd usr/man/man1 ; rm -rf vdekvm.1.gz )
( cd usr/man/man1 ; ln -sf vdeq.1.gz vdekvm.1.gz )
( cd usr/man/man1 ; rm -rf vdecmd.1.gz )
( cd usr/man/man1 ; ln -sf unixcmd.1.gz vdecmd.1.gz )
( cd usr/bin ; rm -rf vdekvm )
( cd usr/bin ; ln -sf vdeq vdekvm )
( cd usr/bin ; rm -rf vdeqemu )
( cd usr/bin ; ln -sf vdeq vdeqemu )
( cd usr/bin ; rm -rf vdecmd )
( cd usr/bin ; ln -sf unixcmd vdecmd )
( cd usr/lib ; rm -rf libvdesnmp.so.0 )
( cd usr/lib ; ln -sf libvdesnmp.so.0.0.1 libvdesnmp.so.0 )
( cd usr/lib ; rm -rf libvdesnmp.so )
( cd usr/lib ; ln -sf libvdesnmp.so.0.0.1 libvdesnmp.so )
( cd usr/lib ; rm -rf libvdeplug.so.3 )
( cd usr/lib ; ln -sf libvdeplug.so.3.0.1 libvdeplug.so.3 )
( cd usr/lib ; rm -rf libvdehist.so.0 )
( cd usr/lib ; ln -sf libvdehist.so.0.0.1 libvdehist.so.0 )
( cd usr/lib ; rm -rf libvdemgmt.so.0 )
( cd usr/lib ; ln -sf libvdemgmt.so.0.0.1 libvdemgmt.so.0 )
( cd usr/lib ; rm -rf libvdehist.so )
( cd usr/lib ; ln -sf libvdehist.so.0.0.1 libvdehist.so )
( cd usr/lib ; rm -rf libvdeplug.so )
( cd usr/lib ; ln -sf libvdeplug.so.3.0.1 libvdeplug.so )
( cd usr/lib ; rm -rf libvdemgmt.so )
( cd usr/lib ; ln -sf libvdemgmt.so.0.0.1 libvdemgmt.so )
