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

config() {
  NEW="$1"
  OLD="${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.shorewall.new

config etc/shorewall/accounting.new
config etc/shorewall/actions.new
config etc/shorewall/arprules.new
config etc/shorewall/blrules.new
config etc/shorewall/clear.new
config etc/shorewall/conntrack.new
config etc/shorewall/ecn.new
config etc/shorewall/findgw.new
config etc/shorewall/hosts.new
config etc/shorewall/init.new
config etc/shorewall/initdone.new
config etc/shorewall/interfaces.new
config etc/shorewall/lib.private.new
config etc/shorewall/maclist.new
config etc/shorewall/mangle.new
config etc/shorewall/nat.new
config etc/shorewall/netmap.new
config etc/shorewall/params.new
config etc/shorewall/policy.new
config etc/shorewall/providers.new
config etc/shorewall/proxyarp.new
config etc/shorewall/refresh.new
config etc/shorewall/refreshed.new
config etc/shorewall/restored.new
config etc/shorewall/routes.new
config etc/shorewall/rtrules.new
config etc/shorewall/rules.new
config etc/shorewall/scfilter.new
config etc/shorewall/secmarks.new
config etc/shorewall/shorewall.conf.new
config etc/shorewall/snat.new
config etc/shorewall/start.new
config etc/shorewall/started.new
config etc/shorewall/stop.new
config etc/shorewall/stopped.new
config etc/shorewall/stoppedrules.new
config etc/shorewall/tcclasses.new
config etc/shorewall/tcclear.new
config etc/shorewall/tcdevices.new
config etc/shorewall/tcfilters.new
config etc/shorewall/tcinterfaces.new
config etc/shorewall/tcpri.new
config etc/shorewall/tunnels.new
config etc/shorewall/zones.new
