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/lib ; rm -rf libnutclient.so )
( cd usr/lib ; ln -sf libnutclient.so.2.0.2 libnutclient.so )
( cd usr/lib ; rm -rf libnutclient.so.2 )
( cd usr/lib ; ln -sf libnutclient.so.2.0.2 libnutclient.so.2 )
( cd usr/lib ; rm -rf libnutclientstub.so )
( cd usr/lib ; ln -sf libnutclientstub.so.1.0.1 libnutclientstub.so )
( cd usr/lib ; rm -rf libnutclientstub.so.1 )
( cd usr/lib ; ln -sf libnutclientstub.so.1.0.1 libnutclientstub.so.1 )
( cd usr/lib ; rm -rf libnutscan.so )
( cd usr/lib ; ln -sf libnutscan.so.3.0.0 libnutscan.so )
( cd usr/lib ; rm -rf libnutscan.so.3 )
( cd usr/lib ; ln -sf libnutscan.so.3.0.0 libnutscan.so.3 )
( cd usr/lib ; rm -rf libupsclient.so )
( cd usr/lib ; ln -sf libupsclient.so.7.0.0 libupsclient.so )
( cd usr/lib ; rm -rf libupsclient.so.7 )
( cd usr/lib ; ln -sf libupsclient.so.7.0.0 libupsclient.so.7 )
( cd usr/share/nut-monitor/app/locale/fr ; rm -rf fr_FR.UTF-8.po )
( cd usr/share/nut-monitor/app/locale/fr ; ln -sf fr.po fr_FR.UTF-8.po )
( 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/it ; rm -rf it_IT.UTF-8.po )
( cd usr/share/nut-monitor/app/locale/it ; ln -sf it.po it_IT.UTF-8.po )
( 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/ru ; rm -rf ru_RU.UTF-8.po )
( cd usr/share/nut-monitor/app/locale/ru ; ln -sf ru.po ru_RU.UTF-8.po )
( 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 )
