2017-06-28 11:19:32 +00:00
|
|
|
#!/bin/sh -e
|
2012-09-19 19:49:36 +00:00
|
|
|
#
|
|
|
|
# 2012 Jake Guffey (jake.guffey at eprotex.com)
|
|
|
|
#
|
|
|
|
# This file is part of cdist.
|
|
|
|
#
|
|
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# cdist is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Apply pf(4) ruleset on *BSD
|
|
|
|
#
|
|
|
|
|
|
|
|
# Debug
|
|
|
|
#exec >&2
|
|
|
|
#set -x
|
|
|
|
|
2012-09-19 20:15:06 +00:00
|
|
|
rcvar=$(cat "$__object/explorer/rcvar")
|
|
|
|
|
2012-09-19 19:49:36 +00:00
|
|
|
cat <<EOF
|
2012-09-19 20:15:06 +00:00
|
|
|
if [ -f "${rcvar}.old" ]; then # rcvar.old exists, we must need to disable pf
|
2012-09-19 20:42:15 +00:00
|
|
|
# Disable pf
|
|
|
|
# If it already is disabled, pfctl -d returns 1, go on with life
|
2012-09-19 21:18:45 +00:00
|
|
|
pfctl -d || true
|
2012-09-19 20:15:06 +00:00
|
|
|
# Cleanup
|
2012-09-19 21:00:22 +00:00
|
|
|
rm -f "${rcvar}.old"
|
2012-09-19 20:15:06 +00:00
|
|
|
elif [ -f "${rcvar}.new" ]; then # rcvar.new exists, we must need to apply it
|
|
|
|
# Ensure that pf is enabled in the first place
|
2012-09-19 20:42:15 +00:00
|
|
|
# If it already is enabled, pfctl -e returns 1, go on with life
|
2012-09-19 21:04:03 +00:00
|
|
|
mv "${rcvar}.new" "${rcvar}"
|
2012-09-19 20:42:15 +00:00
|
|
|
pfctl -e || true
|
2012-09-19 20:15:06 +00:00
|
|
|
pfctl -f "${rcvar}"
|
2012-09-21 14:11:56 +00:00
|
|
|
if [ "\$?" -ne "0" ]; then # failed to configure new ruleset
|
2012-09-19 21:00:22 +00:00
|
|
|
echo "Failed to configure the new ruleset on ${__target_host}!" >&2
|
2012-09-19 20:15:06 +00:00
|
|
|
fi
|
|
|
|
fi
|
2012-09-19 19:49:36 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# Debug
|
|
|
|
#set +x
|
|
|
|
|