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.mythbackend.new
config etc/rc.d/rc.mythbackend.new
config etc/logrotate.d/mythbackend.new
config etc/mythtv/config.xml.new
config etc/mythtv/mysql.txt.new

if [ -x /usr/bin/update-desktop-database ]; then
  /usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1
fi
( cd usr/doc ; rm -rf mythtv )
( cd usr/doc ; ln -sf mythtv-0.27.6 mythtv )
( cd usr/lib64 ; rm -rf libmythavformat.so.54 )
( cd usr/lib64 ; ln -sf libmythavformat.so.54.63.104 libmythavformat.so.54 )
( cd usr/lib64 ; rm -rf libmythservicecontracts-0.27.so.0 )
( cd usr/lib64 ; ln -sf libmythservicecontracts-0.27.so.0.27.0 libmythservicecontracts-0.27.so.0 )
( cd usr/lib64 ; rm -rf libmythui-0.27.so.0 )
( cd usr/lib64 ; ln -sf libmythui-0.27.so.0.27.0 libmythui-0.27.so.0 )
( cd usr/lib64 ; rm -rf libmythbase-0.27.so.0 )
( cd usr/lib64 ; ln -sf libmythbase-0.27.so.0.27.0 libmythbase-0.27.so.0 )
( cd usr/lib64 ; rm -rf libmythswscale.so.2 )
( cd usr/lib64 ; ln -sf libmythswscale.so.2.2.100 libmythswscale.so.2 )
( cd usr/lib64 ; rm -rf libmythmetadata-0.27.so )
( cd usr/lib64 ; ln -sf libmythmetadata-0.27.so.0.27.0 libmythmetadata-0.27.so )
( cd usr/lib64 ; rm -rf libmythavfilter.so )
( cd usr/lib64 ; ln -sf libmythavfilter.so.3.42.103 libmythavfilter.so )
( cd usr/lib64 ; rm -rf libmyth-0.27.so.0 )
( cd usr/lib64 ; ln -sf libmyth-0.27.so.0.27.0 libmyth-0.27.so.0 )
( cd usr/lib64 ; rm -rf libmythzmq.so.1 )
( cd usr/lib64 ; ln -sf libmythzmq.so.1.0.1 libmythzmq.so.1 )
( cd usr/lib64 ; rm -rf libmyth-0.27.so.0.27 )
( cd usr/lib64 ; ln -sf libmyth-0.27.so.0.27.0 libmyth-0.27.so.0.27 )
( cd usr/lib64 ; rm -rf libmythbase-0.27.so )
( cd usr/lib64 ; ln -sf libmythbase-0.27.so.0.27.0 libmythbase-0.27.so )
( cd usr/lib64 ; rm -rf libmythavfilter.so.3 )
( cd usr/lib64 ; ln -sf libmythavfilter.so.3.42.103 libmythavfilter.so.3 )
( cd usr/lib64 ; rm -rf libmythpostproc.so )
( cd usr/lib64 ; ln -sf libmythpostproc.so.52.2.100 libmythpostproc.so )
( cd usr/lib64 ; rm -rf libmythtv-0.27.so.0.27 )
( cd usr/lib64 ; ln -sf libmythtv-0.27.so.0.27.0 libmythtv-0.27.so.0.27 )
( cd usr/lib64 ; rm -rf libmythavdevice.so.54 )
( cd usr/lib64 ; ln -sf libmythavdevice.so.54.3.103 libmythavdevice.so.54 )
( cd usr/lib64 ; rm -rf libmythbase-0.27.so.0.27 )
( cd usr/lib64 ; ln -sf libmythbase-0.27.so.0.27.0 libmythbase-0.27.so.0.27 )
( cd usr/lib64 ; rm -rf libmythnzmqt.so.0.27 )
( cd usr/lib64 ; ln -sf libmythnzmqt.so.0.27.0 libmythnzmqt.so.0.27 )
( cd usr/lib64 ; rm -rf libmythavformat.so )
( cd usr/lib64 ; ln -sf libmythavformat.so.54.63.104 libmythavformat.so )
( cd usr/lib64 ; rm -rf libmythfreemheg-0.27.so.0 )
( cd usr/lib64 ; ln -sf libmythfreemheg-0.27.so.0.27.0 libmythfreemheg-0.27.so.0 )
( cd usr/lib64 ; rm -rf libmythswresample.so.0 )
( cd usr/lib64 ; ln -sf libmythswresample.so.0.17.102 libmythswresample.so.0 )
( cd usr/lib64 ; rm -rf libmythupnp-0.27.so.0 )
( cd usr/lib64 ; ln -sf libmythupnp-0.27.so.0.27.0 libmythupnp-0.27.so.0 )
( cd usr/lib64 ; rm -rf libmythqjson.so.0.7 )
( cd usr/lib64 ; ln -sf libmythqjson.so.0.7.1 libmythqjson.so.0.7 )
( cd usr/lib64 ; rm -rf libmythpostproc.so.52 )
( cd usr/lib64 ; ln -sf libmythpostproc.so.52.2.100 libmythpostproc.so.52 )
( cd usr/lib64 ; rm -rf libmythfreemheg-0.27.so.0.27 )
( cd usr/lib64 ; ln -sf libmythfreemheg-0.27.so.0.27.0 libmythfreemheg-0.27.so.0.27 )
( cd usr/lib64 ; rm -rf libmyth-0.27.so )
( cd usr/lib64 ; ln -sf libmyth-0.27.so.0.27.0 libmyth-0.27.so )
( cd usr/lib64 ; rm -rf libmythqjson.so )
( cd usr/lib64 ; ln -sf libmythqjson.so.0.7.1 libmythqjson.so )
( cd usr/lib64 ; rm -rf libmythupnp-0.27.so )
( cd usr/lib64 ; ln -sf libmythupnp-0.27.so.0.27.0 libmythupnp-0.27.so )
( cd usr/lib64 ; rm -rf libmythprotoserver-0.27.so.0 )
( cd usr/lib64 ; ln -sf libmythprotoserver-0.27.so.0.27.0 libmythprotoserver-0.27.so.0 )
( cd usr/lib64 ; rm -rf libmythmetadata-0.27.so.0.27 )
( cd usr/lib64 ; ln -sf libmythmetadata-0.27.so.0.27.0 libmythmetadata-0.27.so.0.27 )
( cd usr/lib64 ; rm -rf libmythnzmqt.so.0 )
( cd usr/lib64 ; ln -sf libmythnzmqt.so.0.27.0 libmythnzmqt.so.0 )
( cd usr/lib64 ; rm -rf libmythzmq.so )
( cd usr/lib64 ; ln -sf libmythzmq.so.1.0.1 libmythzmq.so )
( cd usr/lib64 ; rm -rf libmythprotoserver-0.27.so )
( cd usr/lib64 ; ln -sf libmythprotoserver-0.27.so.0.27.0 libmythprotoserver-0.27.so )
( cd usr/lib64 ; rm -rf libmythui-0.27.so )
( cd usr/lib64 ; ln -sf libmythui-0.27.so.0.27.0 libmythui-0.27.so )
( cd usr/lib64 ; rm -rf libmythavutil.so.52 )
( cd usr/lib64 ; ln -sf libmythavutil.so.52.18.100 libmythavutil.so.52 )
( cd usr/lib64 ; rm -rf libmythmetadata-0.27.so.0 )
( cd usr/lib64 ; ln -sf libmythmetadata-0.27.so.0.27.0 libmythmetadata-0.27.so.0 )
( cd usr/lib64 ; rm -rf libmythupnp-0.27.so.0.27 )
( cd usr/lib64 ; ln -sf libmythupnp-0.27.so.0.27.0 libmythupnp-0.27.so.0.27 )
( cd usr/lib64 ; rm -rf libmythnzmqt.so )
( cd usr/lib64 ; ln -sf libmythnzmqt.so.0.27.0 libmythnzmqt.so )
( cd usr/lib64 ; rm -rf libmythswresample.so )
( cd usr/lib64 ; ln -sf libmythswresample.so.0.17.102 libmythswresample.so )
( cd usr/lib64 ; rm -rf libmythavdevice.so )
( cd usr/lib64 ; ln -sf libmythavdevice.so.54.3.103 libmythavdevice.so )
( cd usr/lib64 ; rm -rf libmythui-0.27.so.0.27 )
( cd usr/lib64 ; ln -sf libmythui-0.27.so.0.27.0 libmythui-0.27.so.0.27 )
( cd usr/lib64 ; rm -rf libmythavcodec.so.54 )
( cd usr/lib64 ; ln -sf libmythavcodec.so.54.92.100 libmythavcodec.so.54 )
( cd usr/lib64 ; rm -rf libmythavutil.so )
( cd usr/lib64 ; ln -sf libmythavutil.so.52.18.100 libmythavutil.so )
( cd usr/lib64 ; rm -rf libmythfreemheg-0.27.so )
( cd usr/lib64 ; ln -sf libmythfreemheg-0.27.so.0.27.0 libmythfreemheg-0.27.so )
( cd usr/lib64 ; rm -rf libmythavcodec.so )
( cd usr/lib64 ; ln -sf libmythavcodec.so.54.92.100 libmythavcodec.so )
( cd usr/lib64 ; rm -rf libmythtv-0.27.so.0 )
( cd usr/lib64 ; ln -sf libmythtv-0.27.so.0.27.0 libmythtv-0.27.so.0 )
( cd usr/lib64 ; rm -rf libmythtv-0.27.so )
( cd usr/lib64 ; ln -sf libmythtv-0.27.so.0.27.0 libmythtv-0.27.so )
( cd usr/lib64 ; rm -rf libmythprotoserver-0.27.so.0.27 )
( cd usr/lib64 ; ln -sf libmythprotoserver-0.27.so.0.27.0 libmythprotoserver-0.27.so.0.27 )
( cd usr/lib64 ; rm -rf libmythservicecontracts-0.27.so )
( cd usr/lib64 ; ln -sf libmythservicecontracts-0.27.so.0.27.0 libmythservicecontracts-0.27.so )
( cd usr/lib64 ; rm -rf libmythservicecontracts-0.27.so.0.27 )
( cd usr/lib64 ; ln -sf libmythservicecontracts-0.27.so.0.27.0 libmythservicecontracts-0.27.so.0.27 )
( cd usr/lib64 ; rm -rf libmythswscale.so )
( cd usr/lib64 ; ln -sf libmythswscale.so.2.2.100 libmythswscale.so )
( cd usr/lib64 ; rm -rf libmythqjson.so.0 )
( cd usr/lib64 ; ln -sf libmythqjson.so.0.7.1 libmythqjson.so.0 )
