#!/bin/sh if test "`whoami`" != "root"; then echo 'Need root privileges.' exit; fi cp /etc/pf.conf /tmp/ firstrun=yes; while :; do vi /tmp/pf.conf if diff /etc/pf.conf /tmp/pf.conf; then if [[ $firstrun == "yes" ]]; then print "No changes. Not reloading rules."; elif [[ $firstrun == "no" ]]; then print "Edited file same as original. Reloading /etc/pf.conf."; pfctl -f /etc/pf.conf fi exit; elif pfctl -nvf /tmp/pf.conf; then firstrun=no; pfctl -f /tmp/pf.conf print "\n\nNew rules loaded. Test your config before answering."; print -n "[r]evert & edit; continue [e]diting; revert & e[x]it; [q]uit & install new config; [ ]: "; read answer; case $answer in r) pfctl -f /etc/pf.conf;; e) continue;; x) pfctl -f /etc/pf.conf; exit;; q) cat /tmp/pf.conf > /etc/pf.conf; exit esac else print -n "\n\nSyntax error. [s]tart over; [e]dit again; e[x]it; [ ]: "; read answer; case $answer in s) cp /etc/pf.conf /tmp/pf.conf; continue;; e) continue;; x) exit esac fi done rm /tmp/pf.conf