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.vde2.new

# If not already there, start the daemon from /etc/rc.d/rc.local
    if [ ! "$(grep rc\.vde2 etc/rc.d/rc.local)" ]; then
  cat << EOF >> etc/rc.d/rc.local

# Start vde2:
if [ -x /etc/rc.d/rc.vde2 ]; then
  /etc/rc.d/rc.vde2 start
fi
EOF
fi
( cd usr/bin ; rm -rf vdecmd )
( cd usr/bin ; ln -sf unixcmd vdecmd )
( cd usr/lib64 ; rm -rf libvdehist.so )
( cd usr/lib64 ; ln -sf libvdehist.so.0.0.1 libvdehist.so )
( cd usr/lib64 ; rm -rf libvdehist.so.0 )
( cd usr/lib64 ; ln -sf libvdehist.so.0.0.1 libvdehist.so.0 )
( cd usr/lib64 ; rm -rf libvdemgmt.so )
( cd usr/lib64 ; ln -sf libvdemgmt.so.0.0.1 libvdemgmt.so )
( cd usr/lib64 ; rm -rf libvdemgmt.so.0 )
( cd usr/lib64 ; ln -sf libvdemgmt.so.0.0.1 libvdemgmt.so.0 )
( cd usr/lib64 ; rm -rf libvdeplug.so )
( cd usr/lib64 ; ln -sf libvdeplug.so.3.0.1 libvdeplug.so )
( cd usr/lib64 ; rm -rf libvdeplug.so.3 )
( cd usr/lib64 ; ln -sf libvdeplug.so.3.0.1 libvdeplug.so.3 )
( cd usr/lib64 ; rm -rf libvdesnmp.so )
( cd usr/lib64 ; ln -sf libvdesnmp.so.0.0.1 libvdesnmp.so )
( cd usr/lib64 ; rm -rf libvdesnmp.so.0 )
( cd usr/lib64 ; ln -sf libvdesnmp.so.0.0.1 libvdesnmp.so.0 )
( cd usr/man/man1 ; rm -rf vdecmd.1.gz )
( cd usr/man/man1 ; ln -sf unixcmd.1.gz vdecmd.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 vdeqemu.1.gz )
( cd usr/man/man1 ; ln -sf vdeq.1.gz vdeqemu.1.gz )
