aboutsummaryrefslogtreecommitdiffstats
path: root/roles/host_prod/templates/usr_local_bin_safepf.sh
blob: 1b6efeec6bb4783c707e3a8c182dc57acc623db9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh

set -eu

cmd="pfctl -f /etc/pf.conf"
read -p "Run this command (y/n)? $cmd " answer
if [ "$answer" = "y" ]; then
    (set -x; $cmd)
else
    exit 0
fi

cmd="service pf restart"
read -p "Run this command (y/n)? $cmd " answer
if [ "$answer" = "y" ]; then
    (set -x; $cmd)
else
    exit 0
fi

timeout=60
echo "Running safety timeout ($timeout seconds). Press CTRL-C if everything is working."
while [ $timeout -gt 0 ]
do
    sleep 1
    timeout=$((timeout - 1))
    echo -n "."
done

echo "Timeout reached. Enabling empty pf rules"

set -x
mv /etc/pf.conf /etc/pf.conf.locked_out
echo "" > /etc/pf.conf
pfctl -f /etc/pf.conf
service pf restart