-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathadd-addrs.sh
executable file
·63 lines (46 loc) · 1.14 KB
/
add-addrs.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
#
# Add new addresses to ban2fail
set -efu
WD=~/projects/ban2fail
PROTO_CFG=$WD/real-ban2fail.cfg
ACTUAL_CFG=/etc/ban2fail/ban2fail.cfg
BAN2FAIL=/usr/local/bin/ban2fail
B2F_GREP=/usr/local/bin/b2f-grep
MD5SUM=
NEW_MD5SUM=
JUNK=
SEP=
IP=
PRTL_IP=
LINE=
trap "echo && $BAN2FAIL -s" 0
while true; do
read MD5SUM JUNK < <(md5sum $ACTUAL_CFG)
read -p 'Next address(es) please? ' IP
# Only consider editing PROTO_CFG is IP is not empty.
if [[ -n "$IP" ]]; then
$BAN2FAIL $IP
echo '--------------------------------'
read -p 'Edit config file? '
case ${REPLY:0:1} in
y|Y) true;;
*) continue;;
esac
# Edit all addresses we got from b2f-grep
for LINE in $(2>/dev/null $B2F_GREP $IP <$PROTO_CFG); do
$EDITOR +${LINE} $PROTO_CFG
done
fi
# See if PROTO_CFG was changed.
read NEW_MD5SUM JUNK < <(md5sum $PROTO_CFG)
[[ $NEW_MD5SUM == $MD5SUM ]] && continue
$BAN2FAIL -t $PROTO_CFG
read -p 'Make this permanent? '
case ${REPLY:0:1} in
y|Y) true;;
*) continue;;
esac
sudo /bin/cp $PROTO_CFG $ACTUAL_CFG
$BAN2FAIL -s
done