|
7 | 7 |
|
8 | 8 | init-help()
|
9 | 9 | {
|
10 |
| - echo 'pot init [-h][-v]' |
| 10 | + echo 'pot init [-h][-v] [-f pf_file]' |
| 11 | + echo ' -f pf_file : write pot anchors to this file (empty to skip),' |
| 12 | + echo ' defaults to result of `sysrc -n pf_rules`' |
11 | 13 | echo ' -h print this help'
|
12 | 14 | echo ' -v verbose'
|
13 | 15 | }
|
14 | 16 |
|
15 | 17 | pot-init()
|
16 | 18 | {
|
17 | 19 | local pf_file
|
| 20 | + pf_file="$(sysrc -n pf_rules)" |
18 | 21 | OPTIND=1
|
19 |
| - while getopts "hv" _o ; do |
| 22 | + while getopts "hvf:" _o ; do |
20 | 23 | case "$_o" in
|
| 24 | + f) pf_file="$OPTARG" |
| 25 | + ;; |
21 | 26 | h)
|
22 | 27 | init-help
|
23 | 28 | ${EXIT} 0
|
@@ -122,21 +127,24 @@ pot-init()
|
122 | 127 | # service syslogd restart
|
123 | 128 |
|
124 | 129 | # Add pot anchors if needed
|
125 |
| - pf_file="$(sysrc -n pf_rules)" |
126 |
| - if [ -r "$pf_file" ] && [ "$(grep -c '^nat-anchor pot-nat$' "$pf_file" )" -eq 1 ] && [ "$(grep -c '^rdr-anchor "pot-rdr/\*"$' "$pf_file" )" -eq 1 ] ; then |
127 |
| - _debug "pf alredy properly configured" |
128 |
| - else |
129 |
| - if [ -w "$pf_file" ]; then |
130 |
| - echo "Creating a backup of your $pf_file" |
131 |
| - cp -v "$pf_file" "$pf_file".bkp-pot |
132 |
| - # delete incomplete/broken ancory entries - just in case |
133 |
| - sed -i '' '/^nat-anchor pot-nat$/d' "$pf_file" |
134 |
| - sed -i '' '/^rdr-anchor "pot-rdr\/\*"$/d' "$pf_file" |
| 130 | + if [ -n "$pf_file" ]; then |
| 131 | + if [ -r "$pf_file" ] && [ "$(grep -c '^nat-anchor pot-nat$' "$pf_file" )" -eq 1 ] && [ "$(grep -c '^rdr-anchor "pot-rdr/\*"$' "$pf_file" )" -eq 1 ] ; then |
| 132 | + _debug "pf already properly configured" |
135 | 133 | else
|
136 |
| - touch "$pf_file" |
| 134 | + if [ -w "$pf_file" ]; then |
| 135 | + echo "Creating a backup of your $pf_file" |
| 136 | + cp -v "$pf_file" "$pf_file".bkp-pot |
| 137 | + # delete incomplete/broken ancory entries - just in case |
| 138 | + sed -i '' '/^nat-anchor pot-nat$/d' "$pf_file" |
| 139 | + sed -i '' '/^rdr-anchor "pot-rdr\/\*"$/d' "$pf_file" |
| 140 | + else |
| 141 | + touch "$pf_file" |
| 142 | + fi |
| 143 | + echo "auto-magically editing your $pf_file" |
| 144 | + printf "%s\n" 0a "nat-anchor pot-nat" "rdr-anchor \"pot-rdr/*\"" . x | ex "$pf_file" |
| 145 | + echo "Please, check that your PF configuration file $pf_file is still valid!" |
137 | 146 | fi
|
138 |
| - echo "auto-magically editing your $pf_file" |
139 |
| - printf "%s\n" 0a "nat-anchor pot-nat" "rdr-anchor \"pot-rdr/*\"" . x | ex "$pf_file" |
140 |
| - echo "Please, check that your PF configuration file $pf_file is still valid!" |
| 147 | + else |
| 148 | + _debug "pf configuration skipped" |
141 | 149 | fi
|
142 | 150 | }
|
0 commit comments