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.bareos.new
config etc/bareos/bareos-dir.conf.new
config etc/bareos/bareos-fd.conf.new
config etc/bareos/bareos-sd.conf.new
config etc/bareos/bconsole.conf.new
config etc/bareos/mtx-changer.conf.new
config etc/logrotate.d/bareos.new
( cd usr/lib64 ; rm -rf libbareosfind.so )
( cd usr/lib64 ; ln -sf libbareosfind-15.2.3.so libbareosfind.so )
( cd usr/lib64 ; rm -rf libbareoscats.so )
( cd usr/lib64 ; ln -sf libbareoscats-15.2.3.so libbareoscats.so )
( cd usr/lib64 ; rm -rf libbareossql.so )
( cd usr/lib64 ; ln -sf libbareossql-15.2.3.so libbareossql.so )
( cd usr/lib64 ; rm -rf libbareossd.so )
( cd usr/lib64 ; ln -sf libbareossd-15.2.3.so libbareossd.so )
( cd usr/lib64 ; rm -rf libbareos.so )
( cd usr/lib64 ; ln -sf libbareos-15.2.3.so libbareos.so )
( cd usr/lib64 ; rm -rf libbareoscats-mysql.so )
( cd usr/lib64 ; ln -sf libbareoscats-mysql-15.2.3.so libbareoscats-mysql.so )
( cd usr/lib64 ; rm -rf libbareoscfg.so )
( cd usr/lib64 ; ln -sf libbareoscfg-15.2.3.so libbareoscfg.so )
( cd usr/sbin ; rm -rf bwild )
( cd usr/sbin ; ln -sf /usr/bin/bwild bwild )
( cd usr/sbin ; rm -rf bconsole )
( cd usr/sbin ; ln -sf /usr/bin/bconsole bconsole )
( cd usr/sbin ; rm -rf bsmtp )
( cd usr/sbin ; ln -sf /usr/bin/bsmtp bsmtp )
( cd usr/sbin ; rm -rf bregex )
( cd usr/sbin ; ln -sf /usr/bin/bregex bregex )
