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.sqlrelay.new
preserve_perms etc/rc.d/rc.sqlrcachemanager.new
config etc/sqlrelay/sqlrelay.xsd.new
config etc/php.d/pdo_sqlrelay.ini.new
config etc/php.d/sql_relay.ini.new
( cd usr/lib ; rm -rf libsqlrclient.so )
( cd usr/lib ; ln -sf libsqlrclient.so.7.0.0 libsqlrclient.so )
( cd usr/lib ; rm -rf libsqlrclient.so.7 )
( cd usr/lib ; ln -sf libsqlrclient.so.7.0.0 libsqlrclient.so.7 )
( cd usr/lib ; rm -rf libsqlrclientwrapper.so )
( cd usr/lib ; ln -sf libsqlrclientwrapper.so.7.0.0 libsqlrclientwrapper.so )
( cd usr/lib ; rm -rf libsqlrclientwrapper.so.7 )
( cd usr/lib ; ln -sf libsqlrclientwrapper.so.7.0.0 libsqlrclientwrapper.so.7 )
( cd usr/lib ; rm -rf libsqlrserver.so )
( cd usr/lib ; ln -sf libsqlrserver.so.12.0.0 libsqlrserver.so )
( cd usr/lib ; rm -rf libsqlrserver.so.12 )
( cd usr/lib ; ln -sf libsqlrserver.so.12.0.0 libsqlrserver.so.12 )
( cd usr/lib ; rm -rf libsqlrutil.so )
( cd usr/lib ; ln -sf libsqlrutil.so.12.0.0 libsqlrutil.so )
( cd usr/lib ; rm -rf libsqlrutil.so.12 )
( cd usr/lib ; ln -sf libsqlrutil.so.12.0.0 libsqlrutil.so.12 )
