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.nut-drvctl.new
preserve_perms etc/rc.d/rc.nut-upsd.new
preserve_perms etc/rc.d/rc.nut-upsmon.new

for file in etc/nut/*.new ; do
  config $file
done
( cd usr/doc/nut-2.8.5/docs ; rm -rf qa-guide-docinfo.xml )
( cd usr/doc/nut-2.8.5/docs ; ln -sf docinfo-since-v2.8.3.xml qa-guide-docinfo.xml )
( cd usr/lib64 ; rm -rf libnutclient.so )
( cd usr/lib64 ; ln -sf libnutclient.so.2.1.0 libnutclient.so )
( cd usr/lib64 ; rm -rf libnutclient.so.2 )
( cd usr/lib64 ; ln -sf libnutclient.so.2.1.0 libnutclient.so.2 )
( cd usr/lib64 ; rm -rf libnutclientstub.so )
( cd usr/lib64 ; ln -sf libnutclientstub.so.1.0.1 libnutclientstub.so )
( cd usr/lib64 ; rm -rf libnutclientstub.so.1 )
( cd usr/lib64 ; ln -sf libnutclientstub.so.1.0.1 libnutclientstub.so.1 )
( cd usr/lib64 ; rm -rf libnutscan.so )
( cd usr/lib64 ; ln -sf libnutscan.so.4.1.0 libnutscan.so )
( cd usr/lib64 ; rm -rf libnutscan.so.4 )
( cd usr/lib64 ; ln -sf libnutscan.so.4.1.0 libnutscan.so.4 )
( cd usr/lib64 ; rm -rf libupsclient.so )
( cd usr/lib64 ; ln -sf libupsclient.so.7.1.0 libupsclient.so )
( cd usr/lib64 ; rm -rf libupsclient.so.7 )
( cd usr/lib64 ; ln -sf libupsclient.so.7.1.0 libupsclient.so.7 )
( cd usr/share/nut-monitor/app/locale ; rm -rf fr_FR.UTF-8 )
( cd usr/share/nut-monitor/app/locale ; ln -sf fr fr_FR.UTF-8 )
( cd usr/share/nut-monitor/app/locale ; rm -rf it_IT.UTF-8 )
( cd usr/share/nut-monitor/app/locale ; ln -sf it it_IT.UTF-8 )
( cd usr/share/nut-monitor/app/locale ; rm -rf ru_RU.UTF-8 )
( cd usr/share/nut-monitor/app/locale ; ln -sf ru ru_RU.UTF-8 )
