#!/bin/sh
# vim: et ts=2 sw=2

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.shorewall6.new
config etc/shorewall6/accounting.new
config etc/shorewall6/actions.new
config etc/shorewall6/blrules.new
config etc/shorewall6/clear.new
config etc/shorewall6/conntrack.new
config etc/shorewall6/findgw.new
config etc/shorewall6/hosts.new
config etc/shorewall6/init.new
config etc/shorewall6/interfaces.new
config etc/shorewall6/lib.private.new
config etc/shorewall6/maclist.new
config etc/shorewall6/mangle.new
config etc/shorewall6/masq.new
config etc/shorewall6/nat.new
config etc/shorewall6/netmap.new
config etc/shorewall6/params.new
config etc/shorewall6/policy.new
config etc/shorewall6/providers.new
config etc/shorewall6/proxyndp.new
config etc/shorewall6/refresh.new
config etc/shorewall6/refreshed.new
config etc/shorewall6/restored.new
config etc/shorewall6/routes.new
config etc/shorewall6/rtrules.new
config etc/shorewall6/rules.new
config etc/shorewall6/scfilter.new
config etc/shorewall6/secmarks.new
config etc/shorewall6/shorewall6.conf.new
config etc/shorewall6/start.new
config etc/shorewall6/started.new
config etc/shorewall6/stop.new
config etc/shorewall6/stopped.new
config etc/shorewall6/stoppedrules.new
config etc/shorewall6/tcclasses.new
config etc/shorewall6/tcclear.new
config etc/shorewall6/tcdevices.new
config etc/shorewall6/tcfilters.new
config etc/shorewall6/tcinterfaces.new
config etc/shorewall6/tcpri.new
config etc/shorewall6/tos.new
config etc/shorewall6/tunnels.new
config etc/shorewall6/zones.new
( cd usr/share/shorewall6 ; rm -rf functions )
( cd usr/share/shorewall6 ; ln -sf lib.base functions )
