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/lib64 ; rm -rf libnutclient.so )
( cd usr/lib64 ; ln -sf libnutclient.so.2.0.2 libnutclient.so )
( cd usr/lib64 ; rm -rf libnutclient.so.2 )
( cd usr/lib64 ; ln -sf libnutclient.so.2.0.2 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.2.0.5 libnutscan.so )
( cd usr/lib64 ; rm -rf libnutscan.so.2 )
( cd usr/lib64 ; ln -sf libnutscan.so.2.0.5 libnutscan.so.2 )
( cd usr/lib64 ; rm -rf libupsclient.so )
( cd usr/lib64 ; ln -sf libupsclient.so.6.0.1 libupsclient.so )
( cd usr/lib64 ; rm -rf libupsclient.so.6 )
( cd usr/lib64 ; ln -sf libupsclient.so.6.0.1 libupsclient.so.6 )
