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/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 )
( cd usr/sbin ; rm -rf bwild )
( cd usr/sbin ; ln -sf /usr/bin/bwild bwild )
( cd usr/lib ; rm -rf libbareoscfg.so )
( cd usr/lib ; ln -sf libbareoscfg-15.2.3.so libbareoscfg.so )
( cd usr/lib ; rm -rf libbareos.so )
( cd usr/lib ; ln -sf libbareos-15.2.3.so libbareos.so )
( cd usr/lib ; rm -rf libbareossd.so )
( cd usr/lib ; ln -sf libbareossd-15.2.3.so libbareossd.so )
( cd usr/lib ; rm -rf libbareossql.so )
( cd usr/lib ; ln -sf libbareossql-15.2.3.so libbareossql.so )
( cd usr/lib ; rm -rf libbareoscats-mysql.so )
( cd usr/lib ; ln -sf libbareoscats-mysql-15.2.3.so libbareoscats-mysql.so )
( cd usr/lib ; rm -rf libbareosfind.so )
( cd usr/lib ; ln -sf libbareosfind-15.2.3.so libbareosfind.so )
( cd usr/lib ; rm -rf libbareoscats.so )
( cd usr/lib ; ln -sf libbareoscats-15.2.3.so libbareoscats.so )
