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.heimdal.new
config etc/krb5.conf-sample.new
config var/heimdal/kdc.conf-sample.new
config etc/profile.d/heimdal.sh.new
config etc/profile.d/heimdal.csh.new


( cd usr/info ; rm -rf heimdal )
( cd usr/info ; ln -sf heimdal.info.gz heimdal )
( cd usr/heimdal/bin ; rm -rf kswitch )
( cd usr/heimdal/bin ; ln -sf kcc kswitch )
( cd usr/heimdal/bin ; rm -rf klist )
( cd usr/heimdal/bin ; ln -sf kcc klist )
( cd usr/heimdal/man/man5 ; rm -rf qop.5.gz )
( cd usr/heimdal/man/man5 ; ln -sf mech/mech.5.gz qop.5.gz )
( cd usr/lib64 ; rm -rf libkdc.so.2 )
( cd usr/lib64 ; ln -sf libkdc.so.2.0.0 libkdc.so.2 )
( cd usr/lib64 ; rm -rf libkadm5clnt.so )
( cd usr/lib64 ; ln -sf libkadm5clnt.so.7.0.1 libkadm5clnt.so )
( cd usr/lib64 ; rm -rf libheimntlm.so )
( cd usr/lib64 ; ln -sf libheimntlm.so.0.1.0 libheimntlm.so )
( cd usr/lib64 ; rm -rf libroken.so.18 )
( cd usr/lib64 ; ln -sf libroken.so.18.1.0 libroken.so.18 )
( cd usr/lib64 ; rm -rf libheimedit.so.0 )
( cd usr/lib64 ; ln -sf libheimedit.so.0.0.36 libheimedit.so.0 )
( cd usr/lib64 ; rm -rf libroken.so )
( cd usr/lib64 ; ln -sf libroken.so.18.1.0 libroken.so )
( cd usr/lib64 ; rm -rf libkadm5clnt.so.7 )
( cd usr/lib64 ; ln -sf libkadm5clnt.so.7.0.1 libkadm5clnt.so.7 )
( cd usr/lib64 ; rm -rf libheimbase.so.1 )
( cd usr/lib64 ; ln -sf libheimbase.so.1.0.0 libheimbase.so.1 )
( cd usr/lib64 ; rm -rf libasn1.so )
( cd usr/lib64 ; ln -sf libasn1.so.8.0.0 libasn1.so )
( cd usr/lib64 ; rm -rf windc.so.0 )
( cd usr/lib64 ; ln -sf windc.so.0.0.0 windc.so.0 )
( cd usr/lib64 ; rm -rf libhdb.so.9 )
( cd usr/lib64 ; ln -sf libhdb.so.9.2.0 libhdb.so.9 )
( cd usr/lib64 ; rm -rf libheimntlm.so.0 )
( cd usr/lib64 ; ln -sf libheimntlm.so.0.1.0 libheimntlm.so.0 )
( cd usr/lib64 ; rm -rf libkdc.so )
( cd usr/lib64 ; ln -sf libkdc.so.2.0.0 libkdc.so )
( cd usr/lib64 ; rm -rf libwind.so )
( cd usr/lib64 ; ln -sf libwind.so.0.0.0 libwind.so )
( cd usr/lib64 ; rm -rf windc.so )
( cd usr/lib64 ; ln -sf windc.so.0.0.0 windc.so )
( cd usr/lib64 ; rm -rf libgssapi.so.3 )
( cd usr/lib64 ; ln -sf libgssapi.so.3.0.0 libgssapi.so.3 )
( cd usr/lib64 ; rm -rf libkafs.so )
( cd usr/lib64 ; ln -sf libkafs.so.0.5.1 libkafs.so )
( cd usr/lib64 ; rm -rf libkrb5.so.26 )
( cd usr/lib64 ; ln -sf libkrb5.so.26.0.0 libkrb5.so.26 )
( cd usr/lib64 ; rm -rf libkrb5.so )
( cd usr/lib64 ; ln -sf libkrb5.so.26.0.0 libkrb5.so )
( cd usr/lib64 ; rm -rf libheimbase.so )
( cd usr/lib64 ; ln -sf libheimbase.so.1.0.0 libheimbase.so )
( cd usr/lib64 ; rm -rf libwind.so.0 )
( cd usr/lib64 ; ln -sf libwind.so.0.0.0 libwind.so.0 )
( cd usr/lib64 ; rm -rf libkadm5srv.so.8 )
( cd usr/lib64 ; ln -sf libkadm5srv.so.8.0.1 libkadm5srv.so.8 )
( cd usr/lib64 ; rm -rf libhx509.so.5 )
( cd usr/lib64 ; ln -sf libhx509.so.5.0.0 libhx509.so.5 )
( cd usr/lib64 ; rm -rf libhx509.so )
( cd usr/lib64 ; ln -sf libhx509.so.5.0.0 libhx509.so )
( cd usr/lib64 ; rm -rf libheimedit.so )
( cd usr/lib64 ; ln -sf libheimedit.so.0.0.36 libheimedit.so )
( cd usr/lib64 ; rm -rf libkadm5srv.so )
( cd usr/lib64 ; ln -sf libkadm5srv.so.8.0.1 libkadm5srv.so )
( cd usr/lib64 ; rm -rf libsl.so.0 )
( cd usr/lib64 ; ln -sf libsl.so.0.2.1 libsl.so.0 )
( cd usr/lib64 ; rm -rf libkafs.so.0 )
( cd usr/lib64 ; ln -sf libkafs.so.0.5.1 libkafs.so.0 )
( cd usr/lib64 ; rm -rf libhdb.so )
( cd usr/lib64 ; ln -sf libhdb.so.9.2.0 libhdb.so )
( cd usr/lib64 ; rm -rf libsl.so )
( cd usr/lib64 ; ln -sf libsl.so.0.2.1 libsl.so )
( cd usr/lib64 ; rm -rf libasn1.so.8 )
( cd usr/lib64 ; ln -sf libasn1.so.8.0.0 libasn1.so.8 )
( cd usr/lib64 ; rm -rf libgssapi.so )
( cd usr/lib64 ; ln -sf libgssapi.so.3.0.0 libgssapi.so )
