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.kdc.new
preserve_perms etc/rc.d/rc.kadmind.new
preserve_perms etc/rc.d/rc.kpasswdd.new
preserve_perms etc/rc.d/rc.ipropd-master.new
preserve_perms etc/rc.d/rc.ipropd-slave.new
config etc/krb5.conf.new
config var/heimdal/kdc.conf.new
config var/heimdal/kadmind.acl.new
( cd usr/info ; rm -rf heimdal )
( cd usr/info ; ln -sf heimdal.info.gz heimdal )
( cd usr/bin ; rm -rf kswitch )
( cd usr/bin ; ln -sf heimtools kswitch )
( cd usr/bin ; rm -rf klist )
( cd usr/bin ; ln -sf heimtools klist )
( cd usr/lib ; rm -rf libkadm5srv.so )
( cd usr/lib ; ln -sf libkadm5srv.so.8.0.1 libkadm5srv.so )
( cd usr/lib ; rm -rf windc.so.0 )
( cd usr/lib ; ln -sf windc.so.0.0.0 windc.so.0 )
( cd usr/lib ; rm -rf libkrb5.so )
( cd usr/lib ; ln -sf libkrb5.so.26.0.0 libkrb5.so )
( cd usr/lib ; rm -rf libasn1.so )
( cd usr/lib ; ln -sf libasn1.so.8.0.0 libasn1.so )
( cd usr/lib ; rm -rf libkadm5clnt.so.7 )
( cd usr/lib ; ln -sf libkadm5clnt.so.7.0.1 libkadm5clnt.so.7 )
( cd usr/lib ; rm -rf libgssapi.so )
( cd usr/lib ; ln -sf libgssapi.so.3.0.0 libgssapi.so )
( cd usr/lib ; rm -rf libsl.so.0 )
( cd usr/lib ; ln -sf libsl.so.0.2.1 libsl.so.0 )
( cd usr/lib ; rm -rf libhx509.so.5 )
( cd usr/lib ; ln -sf libhx509.so.5.0.0 libhx509.so.5 )
( cd usr/lib ; rm -rf libheimntlm.so.0 )
( cd usr/lib ; ln -sf libheimntlm.so.0.1.0 libheimntlm.so.0 )
( cd usr/lib ; rm -rf libkafs.so )
( cd usr/lib ; ln -sf libkafs.so.0.5.1 libkafs.so )
( cd usr/lib ; rm -rf libheimbase.so.1 )
( cd usr/lib ; ln -sf libheimbase.so.1.0.0 libheimbase.so.1 )
( cd usr/lib ; rm -rf libasn1.so.8 )
( cd usr/lib ; ln -sf libasn1.so.8.0.0 libasn1.so.8 )
( cd usr/lib ; rm -rf libheimntlm.so )
( cd usr/lib ; ln -sf libheimntlm.so.0.1.0 libheimntlm.so )
( cd usr/lib ; rm -rf libhdb.so )
( cd usr/lib ; ln -sf libhdb.so.9.2.0 libhdb.so )
( cd usr/lib ; rm -rf libkrb5.so.26 )
( cd usr/lib ; ln -sf libkrb5.so.26.0.0 libkrb5.so.26 )
( cd usr/lib ; rm -rf libwind.so )
( cd usr/lib ; ln -sf libwind.so.0.0.0 libwind.so )
( cd usr/lib ; rm -rf libhcrypto.so )
( cd usr/lib ; ln -sf libhcrypto.so.4.1.0 libhcrypto.so )
( cd usr/lib ; rm -rf libhx509.so )
( cd usr/lib ; ln -sf libhx509.so.5.0.0 libhx509.so )
( cd usr/lib ; rm -rf libgssapi.so.3 )
( cd usr/lib ; ln -sf libgssapi.so.3.0.0 libgssapi.so.3 )
( cd usr/lib ; rm -rf libheimbase.so )
( cd usr/lib ; ln -sf libheimbase.so.1.0.0 libheimbase.so )
( cd usr/lib ; rm -rf libkafs.so.0 )
( cd usr/lib ; ln -sf libkafs.so.0.5.1 libkafs.so.0 )
( cd usr/lib ; rm -rf libroken.so )
( cd usr/lib ; ln -sf libroken.so.18.1.0 libroken.so )
( cd usr/lib ; rm -rf libhdb.so.9 )
( cd usr/lib ; ln -sf libhdb.so.9.2.0 libhdb.so.9 )
( cd usr/lib ; rm -rf libkdc.so.2 )
( cd usr/lib ; ln -sf libkdc.so.2.0.0 libkdc.so.2 )
( cd usr/lib ; rm -rf libsl.so )
( cd usr/lib ; ln -sf libsl.so.0.2.1 libsl.so )
( cd usr/lib ; rm -rf libkadm5clnt.so )
( cd usr/lib ; ln -sf libkadm5clnt.so.7.0.1 libkadm5clnt.so )
( cd usr/lib ; rm -rf libkdc.so )
( cd usr/lib ; ln -sf libkdc.so.2.0.0 libkdc.so )
( cd usr/lib ; rm -rf libkadm5srv.so.8 )
( cd usr/lib ; ln -sf libkadm5srv.so.8.0.1 libkadm5srv.so.8 )
( cd usr/lib ; rm -rf libroken.so.18 )
( cd usr/lib ; ln -sf libroken.so.18.1.0 libroken.so.18 )
( cd usr/lib ; rm -rf libhcrypto.so.4 )
( cd usr/lib ; ln -sf libhcrypto.so.4.1.0 libhcrypto.so.4 )
( cd usr/lib ; rm -rf windc.so )
( cd usr/lib ; ln -sf windc.so.0.0.0 windc.so )
( cd usr/lib ; rm -rf libwind.so.0 )
( cd usr/lib ; ln -sf libwind.so.0.0.0 libwind.so.0 )
